Class: BOAST::Procedure
Instance Attribute Summary collapse
-
#constants ⇒ Object
readonly
Returns the value of attribute constants.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #call(*parameters) ⇒ Object
- #close(final = true) ⇒ Object
- #close_c(final = true) ⇒ Object
- #close_fortran(final = true) ⇒ Object
- #decl(final = true) ⇒ Object
- #decl_c(final = true) ⇒ Object
- #decl_fortran(final = true) ⇒ Object
- #header(lang = C, final = true) ⇒ Object
-
#initialize(name, parameters = [], constants = [], properties = {}, &block) ⇒ Procedure
constructor
A new instance of Procedure.
- #print(final = true) ⇒ Object
Constructor Details
#initialize(name, parameters = [], constants = [], properties = {}, &block) ⇒ Procedure
Returns a new instance of Procedure.
867 868 869 870 871 872 873 874 875 |
# File 'lib/BOAST/Algorithm.rb', line 867 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
#constants ⇒ Object (readonly)
Returns the value of attribute constants.
864 865 866 |
# File 'lib/BOAST/Algorithm.rb', line 864 def constants @constants end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
866 867 868 |
# File 'lib/BOAST/Algorithm.rb', line 866 def headers @headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
862 863 864 |
# File 'lib/BOAST/Algorithm.rb', line 862 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
863 864 865 |
# File 'lib/BOAST/Algorithm.rb', line 863 def parameters @parameters end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
865 866 867 |
# File 'lib/BOAST/Algorithm.rb', line 865 def properties @properties end |
Class Method Details
.parens(*args, &block) ⇒ Object
858 859 860 |
# File 'lib/BOAST/Algorithm.rb', line 858 def self.parens(*args,&block) return self::new(*args,&block) end |
Instance Method Details
#call(*parameters) ⇒ Object
917 918 919 920 921 922 923 |
# File 'lib/BOAST/Algorithm.rb', line 917 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
928 929 930 931 |
# File 'lib/BOAST/Algorithm.rb', line 928 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
932 933 934 935 936 937 938 939 |
# File 'lib/BOAST/Algorithm.rb', line 932 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
940 941 942 943 944 945 946 947 948 949 950 951 |
# File 'lib/BOAST/Algorithm.rb', line 940 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
924 925 926 927 |
# File 'lib/BOAST/Algorithm.rb', line 924 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
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/BOAST/Algorithm.rb', line 962 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
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 |
# File 'lib/BOAST/Algorithm.rb', line 1010 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
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 |
# File 'lib/BOAST/Algorithm.rb', line 877 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 |
#print(final = true) ⇒ Object
953 954 955 956 957 958 959 960 |
# File 'lib/BOAST/Algorithm.rb', line 953 def print(final=true) s = self.decl if @block then @block.call s += self.close end return s end |