Method: BOAST::Variable#initialize

Defined in:
lib/BOAST/Language/Variable.rb

#initialize(name, type, properties = {}) ⇒ Variable

Creates a new BOAST::Variable

Parameters:

  • name (#to_s)
  • type (DataType)
  • properties (Hash) (defaults to: {})

    a set of named properties. Properties are also propagated to the DataType.

Options Hash (properties):

  • :direction (Symbol) — default: or *:dir*

    can be one of :in, :out or :inout. Specify the intent of the variable.

  • :dimension (Array<Dimension>) — default: or *:dim*

    variable is an array rather than a scalar. Dimensions are given in Fortran order (contiguous first).

  • :constant (Object) — default: or *:const*

    states that the variable is a constant and give its value. For Variable with the :dimension property set must be a ConstArray

  • :restrict (Boolean)

    specifies that the compiler can assume no aliasing to this array.

  • :reference (Boolean)

    specifies that this variable is passed by reference.

  • :allocate (Symbol)

    specify that the variable is to be allocated and where. Can only be :heap or :stack for now.

  • :local (Boolean)

    indicates that the variable is to be allocated on the __local space of OpenCL devices or __shared__ space of CUDA devices. In C or FORTRAN this has the same effect as :allocate => :stack.

  • :texture (Boolean)

    for OpenCL and CUDA. In OpenCL also specifies that a sampler has to be generated to access the array variable.

  • :align (Integer)

    specifies the alignment the variable will be declared/allocated with if allocated or is supposed to have if it is coming from another context (in bytes).

  • :replace_constant (Boolean)

    specifies that for scalar constants this variable should be replaced by its constant value. For constant arrays, the value of the array will be replaced if the index can be determined at evaluation.

  • :deferred_shape (Boolean)

    for Fortran interface generation mainly see Fortran documentation

  • :optional (Boolean)

    for Fortran interface generation mainly see Fortran documentation



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/BOAST/Language/Variable.rb', line 265

def initialize(name, type, properties={})
  @name = name.to_s
  @direction = properties[:direction]
  @direction = properties[:dir] unless @direction

  @constant = properties[:constant]
  @constant = properties[:const] unless @constant

  @dimension = properties[:dimension]
  @dimension = properties[:dim] unless @dimension

  @local = properties[:local]
  @local = properties[:shared] unless @local

  @texture = properties[:texture]
  @allocate = properties[:allocate]
  @restrict = properties[:restrict]
  @alignment = properties[:align]
  @deferred_shape = properties[:deferred_shape]
  @optional = properties[:optional]
  @reference = properties[:reference]
  @force_replace_constant = false
  @replace_constant = properties[:replace_constant]

  if @texture and lang == CL then
    @sampler = Variable::new("sampler_#{name}", CustomType,:type_name => "sampler_t" ,:replace_constant => false, :constant => "CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST")
  else
    @sampler = nil
  end

  @scalar_output = false
  if @dimension then
    @dimension = [@dimension].flatten
  else
    @scalar_output = true if @direction == :out or @direction == :inout
  end

  @type = type::new(properties)
  @properties = properties
end