class Ikra::Translator::CommandTranslator::HostSectionProgramBuilder

Attributes

host_result_expression[RW]

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[RW]

A host C++ function containing the source code of the host section.

result_type[RW]

The type of the result (not an array type, just the inner type).

Public Class Methods

new(environment_builder:, root_command:) click to toggle source
Calls superclass method
# File lib/translator/host_section/program_builder.rb, line 19
def initialize(environment_builder:, root_command:)
    super

    @kernel_builders = Set.new
end

Public Instance Methods

add_kernel_launcher(launcher) click to toggle source
Calls superclass method
# 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() click to toggle source
# File lib/translator/host_section/program_builder.rb, line 50
def all_kernel_builders
    return @kernel_builders
end
assert_ready_to_build() click to toggle source
# 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() click to toggle source
# 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() click to toggle source

Builds the CUDA program. Returns the source code string.

# 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() click to toggle source
# File lib/translator/host_section/program_builder.rb, line 39
def clear_kernel_launchers
    @kernel_launchers.clear
end
prepare_additional_args_for_launch(command) click to toggle source
# 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