BOAST 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/BOAST.gemspec +2 -2
  3. data/lib/BOAST.rb +1 -0
  4. data/lib/BOAST/Language/Algorithm.rb +68 -30
  5. data/lib/BOAST/Language/Annotation.rb +1 -0
  6. data/lib/BOAST/Language/Architectures.rb +1 -0
  7. data/lib/BOAST/Language/Arithmetic.rb +15 -9
  8. data/lib/BOAST/Language/BOAST_OpenCL.rb +94 -87
  9. data/lib/BOAST/Language/CPUID_by_name.rb +1 -0
  10. data/lib/BOAST/Language/Case.rb +6 -0
  11. data/lib/BOAST/Language/CodeBlock.rb +1 -0
  12. data/lib/BOAST/Language/Comment.rb +14 -11
  13. data/lib/BOAST/Language/Config.rb +23 -15
  14. data/lib/BOAST/Language/ControlStructure.rb +10 -2
  15. data/lib/BOAST/Language/DataTypes.rb +23 -15
  16. data/lib/BOAST/Language/Expression.rb +3 -0
  17. data/lib/BOAST/Language/For.rb +31 -26
  18. data/lib/BOAST/Language/FuncCall.rb +7 -0
  19. data/lib/BOAST/Language/Functors.rb +56 -19
  20. data/lib/BOAST/Language/If.rb +3 -0
  21. data/lib/BOAST/Language/Index.rb +11 -9
  22. data/lib/BOAST/Language/Intrinsics.rb +2 -0
  23. data/lib/BOAST/Language/OpenMP.rb +57 -40
  24. data/lib/BOAST/Language/Operators.rb +27 -19
  25. data/lib/BOAST/Language/Pragma.rb +1 -0
  26. data/lib/BOAST/Language/Print.rb +3 -0
  27. data/lib/BOAST/Language/Procedure.rb +81 -76
  28. data/lib/BOAST/Language/Slice.rb +16 -14
  29. data/lib/BOAST/Language/State.rb +126 -55
  30. data/lib/BOAST/Language/Transitions.rb +26 -26
  31. data/lib/BOAST/Language/Variable.rb +89 -58
  32. data/lib/BOAST/Language/While.rb +3 -0
  33. data/lib/BOAST/Runtime/AffinityProbe.rb +65 -0
  34. data/lib/BOAST/Runtime/CKernel.rb +44 -1
  35. data/lib/BOAST/Runtime/CRuntime.rb +3 -0
  36. data/lib/BOAST/Runtime/CUDARuntime.rb +3 -0
  37. data/lib/BOAST/Runtime/CompiledRuntime.rb +4 -0
  38. data/lib/BOAST/Runtime/Compilers.rb +6 -5
  39. data/lib/BOAST/Runtime/Config.rb +1 -1
  40. data/lib/BOAST/Runtime/FFIRuntime.rb +3 -0
  41. data/lib/BOAST/Runtime/FORTRANRuntime.rb +3 -0
  42. data/lib/BOAST/Runtime/MPPARuntime.rb +2 -0
  43. data/lib/BOAST/Runtime/NonRegression.rb +5 -3
  44. data/lib/BOAST/Runtime/OpenCLRuntime.rb +7 -10
  45. data/lib/BOAST/Runtime/Probe.rb +2 -0
  46. metadata +7 -6
@@ -1,5 +1,6 @@
1
1
  module BOAST
2
2
 
3
+ # @!parse module Functors; functorize Pragma; end
3
4
  class Pragma
4
5
  include PrivateStateAccessor
5
6
  include Inspectable
@@ -1,9 +1,12 @@
1
1
  module BOAST
2
2
 
3
+
4
+ # @deprecated
3
5
  def self.print(a, *args)
4
6
  pr(a, *args)
5
7
  end
6
8
 
9
+ # @deprecated
7
10
  def self.open(a)
8
11
  opn(a)
9
12
  end
