Class: Ikra::Symbolic::StencilArrayInput

Inherits:
Input show all
Defined in:
lib/symbolic/input.rb,
lib/symbolic/input_visitor.rb,
lib/translator/input_translator.rb,
lib/types/inference/input_inference.rb

Overview

An array containing values produced by one previous command.

Instance Attribute Summary collapse

Attributes inherited from Input

#command, #pattern

Instance Method Summary collapse

Methods inherited from Input

#eql?, #hash

Constructor Details

#initialize(command:, pattern:, offsets:, out_of_bounds_value:) ⇒ StencilArrayInput

Returns a new instance of StencilArrayInput.



46
47
48
49
50
51
52
# File 'lib/symbolic/input.rb', line 46

def initialize(command:, pattern:, offsets:, out_of_bounds_value:)
    super(pattern: pattern)

    @command = command
    @offsets = offsets
    @out_of_bounds_value = out_of_bounds_value
end

Instance Attribute Details

#offsetsObject (readonly)

Returns the value of attribute offsets.



43
44
45
# File 'lib/symbolic/input.rb', line 43

def offsets
  @offsets
end

#out_of_bounds_valueObject (readonly)

Returns the value of attribute out_of_bounds_value.



44
45
46
# File 'lib/symbolic/input.rb', line 44

def out_of_bounds_value
  @out_of_bounds_value
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
58
# File 'lib/symbolic/input.rb', line 54

def ==(other)
    return super(other) && 
        offsets == other.offsets &&
        out_of_bounds_value == other.out_of_bounds_value
end

#accept(visitor) ⇒ Object



19
20
21
# File 'lib/symbolic/input_visitor.rb', line 19

def accept(visitor)
    visitor.visit_stecil_array_input(self, pattern: pattern)
end

#get_parameters(parent_command:, start_eat_params_offset: 0) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/types/inference/input_inference.rb', line 32

def get_parameters(parent_command:, start_eat_params_offset: 0)
    # Parameters are allocated in a constant-sized array

    return [Translator::Variable.new(
        name: parent_command.block_parameter_names[start_eat_params_offset],
        type: command.result_type.to_array_type)]
end

#translate_input(parent_command:, command_translator:, start_eat_params_offset: 0) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/translator/input_translator.rb', line 45

def translate_input(parent_command:, command_translator:, start_eat_params_offset: 0)
    # Parameters are allocated in a constant-sized array

    # Count number of parameters
    num_parameters = parent_command.offsets.size

    # Get single parameter name
    block_param_name = parent_command.block_parameter_names[start_eat_params_offset]

    # Translate input using visitor
    input_command_translation_result = command_translator.translate_input(self)

    # Take return type from previous computation
    parameters = [Translator::Variable.new(
        name: block_param_name,
        type: input_command_translation_result.result_type.to_array_type)]


    # Allocate and fill array of parameters
    actual_parameter_names = (0...num_parameters).map do |param_index| 
        "_#{block_param_name}_#{param_index}"
    end

    param_array_init = "{ " + actual_parameter_names.join(", ") + " }"

    pre_execution = Translator.read_file(file_name: "stencil_array_reconstruction.cpp", replacements: {
        "type" => input_command_translation_result.result_type.to_c_type,
        "name" => block_param_name.to_s,
        "initializer" => param_array_init})

    # Pass multiple single values instead of array
    override_block_parameters  = actual_parameter_names.map do |param_name|
        Translator::Variable.new(
            name: param_name,
            type: input_command_translation_result.result_type)
    end

    return Translator::InputTranslationResult.new(
        pre_execution: pre_execution,
        parameters: parameters,
        override_block_parameters: override_block_parameters,
        command_translation_result: input_command_translation_result)
end