Class: BOAST::Variable
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, type, hash = {}) ⇒ Variable
Returns a new instance of Variable.
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
# File 'lib/BOAST/Algorithm.rb', line 487
def initialize(name,type,hash={})
@name = name.to_s
@direction = hash[:direction] ? hash[:direction] : hash[:dir]
@constant = hash[:constant] ? hash[:constant] : hash[:const]
@dimension = hash[:dimension] ? hash[:dimension] : hash[:dim]
@local = hash[:local] ? hash[:local] : hash[:shared]
@texture = hash[:texture]
@allocate = hash[:allocate]
@restrict = hash[:restrict]
@force_replace_constant = false
if not hash[:replace_constant].nil? then
@replace_constant = hash[:replace_constant]
else
@replace_constant = true
end
if @texture and BOAST::get_lang == CL then
@sampler = Variable::new("sampler_#{name}", BOAST::CustomType,:type_name => "sampler_t" ,:replace_constant => false, :constant => "CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST")
else
@sampler = nil
end
@type = type::new(hash)
@hash = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
463
464
465
466
467
468
|
# File 'lib/BOAST/Algorithm.rb', line 463
def method_missing(m, *a, &b)
return self.struct_reference(type.members[m.to_s]) if type.members[m.to_s]
return self.orig_method_missing(m, *a, &b)
end
|
Instance Attribute Details
Returns the value of attribute allocate.
477
478
479
|
# File 'lib/BOAST/Algorithm.rb', line 477
def allocate
@allocate
end
|
Returns the value of attribute constant.
476
477
478
|
# File 'lib/BOAST/Algorithm.rb', line 476
def constant
@constant
end
|
#dimension ⇒ Object
Returns the value of attribute dimension.
479
480
481
|
# File 'lib/BOAST/Algorithm.rb', line 479
def dimension
@dimension
end
|
#direction ⇒ Object
Returns the value of attribute direction.
475
476
477
|
# File 'lib/BOAST/Algorithm.rb', line 475
def direction
@direction
end
|
#force_replace_constant ⇒ Object
Returns the value of attribute force_replace_constant.
485
486
487
|
# File 'lib/BOAST/Algorithm.rb', line 485
def force_replace_constant
@force_replace_constant
end
|
Returns the value of attribute local.
480
481
482
|
# File 'lib/BOAST/Algorithm.rb', line 480
def local
@local
end
|
Returns the value of attribute name.
474
475
476
|
# File 'lib/BOAST/Algorithm.rb', line 474
def name
@name
end
|
#replace_constant ⇒ Object
Returns the value of attribute replace_constant.
484
485
486
|
# File 'lib/BOAST/Algorithm.rb', line 484
def replace_constant
@replace_constant
end
|
Returns the value of attribute restrict.
483
484
485
|
# File 'lib/BOAST/Algorithm.rb', line 483
def restrict
@restrict
end
|
Returns the value of attribute sampler.
482
483
484
|
# File 'lib/BOAST/Algorithm.rb', line 482
def sampler
@sampler
end
|
Returns the value of attribute texture.
481
482
483
|
# File 'lib/BOAST/Algorithm.rb', line 481
def texture
@texture
end
|
Returns the value of attribute type.
478
479
480
|
# File 'lib/BOAST/Algorithm.rb', line 478
def type
@type
end
|
Class Method Details
.from_type(name, type, options = {}) ⇒ Object
519
520
521
522
523
524
525
|
# File 'lib/BOAST/Algorithm.rb', line 519
def Variable.from_type(name, type, options={})
hash = type.to_hash
options.each { |k,v|
hash[k] = v
}
return Variable::new(name, type.class, hash)
end
|
.parens(*args, &block) ⇒ Object
470
471
472
|
# File 'lib/BOAST/Algorithm.rb', line 470
def self.parens(*args,&block)
return self::new(*args,&block)
end
|
Instance Method Details
584
585
586
|
# File 'lib/BOAST/Algorithm.rb', line 584
def !
return Expression::new(BOAST::Not,nil,self)
end
|
560
561
562
|
# File 'lib/BOAST/Algorithm.rb', line 560
def <(x)
return Expression::new("<",self,x)
end
|
552
553
554
|
# File 'lib/BOAST/Algorithm.rb', line 552
def ==(x)
return Expression::new("==",self,x)
end
|
556
557
558
|
# File 'lib/BOAST/Algorithm.rb', line 556
def >(x)
return Expression::new(">",self,x)
end
|
564
565
566
|
# File 'lib/BOAST/Algorithm.rb', line 564
def >=(x)
return Expression::new(">=",self,x)
end
|
#[](*args) ⇒ Object
611
612
613
|
# File 'lib/BOAST/Algorithm.rb', line 611
def [](*args)
return Index::new(self,args)
end
|
592
593
594
|
# File 'lib/BOAST/Algorithm.rb', line 592
def address
return Expression::new("&",nil,self)
end
|
#copy(name = @name, options = {}) ⇒ Object
511
512
513
514
515
516
517
|
# File 'lib/BOAST/Algorithm.rb', line 511
def copy(name=@name,options={})
hash = @hash.clone
options.each { |k,v|
hash[k] = v
}
return Variable::new(name, @type.class, hash)
end
|
#decl(final = true, device = false) ⇒ Object
690
691
692
693
|
# File 'lib/BOAST/Algorithm.rb', line 690
def decl(final=true,device=false)
return self.decl_fortran(final) if BOAST::get_lang == FORTRAN
return self.decl_c(final, device) if [C, CL, CUDA].include?( BOAST::get_lang )
end
|
#decl_c(final = true, device = false) ⇒ Object
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
|
# File 'lib/BOAST/Algorithm.rb', line 626
def decl_c(final=true, device=false)
return decl_texture(final) if @texture
s = ""
s += self.indent if final
s += "const " if @constant or @direction == :in
s += "__global " if @direction and @dimension and not (@hash[:register] or @hash[:private] or @local) and BOAST::get_lang == CL
s += "__local " if @local and BOAST::get_lang == CL
s += "__shared__ " if @local and not device and BOAST::get_lang == CUDA
s += @type.decl
if(@dimension and not @constant and not @allocate and (not @local or (@local and device))) then
s += " *"
if @restrict then
if BOAST::get_lang == CL
s += " restrict"
else
s += " __restrict__"
end
end
end
s += " #{@name}"
if @dimension and @constant then
s += "[]"
end
if @dimension and ((@local and not device) or (@allocate and not @constant)) then
s +="["
s += @dimension.reverse.join("*")
s +="]"
end
s += " = #{@constant}" if @constant
s += self.finalize if final
BOAST::get_output.print s if final
return s
end
|
#decl_fortran(final = true) ⇒ Object
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
|
# File 'lib/BOAST/Algorithm.rb', line 722
def decl_fortran(final=true)
s = ""
s += self.indent if final
s += @type.decl
s += ", intent(#{@direction})" if @direction
s += ", parameter" if @constant
if(@dimension) then
s += ", dimension("
dim = @dimension[0].to_str
if dim then
s += dim
@dimension[1..-1].each { |d|
s += ", "
s += d
}
else
s += ":"
end
s += ")"
end
s += " :: #{@name}"
if @constant
s += " = #{@constant}"
s += "_wp" if not @dimension and @type and @type.size == 8
end
s += self.finalize if final
BOAST::get_output.print s if final
return s
end
|
#decl_texture(final = true) ⇒ Object
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
# File 'lib/BOAST/Algorithm.rb', line 695
def decl_texture(final=true)
raise "Unsupported language #{BOAST::get_lang} for texture!" if not [CL, CUDA].include?( BOAST::get_lang )
raise "Write is unsupported for textures!" if not (@constant or @direction == :in)
dim_number = 1
if @dimension then
dim_number == @dimension.size
end
raise "Unsupported number of dimension: #{dim_number}!" if dim_number > 3
s = ""
s += self.indent if final
if BOAST::get_lang == CL then
s += "__read_only "
if dim_number < 3 then
s += "image2d_t " else
s += "image3d_t "
end
else
s += "texture<#{@type.decl}, cudaTextureType#{dim_number}D, cudaReadModeElementType> "
end
s += @name
s += self.finalize if final
BOAST::get_output.print s if final
return s
end
|
#dereference ⇒ Object
596
597
598
599
600
|
# File 'lib/BOAST/Algorithm.rb', line 596
def dereference
return self.copy("*(#{self.name})", :dimension => false, :dim => false) if [C, CL, CUDA].include?( BOAST::get_lang )
return self if BOAST::get_lang == FORTRAN
end
|
619
620
621
622
623
624
|
# File 'lib/BOAST/Algorithm.rb', line 619
def finalize
s = ""
s += ";" if [C, CL, CUDA].include?( BOAST::get_lang )
s+="\n"
return s
end
|
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
# File 'lib/BOAST/Algorithm.rb', line 660
def (lang=C,final=true)
return decl_texture(final) if @texture
s = ""
s += self.indent if final
s += "const " if @constant or @direction == :in
s += "__global " if @direction and @dimension and BOAST::get_lang == CL
s += "__local " if @local and BOAST::get_lang == CL
s += "__shared__ " if @local and BOAST::get_lang == CUDA
s += @type.decl
if(@dimension and not @constant and not @local) then
s += " *"
end
if not @dimension and lang == FORTRAN then
s += " *"
end
s += " #{@name}"
if(@dimension and @constant) then
s += "[]"
end
if(@dimension and @local) then
s +="["
s += @dimension.reverse.join("*")
s +="]"
end
s += " = #{@constant}" if @constant
s += self.finalize if final
BOAST::get_output.print s if final
return s
end
|
607
608
609
|
# File 'lib/BOAST/Algorithm.rb', line 607
def inc
return Expression::new("++",self,nil)
end
|
#orig_method_missing ⇒ Object
461
|
# File 'lib/BOAST/Algorithm.rb', line 461
alias_method :orig_method_missing, :method_missing
|
544
545
546
|
# File 'lib/BOAST/Algorithm.rb', line 544
def set(x)
return Expression::new(BOAST::Set, self, x)
end
|
#struct_reference(x) ⇒ Object
602
603
604
605
|
# File 'lib/BOAST/Algorithm.rb', line 602
def struct_reference(x)
return x.copy(self.name+"."+x.name) if [C, CL, CUDA].include?( BOAST::get_lang )
return x.copy(self.name+"%"+x.name) if BOAST::get_lang == FORTRAN
end
|
527
528
529
|
# File 'lib/BOAST/Algorithm.rb', line 527
def to_s
self.to_str
end
|
531
532
533
534
535
536
537
538
|
# File 'lib/BOAST/Algorithm.rb', line 531
def to_str
if @force_replace_constant or ( @replace_constant and @constant and BOAST::get_replace_constants and not @dimension ) then
s = @constant.to_s
s += "_wp" if BOAST::get_lang == FORTRAN and @type and @type.size == 8
return s
end
return @name
end
|
540
541
542
|
# File 'lib/BOAST/Algorithm.rb', line 540
def to_var
return self
end
|