@@ -1,5 +1,6 @@
1
1
  module BOAST
2
2
 
3
+ # @!parse module Functors; functorize Procedure; end
3
4
  class Procedure
4
5
  include PrivateStateAccessor
5
6
  include Inspectable
@@ -13,54 +14,18 @@ module BOAST
13
14
  attr_reader :properties
14
15
  attr_reader :headers
15
16
 
16
- def initialize(name, parameters=[], constants=[], properties={}, &block)
17
+ def initialize(name, parameters=[], properties={}, &block)
17
18
  @name = name
18
19
  @parameters = parameters
19
- @constants = constants
20
+ @constants = properties[:constants]
21
+ @constants = [] unless @constants
20
22
  @block = block
21
23
  @properties = properties
22
24
  @headers = properties[:headers]
23
- @headers = [] if not @headers
24
- end
25
-
26
- def boast_header_s( lang=C )
27
- s = ""
28
- headers.each { |h|
29
- s += "#include <#{h}>\n"
30
- }
31
- if lang == CL then
32
- s += "__kernel "
33
- wgs = @properties[:reqd_work_group_size]
34
- if wgs then
35
- s += "__attribute__((reqd_work_group_size(#{wgs[0]},#{wgs[1]},#{wgs[2]}))) "
36
- end
37
- end
38
- trailer = ""
39
- trailer += "_" if lang == FORTRAN
40
- trailer += "_wrapper" if lang == CUDA
41
- if @properties[:return] then
42
- s += "#{@properties[:return].type.decl} "
43
- elsif lang == CUDA
44
- s += "unsigned long long int "
45
- else
46
- s += "void "
47
- end
48
- s += "#{@name}#{trailer}("
49
- if parameters.first then
50
- s += parameters.first.boast_header(lang)
51
- parameters[1..-1].each { |p|
52
- s += ", "
53
- s += p.boast_header(lang)
54
- }
55
- end
56
- if lang == CUDA then
57
- s += ", " if parameters.first
58
- s += "size_t *block_number, size_t *block_size"
59
- end
60
- s += ")"
61
- return s
25
+ @headers = [] unless @headers
62
26
  end
63
27
 
28
+ # @private
64
29
  def boast_header(lang=C)
65
30
  s = boast_header_s(lang)
66
31
  s += ";\n"
@@ -90,29 +55,6 @@ module BOAST
90
55
  return k
91
56
  end
92
57
 
93
- def close_c
94
- s = ""
95
- s += indent + "return #{@properties[:return]};\n" if @properties[:return]
96
- decrement_indent_level
97
- s += indent + "}"
98
- output.puts s
99
- return self
100
- end
101
-
102
- def close_fortran
103
- s = ""
104
- if @properties[:return] then
105
- s += indent + "#{@name} = #{@properties[:return]}\n"
106
- decrement_indent_level
107
- s += indent + "END FUNCTION #{@name}"
108
- else
109
- decrement_indent_level
110
- s += indent + "END SUBROUTINE #{@name}"
111
- end
112
- output.puts s
113
- return self
114
- end
115
-
116
58
  def pr
117
59
  open
118
60
  if @block then
@@ -127,6 +69,18 @@ module BOAST
127
69
  return decl_c if [C, CL, CUDA].include?( lang )
128
70
  end
129
71
 
72
+ def open
73
+ return open_fortran if lang==FORTRAN
74
+ return open_c if [C, CL, CUDA].include?( lang )
75
+ end
76
+
77
+ def to_s
78
+ return decl_c_s if [C, CL, CUDA].include?( lang )
79
+ return to_s_fortran if lang==FORTRAN
80
+ end
81
+
82
+ private
83
+
130
84
  def decl_fortran
131
85
  output.puts indent + "INTERFACE"
132
86
  increment_indent_level
@@ -179,9 +133,9 @@ module BOAST
179
133
  end
180
134
  s += "#{@name}("
181
135
  if parameters.first then
