Class: Ikra::Translator::CommandTranslator::ProgramBuilder
- Defined in:
- lib/translator/program_builder.rb,
lib/translator/program_launcher.rb
Overview
Builds the entire CUDA program. A CUDA program may consist of multiple kernels, but has at least one kernel. The generated code performs the following steps:
-
Insert header of CUDA file.
-
For every kernel: Build all methods, blocks, and kernels.
-
Build the program entry point (including kernel launchers).
Direct Known Subclasses
Defined Under Namespace
Classes: Launcher
Instance Attribute Summary collapse
-
#array_command_structs ⇒ Object
readonly
An array of array command structs.
-
#environment_builder ⇒ Object
readonly
Returns the value of attribute environment_builder.
-
#kernel_launchers ⇒ Object
readonly
Returns the value of attribute kernel_launchers.
-
#kernels ⇒ Object
readonly
Returns the value of attribute kernels.
-
#root_command ⇒ Object
readonly
Returns the value of attribute root_command.
-
#structs ⇒ Object
readonly
An array of structs definitions ([Types::StructType] instances) that should be generated for this program.
Instance Method Summary collapse
- #add_array_command_struct(*structs) ⇒ Object
- #add_kernel_launcher(launcher) ⇒ Object
-
#build_kernel_launchers ⇒ Object
Build kernel invocations.
-
#execute ⇒ Object
Generates the source code for the CUDA program, compiles it with nvcc and executes the program.
-
#initialize(environment_builder:, root_command:) ⇒ ProgramBuilder
constructor
A new instance of ProgramBuilder.
Constructor Details
#initialize(environment_builder:, root_command:) ⇒ ProgramBuilder
Returns a new instance of ProgramBuilder.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/translator/program_builder.rb', line 27 def initialize(environment_builder:, root_command:) @kernel_launchers = [] @kernels = Set.new([]) @environment_builder = environment_builder @root_command = root_command # The collection of structs is a [Set]. Struct types are unique, i.e., there # are never two equal struct types with different object identity. @structs = Set.new @array_command_structs = Set.new end |
Instance Attribute Details
#array_command_structs ⇒ Object (readonly)
An array of array command structs.
25 26 27 |
# File 'lib/translator/program_builder.rb', line 25 def array_command_structs @array_command_structs end |
#environment_builder ⇒ Object (readonly)
Returns the value of attribute environment_builder.
15 16 17 |
# File 'lib/translator/program_builder.rb', line 15 def environment_builder @environment_builder end |
#kernel_launchers ⇒ Object (readonly)
Returns the value of attribute kernel_launchers.
16 17 18 |
# File 'lib/translator/program_builder.rb', line 16 def kernel_launchers @kernel_launchers end |
#kernels ⇒ Object (readonly)
Returns the value of attribute kernels.
17 18 19 |
# File 'lib/translator/program_builder.rb', line 17 def kernels @kernels end |
#root_command ⇒ Object (readonly)
Returns the value of attribute root_command.
18 19 20 |
# File 'lib/translator/program_builder.rb', line 18 def root_command @root_command end |
#structs ⇒ Object (readonly)
An array of structs definitions ([Types::StructType] instances) that should be generated for this program.
22 23 24 |
# File 'lib/translator/program_builder.rb', line 22 def structs @structs end |
Instance Method Details
#add_array_command_struct(*structs) ⇒ Object
39 40 41 42 43 |
# File 'lib/translator/program_builder.rb', line 39 def add_array_command_struct(*structs) for struct in structs array_command_structs.add(struct) end end |
#add_kernel_launcher(launcher) ⇒ Object
45 46 47 |
# File 'lib/translator/program_builder.rb', line 45 def add_kernel_launcher(launcher) @kernel_launchers.push(launcher) end |
#build_kernel_launchers ⇒ Object
Build kernel invocations
65 66 67 68 69 |
# File 'lib/translator/program_builder.rb', line 65 def build_kernel_launchers return kernel_launchers.map do |launcher| launcher.build_kernel_launcher end.join("") end |
#execute ⇒ Object
Generates the source code for the CUDA program, compiles it with nvcc and executes the program.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/translator/program_builder.rb', line 51 def execute source = build_program launcher = Launcher.new( source: source, environment_builder: environment_builder, result_type: result_type, root_command: root_command) launcher.compile return launcher.execute end |