Class: BOAST::Index
Instance Attribute Summary collapse
Attributes inherited from Expression
#operand1, #operand2, #operator
Instance Method Summary
collapse
Methods inherited from Expression
#!, #*, #+, #-, #-@, #/, #<, #==, #===, #>, #>=, #dereference, parens, #struct_reference, to_str_base
Constructor Details
#initialize(source, indexes) ⇒ Index
Returns a new instance of Index.
342
343
344
345
|
# File 'lib/BOAST/Algorithm.rb', line 342
def initialize(source, indexes)
@source = source
@indexes = indexes
end
|
Instance Attribute Details
Returns the value of attribute indexes.
341
342
343
|
# File 'lib/BOAST/Algorithm.rb', line 341
def indexes
@indexes
end
|
Returns the value of attribute source.
340
341
342
|
# File 'lib/BOAST/Algorithm.rb', line 340
def source
@source
end
|
Instance Method Details
351
352
353
|
# File 'lib/BOAST/Algorithm.rb', line 351
def to_s
self.to_str
end
|
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
# File 'lib/BOAST/Algorithm.rb', line 408
def to_str_c
return to_str_texture if @source.texture
dim = @source.dimension.first
if dim.val2 then
start = dim.val1
else
start = BOAST::get_array_start
end
sub = "#{@indexes.first} - (#{start})"
i=1
ss = ""
@source.dimension[0..-2].each{ |d|
if d.size then
ss += " * (#{d.size})"
elsif d.val2 then
ss += " * (#{d.val2} - (#{d.val1}) + 1)"
else
raise "Unkwown dimension size!"
end
dim = @source.dimension[i]
if dim.val2 then
start = dim.val1
else
start = BOAST::get_array_start
end
sub += " + (#{@indexes[i]} - (#{start}))"+ss
i+=1
}
if BOAST::get_replace_constants then
begin
indx = eval(sub)
indx = indx.to_i
return "#{@source.constant[indx]}"
rescue Exception => e
end
end
s = "#{@source}[" + sub + "]"
return s
end
|
#to_str_fortran ⇒ Object
358
359
360
361
362
|
# File 'lib/BOAST/Algorithm.rb', line 358
def to_str_fortran
s = ""
s += "#{@source}(#{@indexes.join(", ")})"
return s
end
|
#to_str_texture ⇒ Object
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# File 'lib/BOAST/Algorithm.rb', line 363
def to_str_texture
raise "Unsupported language #{BOAST::get_lang} for texture!" if not [CL, CUDA].include?( BOAST::get_lang )
raise "Write is unsupported for textures!" if not ( @source.constant or @source.direction == :in )
dim_number = 1
if @source.dimension then
dim_number == @source.dimension.size
end
raise "Unsupported number of dimension: #{dim_number}!" if dim_number > 3
s = ""
if BOAST::get_lang == CL then
s += "as_#{@source.type.decl}("
s += "read_imageui(#{@source}, #{@source.sampler}, "
if dim_number == 1 then
s += "int2(#{@indexes[0]},0)"
else
if dim_number == 2 then
s += "int2("
else
s += "int3("
end
s += "#{@indexes.join(", ")})"
end
s += ")"
if @source.type.size == 4 then
s += ".x"
elsif @source.type.size == 8 then
s += ".xy"
end
s += ")"
else
s += "tex#{dim_number}Dfetch(#{@source},"
if dim_number == 1 then
s += "#{@indexes[0]}"
else
if dim_number == 2 then
s += "int2("
else
s += "int3("
end
s += "#{@indexes.join(", ")})"
end
s += ")"
end
return s
end
|
347
348
349
|
# File 'lib/BOAST/Algorithm.rb', line 347
def to_var
return @source.copy("#{self}", :const => nil, :constant => nil, :dim => nil, :dimension => nil)
end
|