class Ikra::Translator::ArrayCommandStructBuilder::SingleStructBuilder
This class builds a struct containing references to input (depending) commands for a certain array command. It is a subclass of [Symbolic::Visitor] but does not traverse the tree. We just take advantage of the double dispatch here.
Public Instance Methods
struct_name(command)
click to toggle source
# File lib/translator/array_command_struct_builder.rb, line 87 def struct_name(command) return ArrayCommandStructBuilder.struct_name(command) end
visit_array_command(command)
click to toggle source
# File lib/translator/array_command_struct_builder.rb, line 91 def visit_array_command(command) this_name = struct_name(command) struct_def = "struct #{this_name} {\n" # Debug information struct_def = struct_def + " // #{command.class}\n" # Generate fields struct_def = struct_def + " #{command.result_type.to_c_type} *result;\n" all_params = ["#{command.result_type.to_c_type} *result = NULL"] all_initializers = ["result(result)"] command.input.each_with_index do |input, index| if input.command.is_a?(Symbolic::ArrayCommand) struct_def = struct_def + " #{struct_name(input.command)} *input_#{index};\n" all_params.push("#{struct_name(input.command)} *input_#{index} = NULL") all_initializers.push("input_#{index}(input_#{index})") end end # Generate constructor struct_def = struct_def + " __host__ __device__ #{this_name}(#{all_params.join(', ')}) : #{all_initializers.join(', ')} { }\n" # Add instance methods if RequireRuntimeSizeChecker.require_size_function?(command) # ArrayIndexCommand does not have any input, as an example. But in this # case, we also do not need the `size` function, because it is a root # command that can be fused. struct_def = struct_def + " int size() { return input_0->size(); }\n" end struct_def = struct_def + "};" end
visit_array_in_host_section_command(command)
click to toggle source
# File lib/translator/array_command_struct_builder.rb, line 126 def visit_array_in_host_section_command(command) this_name = struct_name(command) struct_def = "struct #{this_name} {\n" # Debug information struct_def = struct_def + " // #{command.class}\n" struct_def = struct_def + " #{command.result_type.to_c_type} *result;\n" struct_def = struct_def + " variable_size_array_t input_0;\n" struct_def = struct_def + " __host__ __device__ #{this_name}(#{command.result_type.to_c_type} *result = NULL, variable_size_array_t input_0 = variable_size_array_t::error_return_value) : result(result), input_0(input_0) { }\n" # Add instance methods struct_def = struct_def + " int size() { return input_0.size; }\n" return struct_def + "};" end