Class: Ikra::Translator::CommandTranslator::WhileLoopKernelLauncher

Inherits:
KernelLauncher show all
Defined in:
lib/translator/kernel_launcher/while_loop_kernel_launcher.rb

Instance Attribute Summary collapse

Attributes inherited from KernelLauncher

#additional_arguments, #block_dim, #cached_results, #grid_dim, #kernel_builder, #kernel_result_var_name, #num_threads, #previous_kernel_input, #previously_cached_results, #reuse_memory

Instance Method Summary collapse

Methods inherited from KernelLauncher

#add_additional_arguments, #add_cached_result, #add_previous_kernel_parameter, #assert_ready_to_build, #build_device_memory_free, #build_device_memory_free_in_host_section, #configure_grid, #kernel_builders, #prepare_additional_args_for_launch, #result_size, #result_type, #reuse_memory!, #reuse_memory?, #use_cached_result

Constructor Details

#initialize(kernel_builder:, condition:, before_loop: "", post_iteration: "") ⇒ WhileLoopKernelLauncher

Returns a new instance of WhileLoopKernelLauncher.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/translator/kernel_launcher/while_loop_kernel_launcher.rb', line 5

def initialize(
    kernel_builder:,
    condition:,
    before_loop: "",
    post_iteration: "")

    super(kernel_builder)
    @condition = condition
    @before_loop = before_loop
    @post_iteration = post_iteration
end

Instance Attribute Details

#before_loopObject (readonly)

Returns the value of attribute before_loop.



18
19
20
# File 'lib/translator/kernel_launcher/while_loop_kernel_launcher.rb', line 18

def before_loop
  @before_loop
end

#conditionObject (readonly)

Returns the value of attribute condition.



17
18
19
# File 'lib/translator/kernel_launcher/while_loop_kernel_launcher.rb', line 17

def condition
  @condition
end

#post_iterationObject (readonly)

Returns the value of attribute post_iteration.



19
20
21
# File 'lib/translator/kernel_launcher/while_loop_kernel_launcher.rb', line 19

def post_iteration
  @post_iteration
end

Instance Method Details

#build_kernel_launcherObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/translator/kernel_launcher/while_loop_kernel_launcher.rb', line 21

def build_kernel_launcher
    Log.info("Building for-loop kernel launcher")

    assert_ready_to_build

    result = ""
    result = result + before_loop + "\n"
    result = result + "while (#{condition}) {\n"
    result = result + super
    result = result + "\n" + post_iteration
    result = result + "\n}\n"

    return result
end