182
- s += parameters.first.decl_c_s(@properties[:local])
136
+ s += parameters.first.send(:decl_c_s, @properties[:local])
183
137
  parameters[1..-1].each { |p|
184
- s += ", "+p.decl_c_s(@properties[:local])
138
+ s += ", "+p.send(:decl_c_s, @properties[:local])
185
139
  }
186
140
  end
187
141
  s += ")"
@@ -194,16 +148,6 @@ module BOAST
194
148
  return self
195
149
  end
196
150
 
197
- def open
198
- return open_fortran if lang==FORTRAN
199
- return open_c if [C, CL, CUDA].include?( lang )
200
- end
201
-
202
- def to_s
203
- return decl_c_s if [C, CL, CUDA].include?( lang )
204
- return to_s_fortran if lang==FORTRAN
205
- end
206
-
207
151
  def to_s_fortran
208
152
  s = ""
209
153
  if @properties[:return] then
@@ -255,6 +199,67 @@ module BOAST
255
199
  return self
256
200
  end
257
201
 
202
+ def close_c
203
+ s = ""
204
+ s += indent + "return #{@properties[:return]};\n" if @properties[:return]
205
+ decrement_indent_level
206
+ s += indent + "}"
207
+ output.puts s
208
+ return self
209
+ end
210
+
211
+ def close_fortran
212
+ s = ""
213
+ if @properties[:return] then
214
+ s += indent + "#{@name} = #{@properties[:return]}\n"
215
+ decrement_indent_level
216
+ s += indent + "END FUNCTION #{@name}"
217
+ else
218
+ decrement_indent_level
219
+ s += indent + "END SUBROUTINE #{@name}"
220
+ end
221
+ output.puts s
222
+ return self
223
+ end
224
+
225
+ def boast_header_s( lang=C )
226
+ s = ""
227
+ headers.each { |h|
228
+ s += "#include <#{h}>\n"
229
+ }
230
+ if lang == CL then
231
+ s += "__kernel "
232
+ wgs = @properties[:reqd_work_group_size]
233
+ if wgs then
234
+ s += "__attribute__((reqd_work_group_size(#{wgs[0]},#{wgs[1]},#{wgs[2]}))) "
235
+ end
236
+ end
237
+ trailer = ""
238
+ trailer += "_" if lang == FORTRAN
239
+ trailer += "_wrapper" if lang == CUDA
240
+ if @properties[:return] then
241
+ s += "#{@properties[:return].type.decl} "
242
+ elsif lang == CUDA
243
+ s += "unsigned long long int "
244
+ else
245
+ s += "void "
246
+ end
247
+ s += "#{@name}#{trailer}("
248
+ if parameters.first then
249
+ s += parameters.first.boast_header(lang)
250
+ parameters[1..-1].each { |p|
251
+ s += ", "
252
+ s += p.boast_header(lang)
253
+ }
254
+ end
255
+ if lang == CUDA then
256
+ s += ", " if parameters.first
257
+ s += "size_t *block_number, size_t *block_size"
258
+ end
259
+ s += ")"
260
+ return s
261
+ end
262
+
258
263
  end
259
264
 
260
265
  end
@@ -13,6 +13,22 @@ module BOAST
13
13
  @slices = slices
14
14
  end
15
15
 
16
+ def to_s
17
+ return to_s_fortran if lang == FORTRAN
18
+ return to_s_c if [C, CL, CUDA].include?( lang )
19
+ end
20
+
21
+ def pr
22
+ s=""
23
+ s += indent
24
+ s += to_s
25
+ s += ";" if [C, CL, CUDA].include?( lang )
26
+ output.puts s
27
+ return self
28
+ end
29
+
30
+ private
31
+
16
32
  def to_s_c
17
33
  s = "#{@source}["
18
34
  dims = @source.dimension.reverse
@@ -67,20 +83,6 @@ module BOAST
67
83
  return "#{source}(#{slices_to_fortran.join(",")})"
68
84
  end
69
85
 
