Class: MetaCL::DSL::Root

Inherits:
Object
  • Object
show all
Includes:
DataDefinitions, Directs, GPUTransfers
Defined in:
lib/metacl/dsl/root.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GPUTransfers

#download_from_gpu, #upload_to_gpu

Methods included from DataDefinitions

#array, #matrix, #numeric

Methods included from Directs

#direct, #direct_pre

Constructor Details

#initialize(program, filename) ⇒ Root

Returns a new instance of Root.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/metacl/dsl/root.rb', line 12

def initialize(program, filename)
  @program = program
  super() # call initializers from modules
  @inner_code     = ""
  @post_init_code = ""
  @outer_code     = ""

  instance_eval IO.read(filename), filename

  @code = Templates::Wrapper.render(@inner_code, @post_init_code, @outer_code, @program.platform)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/metacl/dsl/root.rb', line 4

def code
  @code
end

Instance Method Details

#apply_expression(matrix_name, options = {}, &block) ⇒ Object



37
38
39
40
41
42
# File 'lib/metacl/dsl/root.rb', line 37

def apply_expression(matrix_name, options = {}, &block)
  expr = Expression.construct(@program, &block)
  code, init_code = ExpressionApplicator.construct(@program, expr, matrix_name, options)
  @inner_code << code << "\n\n"
  @post_init_code << init_code << "\n\n"
end

#expression(name, *args, &block) ⇒ Object



32
33
34
35
# File 'lib/metacl/dsl/root.rb', line 32

def expression(name, *args, &block)
  tree = Expression.construct(@program, &block)
  @program.resources.add_expression(name, tree, args)
end

#platform(name) ⇒ Object



24
25
26
# File 'lib/metacl/dsl/root.rb', line 24

def platform(name)
  @program.set_platform name # TODO platform check
end


44
45
46
47
# File 'lib/metacl/dsl/root.rb', line 44

def print_matrix(name)
  matrix = @program.resources.matrices_hash[name]
  @inner_code << Templates::PrintMatrix.render(matrix.name, matrix.size_n, matrix.size_m, @program.platform)
end

#prints(string) ⇒ Object



28
29
30
# File 'lib/metacl/dsl/root.rb', line 28

def prints(string)
  @inner_code << Templates::Prints.render(string, @program.platform) << "\n\n"
end

#repeat(count, &block) ⇒ Object



49
50
51
52
53
# File 'lib/metacl/dsl/root.rb', line 49

def repeat(count, &block)
  @inner_code << Templates::Iterate.render(count) << "\n"
  instance_eval(&block)
  @inner_code << "}\n\n"
end