Class: Ikra::Translator::CommandTranslator::HostSectionProgramBuilder
- Inherits:
-
ProgramBuilder
- Object
- ProgramBuilder
- Ikra::Translator::CommandTranslator::HostSectionProgramBuilder
- Defined in:
- lib/translator/host_section/program_builder.rb
Instance Attribute Summary collapse
-
#host_result_expression ⇒ Object
An expression that returns the final result, as an ‘variable_size_array_t` object pointing to an array in the host memory.
-
#host_section_source ⇒ Object
A host C++ function containing the source code of the host section.
-
#result_type ⇒ Object
The type of the result (not an array type, just the inner type).
Attributes inherited from ProgramBuilder
#array_command_structs, #environment_builder, #kernel_launchers, #kernels, #root_command, #structs
Instance Method Summary collapse
- #add_kernel_launcher(launcher) ⇒ Object
- #all_kernel_builders ⇒ Object
- #assert_ready_to_build ⇒ Object
- #build_memory_free_except_last ⇒ Object
-
#build_program ⇒ Object
Builds the CUDA program.
- #clear_kernel_launchers ⇒ Object
-
#initialize(environment_builder:, root_command:) ⇒ HostSectionProgramBuilder
constructor
A new instance of HostSectionProgramBuilder.
- #prepare_additional_args_for_launch(command) ⇒ Object
Methods inherited from ProgramBuilder
#add_array_command_struct, #build_kernel_launchers, #execute
Constructor Details
#initialize(environment_builder:, root_command:) ⇒ HostSectionProgramBuilder
Returns a new instance of HostSectionProgramBuilder.
19 20 21 22 23 |
# File 'lib/translator/host_section/program_builder.rb', line 19 def initialize(environment_builder:, root_command:) super @kernel_builders = Set.new end |
Instance Attribute Details
#host_result_expression ⇒ Object
An expression that returns the final result, as an ‘variable_size_array_t` object pointing to an array in the host memory.
17 18 19 |
# File 'lib/translator/host_section/program_builder.rb', line 17 def host_result_expression @host_result_expression end |
#host_section_source ⇒ Object
A host C++ function containing the source code of the host section.
10 11 12 |
# File 'lib/translator/host_section/program_builder.rb', line 10 def host_section_source @host_section_source end |
#result_type ⇒ Object
The type of the result (not an array type, just the inner type).
13 14 15 |
# File 'lib/translator/host_section/program_builder.rb', line 13 def result_type @result_type end |
Instance Method Details
#add_kernel_launcher(launcher) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/translator/host_section/program_builder.rb', line 43 def add_kernel_launcher(launcher) super # Let's keep track of kernels here by ourselves @kernel_builders.merge(launcher.kernel_builders) end |
#all_kernel_builders ⇒ Object
50 51 52 |
# File 'lib/translator/host_section/program_builder.rb', line 50 def all_kernel_builders return @kernel_builders end |
#assert_ready_to_build ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/translator/host_section/program_builder.rb', line 25 def assert_ready_to_build if host_section_source == nil raise AssertionError.new("Not ready to build (HostSectionProgramBuilder): No host section source code defined") end if result_type == nil raise AssertionError.new("Not ready to build (HostSectionProgramBuilder): No result type defined") end if host_result_expression == nil raise AssertionError.new("Not ready to build (HostSectionProgramBuilder): No host result expression defined") end end |
#build_memory_free_except_last ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/translator/host_section/program_builder.rb', line 60 def build_memory_free_except_last result = "" for launcher in kernel_launchers[0...-1] if !launcher.reuse_memory? result = result + launcher.build_device_memory_free_in_host_section end end return result end |
#build_program ⇒ Object
Builds the CUDA program. Returns the source code string.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/translator/host_section/program_builder.rb', line 73 def build_program assert_ready_to_build result = build_header + build_struct_types + build_header_structs + build_array_command_struct_types + build_environment_struct + build_kernels + host_section_source # Build program entry point return result + Translator.read_file(file_name: "host_section_entry_point.cpp", replacements: { "prepare_environment" => environment_builder.build_environment_variable, "host_env_var_name" => Constants::ENV_HOST_IDENTIFIER, "host_result_array" => host_result_expression}) end |
#clear_kernel_launchers ⇒ Object
39 40 41 |
# File 'lib/translator/host_section/program_builder.rb', line 39 def clear_kernel_launchers @kernel_launchers.clear end |
#prepare_additional_args_for_launch(command) ⇒ Object
54 55 56 57 58 |
# File 'lib/translator/host_section/program_builder.rb', line 54 def prepare_additional_args_for_launch(command) kernel_launchers.each do |launcher| launcher.prepare_additional_args_for_launch(command) end end |