70
- def to_s
71
- return to_s_fortran if lang == FORTRAN
72
- return to_s_c if [C, CL, CUDA].include?( lang )
73
- end
74
-
75
- def pr
76
- s=""
77
- s += indent
78
- s += to_s
79
- s += ";" if [C, CL, CUDA].include?( lang )
80
- output.puts s
81
- return self
82
- end
83
-
84
86
  end
85
87
 
86
88
  class Variable
@@ -1,91 +1,162 @@
1
1
  module BOAST
2
2
 
3
- def self.state_accessor(*args)
4
- args.each { |arg|
5
- s = <<EOF
6
- def #{arg}=(val)
7
- @@#{arg} = val
3
+ EXTENDED = []
4
+ private_constant :EXTENDED
5
+
6
+ def self.included(base)
7
+ EXTENDED.each { |m|
8
+ base.send(:include, m)
9
+ }
10
+ end
11
+
12
+ # Generates setters and getters for the specified state
13
+ # @param [Symbol] state
14
+ # @!macro [attach] state_accessor
15
+ # @!method $1
16
+ # @scope class
17
+ # @return the BOAST *$1* state
18
+ # @!method $1=( val )
19
+ # @scope class
20
+ # Sets *$1* state to a new value
21
+ # @param val the new value of *$1* state
22
+ # @return the new +$1+ state
23
+ # @!method get_$1
24
+ # @scope class
25
+ # @return the *$1* state
26
+ # @!method set_$1( val )
27
+ # @scope class
28
+ # Sets *$1* state to a new value
29
+ # @param val the new value of *$1* state
30
+ # @return the new *$1* state
31
+ def self.state_accessor(state)
32
+ s = <<EOF
33
+ module_function
34
+
35
+ def #{state}=(val)
36
+ @@#{state} = val
8
37
  end
9
- module_function :#{arg}=
10
- def #{arg}
11
- @@#{arg}
38
+
39
+ def #{state}
40
+ @@#{state}
12
41
  end
13
- module_function :#{arg}
14
- def set_#{arg}(val)
15
- @@#{arg} = val
42
+
43
+ def set_#{state}(val)
44
+ @@#{state} = val
16
45
  end
17
- module_function :set_#{arg}
18
- def get_#{arg}
19
- @@#{arg}
46
+
47
+ def get_#{state}
48
+ @@#{state}
20
49
  end
21
- module_function :get_#{arg}
22
50
  EOF
23
- eval s
24
- }
51
+ eval s
25
52
  end
26
53
 
27
- def self.boolean_state_accessor(*args)
28
- self.state_accessor(*args)
29
- args.each { |arg|
30
- s = <<EOF
31
- def #{arg}?
32
- !!@@#{arg}
54
+ # Generates setters and getters for the specified boolean state
55
+ # @param [Symbol] state
56
+ # @!macro [attach] boolean_state_accessor
57
+ # @!method $1?
58
+ # @scope class
59
+ # @return the boolean evaluation of the *$1* state
60
+ # @!parse state_accessor $1
61
+ def self.boolean_state_accessor(state)
62
+ state_accessor(state)
63
+ s = <<EOF
64
+ module_function
65
+
66
+ def #{state}?
67
+ !!@@#{state}
33
68
  end
34
- module_function :#{arg}?
35
69
  EOF
36
- eval s
37
- }
70
+ eval s
38
71
  end
39
72
 
40
- def self.default_state_getter(arg, default, get_env_string=nil, env = arg.upcase)
73
+
74
+ # Generates an initializer for the specified state using default value or environment variable. Calls this initializer.
75
+ # @param [Symbol] state
76
+ # @param [Object] default default value
77
+ # @param [String] get_env_string if specified, an escaped string that can be evaluated. the envs variable can be used in the string to obtain what the corresponding environment variable was. Example: '"const_get(#{ envs })"'
78
+ # @param [Symbol] env name of the corresponding environment variable
79
+ # @!macro [attach] default_state_getter
80
+ # @!method get_default_$1
81
+ # @scope class
82
+ # @private
83
+ def self.default_state_getter(state, default, get_env_string=nil, env = state.upcase)
41
84
  envs = "ENV['#{env}']"
