Class: Ikra::Symbolic::ArrayIdentityCommand

Inherits:
Object
  • Object
show all
Includes:
ArrayCommand
Defined in:
lib/symbolic/visitor.rb,
lib/symbolic/symbolic.rb

Constant Summary collapse

@@unique_id =
1

Instance Attribute Summary collapse

Attributes included from ArrayCommand

#block, #block_size, #generator_node, #gpu_result_pointer, #input, #keep, #unique_id

Instance Method Summary collapse

Methods included from ArrayCommand

#==, #[], #block_def_node, #block_parameter_names, #command_binding, #command_translator_class, #each, #eql?, #has_previous_result?, #hash, #ikra_type, included, #lexical_externals, #pack, #post_execute, reset_unique_id, #result_type, #set_unique_id, #to_c_type, #to_command, #to_ffi_type, #to_ruby_type, #to_s, #with_index

Methods included from Types::RubyType

#class_id, #eql?, #hash, #inspect, #is_primitive?, #is_union_type?, #should_generate_self_arg?, #to_array_type, #to_c_type, #to_ruby_type, #to_str, #to_union_type

Methods included from ParallelOperations

#&, #*, #+, #-, #/, #<, #<=, #>, #>=, #^, #pcombine, #pmap, #preduce, #pstencil, #pzip, #|

Constructor Details

#initialize(target, block_size: DEFAULT_BLOCK_SIZE, dimensions: nil) ⇒ ArrayIdentityCommand

Returns a new instance of ArrayIdentityCommand.



804
805
806
807
808
809
810
811
812
813
814
815
# File 'lib/symbolic/symbolic.rb', line 804

def initialize(target, block_size: DEFAULT_BLOCK_SIZE, dimensions: nil)
    super(block_size: block_size)

    # Ensure that base array cannot be modified
    target.freeze

    # One thread per array element
    @target = target
    @input = [SingleInput.new(command: target, pattern: :tid)]

    @dimensions = dimensions
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



800
801
802
# File 'lib/symbolic/symbolic.rb', line 800

def target
  @target
end

Instance Method Details

#accept(visitor) ⇒ Object



34
35
36
# File 'lib/symbolic/visitor.rb', line 34

def accept(visitor)
    visitor.visit_array_identity_command(self)
end

#base_typeObject



839
840
841
842
843
844
845
846
847
848
# File 'lib/symbolic/symbolic.rb', line 839

def base_type
    # TODO: add caching (`input` is frozen)
    type = Types::UnionType.new

    input.first.command.each do |element|
        type.add(element.class.to_ikra_type)
    end

    return type
end

#dimensionsObject



825
826
827
828
829
830
831
# File 'lib/symbolic/symbolic.rb', line 825

def dimensions
    if @dimensions == nil
        return [size]
    else
        return @dimensions
    end
end

#executeObject



817
818
819
# File 'lib/symbolic/symbolic.rb', line 817

def execute
    return input.first.command
end

#externalsObject

Returns a collection of external objects that are accessed within a parallel section. This includes all elements of the base array.



835
836
837
# File 'lib/symbolic/symbolic.rb', line 835

def externals
    lexical_externals.keys + input.first.command
end

#sizeObject



821
822
823
# File 'lib/symbolic/symbolic.rb', line 821

def size
    return input.first.command.size
end