Class: BOAST::Procedure

Inherits:
Object show all
Defined in:
lib/BOAST/Algorithm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parameters = [], constants = [], properties = {}, &block) ⇒ Procedure

Returns a new instance of Procedure.



782
783
784
785
786
787
788
789
790
# File 'lib/BOAST/Algorithm.rb', line 782

def initialize(name, parameters=[], constants=[], properties={}, &block)
  @name = name
  @parameters = parameters
  @constants = constants
  @block = block
  @properties = properties
  @headers = properties[:headers]
  @headers = [] if not @headers
end

Instance Attribute Details

#constantsObject (readonly)

Returns the value of attribute constants.



779
780
781
# File 'lib/BOAST/Algorithm.rb', line 779

def constants
  @constants
end

#headersObject (readonly)

Returns the value of attribute headers.



781
782
783
# File 'lib/BOAST/Algorithm.rb', line 781

def headers
  @headers
end

#nameObject (readonly)

Returns the value of attribute name.



777
778
779
# File 'lib/BOAST/Algorithm.rb', line 777

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



778
779
780
# File 'lib/BOAST/Algorithm.rb', line 778

def parameters
  @parameters
end

#propertiesObject (readonly)

Returns the value of attribute properties.



780
781
782
# File 'lib/BOAST/Algorithm.rb', line 780

def properties
  @properties
end

Class Method Details

.parens(*args, &block) ⇒ Object



773
774
775
# File 'lib/BOAST/Algorithm.rb', line 773

def self.parens(*args,&block)
  return self::new(*args,&block)
end

Instance Method Details

#call(*parameters) ⇒ Object



832
833
834
835
836
837
838
# File 'lib/BOAST/Algorithm.rb', line 832

def call(*parameters)
  prefix = ""
  prefix += "call " if BOAST::get_lang==FORTRAN
  f = FuncCall::new(@name, *parameters)
  f.prefix = prefix
  return f
end

#close(final = true) ⇒ Object



843
844
845
846
# File 'lib/BOAST/Algorithm.rb', line 843

def close(final=true)
  return self.close_fortran(final) if BOAST::get_lang==FORTRAN
  return self.close_c(final) if [C, CL, CUDA].include?( BOAST::get_lang )
end

#close_c(final = true) ⇒ Object



847
848
849
850
851
852
853
854
# File 'lib/BOAST/Algorithm.rb', line 847

def close_c(final=true)
  BOAST::decrement_indent_level
  s = ""
  s += "  return #{@properties[:return]};\n" if @properties[:return]
  s += "}"
  BOAST::get_output.puts s if final
  return s
end

#close_fortran(final = true) ⇒ Object



855
856
857
858
859
860
861
862
863
864
865
866
# File 'lib/BOAST/Algorithm.rb', line 855

def close_fortran(final=true)
  BOAST::decrement_indent_level
  s = ""
  if @properties[:return] then
    s += "  #{@name} = #{@properties[:return]}\n"
    s += "END FUNCTION #{@name}"
  else
    s += "END SUBROUTINE #{@name}"
  end
  BOAST::get_output.puts s if final
  return s
end

#decl(final = true) ⇒ Object



839
840
841
842
# File 'lib/BOAST/Algorithm.rb', line 839

def decl(final=true)
  return self.decl_fortran(final) if BOAST::get_lang==FORTRAN
  return self.decl_c(final) if [C, CL, CUDA].include?( BOAST::get_lang )
end

#decl_c(final = true) ⇒ Object



877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'lib/BOAST/Algorithm.rb', line 877

def decl_c(final=true)
  s = ""
#      s += self.header(BOAST::get_lang,false)
#      s += ";\n"
  if BOAST::get_lang == CL then
    if not @properties[:local] then
      s += "__kernel "
      wgs = @properties[:reqd_work_group_size]
      if wgs then
        s += "__attribute__((reqd_work_group_size(#{wgs[0]},#{wgs[1]},#{wgs[2]}))) "
      end
    end
  elsif BOAST::get_lang == CUDA then
    if @properties[:local] then
      s += "static __device__ "
    else
      s += "__global__ "
      wgs = @properties[:reqd_work_group_size]
      if wgs then
        s += "__launch_bounds__(#{wgs[0]}*#{wgs[1]}*#{wgs[2]}) "
      end
    end
  end
  if @properties[:qualifiers] then
    s += "#{@properties[:qualifiers]} "
  end
  if @properties[:return] then
    s += "#{@properties[:return].type.decl} "
  else
    s += "void "
  end
  s += "#{@name}("
  if parameters.first then
    s += parameters.first.decl(false, @properties[:local])
    parameters[1..-1].each { |p|
      s += ", "+p.decl(false, @properties[:local])
    }
  end
  s += "){\n"
  BOAST::increment_indent_level
  constants.each { |c|
    s += " "*BOAST::get_indent_level
    s += c.decl(false)
    s += ";\n"
  }
  BOAST::get_output.print s if final
  return s
end

#decl_fortran(final = true) ⇒ Object



925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
# File 'lib/BOAST/Algorithm.rb', line 925

def decl_fortran(final=true)
  s = ""
  if @properties[:return] then
    s += "#{@properties[:return].type.decl} FUNCTION "
  else
    s += "SUBROUTINE "
  end
  s += "#{@name}("
  if parameters.first then
    s += parameters.first
    parameters[1..-1].each { |p|
      s += ", "+p
    }
  end
  s += ")\n"
  BOAST::increment_indent_level
  s += " "*BOAST::get_indent_level + "integer, parameter :: wp=kind(1.0d0)\n"
  constants.each { |c|
    s += " "*BOAST::get_indent_level
    s += c.decl(false)
    s += "\n"
  }
  parameters.each { |p|
    s += " "*BOAST::get_indent_level
    s += p.decl(false)
    s += "\n"
  }
  BOAST::get_output.print s if final
  return s
end

#header(lang = C, final = true) ⇒ Object



792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
# File 'lib/BOAST/Algorithm.rb', line 792

def header(lang=C,final=true)
  s = ""
  headers.each { |h|
    s += "#include <#{h}>\n"
  }
  if BOAST::get_lang == CL then
    s += "__kernel "
    wgs = @properties[:reqd_work_group_size]
    if wgs then
      s += "__attribute__((reqd_work_group_size(#{wgs[0]},#{wgs[1]},#{wgs[2]}))) "
    end
  end
  trailer = ""
  trailer += "_" if lang == FORTRAN
  trailer += "_wrapper" if lang == CUDA
  if @properties[:return] then
    s += "#{@properties[:return].type.decl} "
  elsif lang == CUDA
    s += "unsigned long long int "
  else
    s += "void "
  end
  s += "#{@name}#{trailer}("
  if parameters.first then
    s += parameters.first.header(lang,false)
    parameters[1..-1].each { |p|
      s += ", "
      s += p.header(lang,false)
    }
  end
  if lang == CUDA then
    s += ", " if parameters.first
    s += "size_t *block_number, size_t *block_size"
  end
  s += ")"
  s += ";\n" if final
  BOAST::get_output.print s if final
  return s
end


868
869
870
871
872
873
874
875
# File 'lib/BOAST/Algorithm.rb', line 868

def print(final=true)
  s = self.decl
  if @block then
    @block.call
    s += self.close
  end
  return s
end