42
85
  s = <<EOF
43
- def get_default_#{arg}
44
- #{arg} = @@boast_config[#{arg.inspect}]
45
- #{arg} = #{default.inspect} unless #{arg}
46
- #{arg} = #{get_env_string ? eval( "#{get_env_string}" ) : "YAML::load(#{envs})" } if #{envs}
47
- return #{arg}
86
+ module_function
87
+
88
+ def get_default_#{state}
89
+ #{state} = @@boast_config[#{state.inspect}]
90
+ #{state} = #{default.inspect} unless #{state}
91
+ #{state} = #{get_env_string ? eval( "#{get_env_string}" ) : "YAML::load(#{envs})" } if #{envs}
92
+ return #{state}
48
93
  end
49
- module_function :get_default_#{arg}
50
- @@#{arg} = get_default_#{arg}
94
+
95
+ @@#{state} = get_default_#{state}
51
96
  EOF
52
97
  eval s
53
98
  end
54
99
 
100
+ # Implements private setters and getters interface for BOAST states.
101
+ # @private
55
102
  module PrivateStateAccessor
56
103
 
57
- def self.private_state_accessor(*args)
58
- args.each { |arg|
59
- s = <<EOF
60
104
  private
61
- def #{arg}=(val)
62
- BOAST::#{arg}= val
105
+
106
+ # Generates private setters and getters for the specified state
107
+ # @param [Symbol] state
108
+ # @!macro [attach] private_state_accessor
109
+ # @!method $1
110
+ # @return the BOAST *$1* state
111
+ # @private
112
+ # @!method $1=( val )
113
+ # Sets *$1* state to a new value
114
+ # @param val the new value of *$1* state
115
+ # @return the new +$1+ state
116
+ # @private
117
+ # @!method get_$1
118
+ # @return the *$1* state
119
+ # @private
120
+ # @!method set_$1( val )
121
+ # Sets *$1* state to a new value
122
+ # @param val the new value of *$1* state
123
+ # @return the new *$1* state
124
+ # @private
125
+ def self.private_state_accessor(state)
126
+ s = <<EOF
127
+ private
128
+ def #{state}=(val)
129
+ BOAST::set_#{state}(val)
63
130
  end
64
- def #{arg}
65
- BOAST::#{arg}
131
+ def #{state}
132
+ BOAST::get_#{state}
66
133
  end
67
- def set_#{arg}(val)
68
- BOAST::set_#{arg}(val)
134
+ def set_#{state}(val)
135
+ BOAST::set_#{state}(val)
69
136
  end
70
- def get_#{arg}
71
- BOAST::get_#{arg}
137
+ def get_#{state}
138
+ BOAST::get_#{state}
72
139
  end
73
140
  EOF
74
- eval s
75
- }
141
+ eval s
76
142
  end
77
143
 
78
- def self.private_boolean_state_accessor(*args)
79
- self.private_state_accessor(*args)
80
- args.each { |arg|
81
- s = <<EOF
144
+ # Generates private setters and getters for the specified boolean state
145
+ # @param [Symbol] state
146
+ # @!macro [attach] private_boolean_state_accessor
147
+ # @!method $1?
148
+ # @return the boolean evaluation of the *$1* state
149
+ # @private
150
+ # @!parse private_state_accessor $1
151
+ def self.private_boolean_state_accessor(state)
152
+ self.private_state_accessor(state)
153
+ s = <<EOF
82
154
  private
83
- def #{arg}?
84
- BOAST::#{arg}?
155
+ def #{state}?
156
+ BOAST::#{state}?
85
157
  end
86
158
  EOF
87
- eval s
88
- }
159
+ eval s
89
160
  end
90
161
 
91
162
  end