BOAST 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 FuncCall; end
3
4
  class FuncCall
4
5
  include PrivateStateAccessor
5
6
  include Arithmetic
@@ -52,6 +53,8 @@ module BOAST
52
53
  s += "#{func_name}(#{@args.join(", ")})"
53
54
  end
54
55
 
56
+ private :to_s_fortran, :to_s_c
57
+
55
58
  def pr
56
59
  s=""
57
60
  s += indent
@@ -62,4 +65,8 @@ module BOAST
62
65
  end
63
66
  end
64
67
 
68
+ module Functors
69
+ alias Call FuncCall
70
+ end
71
+
65
72
  end
@@ -1,34 +1,71 @@
1
1
  module BOAST
2
-
3
- module_function
4
- def functorize(klass)
5
- name = klass.name.split('::').last
6
- s = <<EOF
7
- def #{name}(*args,&block)
8
- #{name}::new(*args,&block)
2
+
3
+ module Functors
9
4
  end
10
5
 
11
- module_function :#{name}
12
- EOF
13
- eval s
6
+ module VarFunctors
14
7
  end
15
8
 
16
- def var_functorize(klass)
17
- name = klass.name.split('::').last
18
- s = <<EOF
19
- def #{name}(*args,&block)
20
- Variable::new(args[0],#{name},*args[1..-1], &block)
9
+ extend Functors
10
+
11
+ EXTENDED.push Functors
12
+
13
+ extend VarFunctors
14
+
15
+ EXTENDED.push VarFunctors
16
+
17
+
18
+ module Functors
19
+
20
+ module_function
21
+
22
+ # Creates a wrapper for klass new method
23
+ # @param [Class] klass class to turn into a functor.
24
+ # @private
25
+ # @!macro [attach] functorize
26
+ # @!method $1
27
+ # Creates a new $1 object, arguments are passed to the *new* method of $1. (see {$1#initialize}).
28
+ def functorize(klass)
29
+ name = klass.name.split('::').last
30
+ s = <<EOF
31
+ def #{name}(*args,&block)
32
+ #{name}::new(*args,&block)
33
+ end
34
+ EOF
35
+ class_eval s
36
+ end
37
+
21
38
  end
22
39
 
23
- module_function :#{name}
40
+ module VarFunctors
41
+
42
+ module_function
43
+
44
+ # Creates a functor to create a Variable of type klass
45
+ # @param [DataType] klass DataType to turn into a functor and add it to the VarFunctors module.
46
+ # @private
47
+ # @!macro [attach] var_functorize
48
+ # @!method $1(name, *args, &block)
49
+ # Creates a new Variable of type $1.
50
+ # @param [#to_s] name name of the Variable
51
+ # @param [Object] args parameters to use when creating a Variable
52
+ # @param [Block] block block of code will be forwarded
53
+ def var_functorize(klass)
54
+ name = klass.name.split('::').last
55
+ s = <<EOF
56
+ def #{name}(*args,&block)
57
+ Variable::new(args[0],#{name},*args[1..-1], &block)
58
+ end
24
59
  EOF
25
- eval s
60
+ class_eval s
61
+ end
62
+
26
63
  end
27
64
 
28
65
  module Functor
29
66
 
30
67
  def self.extended(mod)
31
- eval "#{mod.name.split('::')[-2]}::functorize(mod)"
68
+ BOAST::Functors::functorize(mod)
32
69
  end
33
70
 
34
71
  end
@@ -36,7 +73,7 @@ EOF
36
73
  module VarFunctor
37
74
 
38
75
  def self.extended(mod)
39
- eval "#{mod.name.split('::')[-2]}::var_functorize(mod)"
76
+ BOAST::VarFunctors::var_functorize(mod)
40
77
  end
41
78
 
42
79
  end
@@ -1,5 +1,6 @@
1
1
  module BOAST
2
2
 
3
+ # @!parse module Functors; functorize If; end
3
4
  class If < ControlStructure
4
5
 
5
6
  attr_reader :conditions
@@ -35,6 +36,8 @@ module BOAST
35
36
  :end => '"end if"' }
36
37
  end
37
38
 
39
+ private :get_c_strings, :get_fortran_strings
40
+
38
41
  alias get_cl_strings get_c_strings
39
42
  alias get_cuda_strings get_c_strings
40
43
 
@@ -58,6 +58,17 @@ module BOAST
58
58
  return to_s_c if [C, CL, CUDA].include?( lang )
59
59
  end
60
60
 
61
+ def pr
62
+ s=""
63
+ s += indent
64
+ s += to_s
65
+ s += ";" if [C, CL, CUDA].include?( lang )
66
+ output.puts s
67
+ return self
68
+ end
69
+
70
+ private
71
+
61
72
  def to_s_fortran
62
73
  s = ""
63
74
  s += "#{@source}(#{@indexes.join(", ")})"
@@ -155,15 +166,6 @@ module BOAST
155
166
  return s
156
167
  end
157
168
 
158
- def pr
159
- s=""
160
- s += indent
161
- s += to_s
162
- s += ";" if [C, CL, CUDA].include?( lang )
163
- output.puts s
164
- return self
165
- end
166
-
167
169
  end
168
170
 
169
171
  end
@@ -28,9 +28,11 @@ module BOAST
28
28
  class IntrinsicsError < Error
29
29
  end
30
30
 
31
+ # @private
31
32
  class InternalIntrinsicsError < Error
32
33
  end
33
34
 
35
+ # @private
34
36
  module Intrinsics
35
37
  extend PrivateStateAccessor
36
38
  INTRINSICS = Hash::new { |h, k| h[k] = Hash::new { |h2, k2| h2[k2] = {} } }
@@ -118,8 +118,7 @@ EOF
118
118
 
119
119
  end
120
120
 
121
- module_function
122
- def functorize(klass)
121
+ def self.functorize(klass)
123
122
  name = klass.name.split('::').last
124
123
  s = <<EOF
125
124
  def #{name}(*args,&block)
@@ -130,10 +129,14 @@ EOF
130
129
  EOF
131
130
  eval s
132
131
  end
133
-
132
+
134
133
  class OpenMPControlStructure < ControlStructure
135
134
  include OpenMP::Pragma
136
135
 
136
+ def self.inherited(child)
137
+ OpenMP.send(:functorize,child)
138
+ end
139
+
137
140
  def get_strings
138
141
  return { C => get_c_strings,
139
142
  FORTRAN => get_fortran_strings }
@@ -172,6 +175,10 @@ EOF
172
175
 
173
176
  end
174
177
 
178
+ # @!macro [attach] register_openmp_construct
179
+ # @!method $1(options = {}, &block)
180
+ # Creates an OpenMP construct that correspond to the "$2" C OpenMP construct.
181
+ # @param [Hash] options OpenMP clause and their values. See OpenMP documentation
175
182
  def self.register_openmp_construct( name, c_name, open_clauses, end_clauses = [], options = {} )
176
183
  fortran_name = c_name
177
184
  fortran_name = options[:fortran_name] if options[:fortran_name]
@@ -245,6 +252,10 @@ EOF
245
252
  eval s
246
253
  end
247
254
 
255
+ # @!macro [attach] register_openmp_compound_construct
256
+ # @!method $1$2(options={}, &block)
257
+ # Creates an OpenMP construct that correspond to the "$1#c_name $2#c_name" C OpenMP construct.
258
+ # @param [Hash] options OpenMP clause and their values. See OpenMP documentation
248
259
  def self.register_openmp_compound_construct( c1, c2, options = {} )
249
260
  register_openmp_construct( c1.name+c2.name, "#{c1.c_name} #{c2.c_name}",
250
261
  (c1.get_open_clauses + c2.get_open_clauses).uniq,
@@ -253,7 +264,13 @@ EOF
253
264
  :block => options[:block] )
254
265
  end
255
266
 
256
- register_openmp_construct( :Parallel, "parallel",
267
+ class << self
268
+ private :register_openmp_construct
269
+ private :register_openmp_compound_construct
270
+ private :functorize
271
+ end
272
+
273
+ register_openmp_construct( "Parallel", "parallel",
257
274
  [ :if,
258
275
  :num_threads,
259
276
  :default,
@@ -266,7 +283,7 @@ EOF
266
283
  [],
267
284
  :block => true )
268
285
 
269
- register_openmp_construct( :For, "for",
286
+ register_openmp_construct( "For", "for",
270
287
  [ :private,
271
288
  :firstprivate,
272
289
  :lastprivate,
@@ -277,7 +294,7 @@ EOF
277
294
  [ :nowait ],
278
295
  :fortran_name => "do" )
279
296
 
280
- register_openmp_construct( :Sections, "sections",
297
+ register_openmp_construct( "Sections", "sections",
281
298
  [ :private,
282
299
  :firstprivate,
283
300
  :lastprivate,
@@ -285,18 +302,18 @@ EOF
285
302
  [ :nowait ],
286
303
  :block => true )
287
304
 
288
- register_openmp_construct( :Section, "section", [], [],
289
- :block => true,
290
- :fortran_no_end => true )
305
+ register_openmp_construct( "Section", "section", [], [],
306
+ :block => true,
307
+ :fortran_no_end => true )
291
308
 
292
- register_openmp_construct( :Single, "single",
309
+ register_openmp_construct( "Single", "single",
293
310
  [ :private,
294
311
  :firstprivate ],
295
312
  [ :copyprivate,
296
313
  :nowait ],
297
314
  :block => true )
298
315
 
299
- register_openmp_construct( :Simd, "simd",
316
+ register_openmp_construct( "Simd", "simd",
300
317
  [ :safelen,
301
318
  :linear,
302
319
  :aligned,
@@ -305,7 +322,7 @@ EOF
305
322
  :reduction,
306
323
  :collapse ] )
307
324
 
308
- register_openmp_construct( :DeclareSimd, "declare simd",
325
+ register_openmp_construct( "DeclareSimd", "declare simd",
309
326
  [ :simdlen,
310
327
  :linear,
311
328
  :aligned,
@@ -315,21 +332,21 @@ EOF
315
332
 
316
333
  register_openmp_compound_construct( For, Simd )
317
334
 
318
- register_openmp_construct( :TargetData, "target data",
335
+ register_openmp_construct( "TargetData", "target data",
319
336
  [ :device,
320
337
  :map,
321
338
  :if ],
322
339
  [],
323
340
  :block => true )
324
341
 
325
- register_openmp_construct( :Target, "target",
342
+ register_openmp_construct( "Target", "target",
326
343
  [ :device,
327
344
  :map,
328
345
  :if ],
329
346
  [],
330
347
  :block => true )
331
348
 
332
- register_openmp_construct( :TargetUpdate, "target update",
349
+ register_openmp_construct( "TargetUpdate", "target update",
333
350
  [ :to,
334
351
  :from,
335
352
  :device,
@@ -337,14 +354,14 @@ EOF
337
354
  [],
338
355
  :fortran_no_end => true )
339
356
 
340
- register_openmp_construct( :DeclareTarget, "declare target",
357
+ register_openmp_construct( "DeclareTarget", "declare target",
341
358
  [],
342
359
  [],
343
360
  :c_end => true,
344
361
  :fortran_no_end => true,
345
362
  :fortran_block => true )
346
363
 
347
- register_openmp_construct( :Teams, "teams",
364
+ register_openmp_construct( "Teams", "teams",
348
365
  [ :num_teams,
349
366
  :thread_limit,
350
367
  :default,
@@ -355,7 +372,7 @@ EOF
355
372
  [],
356
373
  :block => true )
357
374
 
358
- register_openmp_construct( :Distribute, "distribute",
375
+ register_openmp_construct( "Distribute", "distribute",
359
376
  [ :private,
360
377
  :firstprivate,
361
378
  :collapse,
@@ -391,7 +408,7 @@ EOF
391
408
 
392
409
  register_openmp_compound_construct( Target, TeamsDistributeParallelForSimd )
393
410
 
394
- register_openmp_construct( :Task, "task",
411
+ register_openmp_construct( "Task", "task",
395
412
  [ :if,
396
413
  :final,
397
414
  :untied,
@@ -404,47 +421,47 @@ EOF
404
421
  [],
405
422
  :block => true )
406
423
 
407
- register_openmp_construct( :Taskyield, "taskyield", [], [], :fortran_no_end => true )
424
+ register_openmp_construct( "Taskyield", "taskyield", [], [], :fortran_no_end => true )
408
425
 
409
- register_openmp_construct( :Master, "master", [], [], :block => true )
426
+ register_openmp_construct( "Master", "master", [], [], :block => true )
410
427
 
411
- register_openmp_construct( :Critical, "critical", [:name], [:name], :block => true )
428
+ register_openmp_construct( "Critical", "critical", [:name], [:name], :block => true )
412
429
 
413
- register_openmp_construct( :Barrier, "barrier", [], [], :fortran_no_end => true )
430
+ register_openmp_construct( "Barrier", "barrier", [], [], :fortran_no_end => true )
414
431
 
415
- register_openmp_construct( :Taskwait, "taskwait", [], [], :fortran_no_end => true )
432
+ register_openmp_construct( "Taskwait", "taskwait", [], [], :fortran_no_end => true )
416
433
 
417
- register_openmp_construct( :Taskgroup, "taskgroup", [], [], :block => true )
434
+ register_openmp_construct( "Taskgroup", "taskgroup", [], [], :block => true )
418
435
 
419
- register_openmp_construct( :AtomicRead, "atomic read", [:seq_cst], [] )
436
+ register_openmp_construct( "AtomicRead", "atomic read", [:seq_cst], [] )
420
437
 
421
- register_openmp_construct( :AtomicWrite, "atomic write", [:seq_cst], [] )
438
+ register_openmp_construct( "AtomicWrite", "atomic write", [:seq_cst], [] )
422
439
 
423
- register_openmp_construct( :AtomicUpdate, "atomic update", [:seq_cst], [] )
440
+ register_openmp_construct( "AtomicUpdate", "atomic update", [:seq_cst], [] )
424
441
 
425
- register_openmp_construct( :AtomicCapture, "atomic capture", [:seq_cst], [], :block => true )
442
+ register_openmp_construct( "AtomicCapture", "atomic capture", [:seq_cst], [], :block => true )
426
443
 
427
- register_openmp_construct( :Flush, "flush", [:flush_list], [], :fortran_no_end => true )
444
+ register_openmp_construct( "Flush", "flush", [:flush_list], [], :fortran_no_end => true )
428
445
 
429
- register_openmp_construct( :Ordered, "ordered", [], [], :block => true )
446
+ register_openmp_construct( "Ordered", "ordered", [], [], :block => true )
430
447
 
431
- register_openmp_construct( :CancelParallel, "cancel parallel", [:if], [], :fortran_no_end => true )
448
+ register_openmp_construct( "CancelParallel", "cancel parallel", [:if], [], :fortran_no_end => true )
432
449
 
433
- register_openmp_construct( :CancelSections, "cancel sections", [:if], [], :fortran_no_end => true )
450
+ register_openmp_construct( "CancelSections", "cancel sections", [:if], [], :fortran_no_end => true )
434
451
 
435
- register_openmp_construct( :CancelFor, "cancel for", [:if], [], :fortran_no_end => true )
452
+ register_openmp_construct( "CancelFor", "cancel for", [:if], [], :fortran_no_end => true )
436
453
 
437
- register_openmp_construct( :CancelTaskgroup, "cancel taskgroup", [:if], [], :fortran_no_end => true )
454
+ register_openmp_construct( "CancelTaskgroup", "cancel taskgroup", [:if], [], :fortran_no_end => true )
438
455
 
439
- register_openmp_construct( :CancellationPointParallel, "cancellation point parallel", [], [], :fortran_no_end => true )
456
+ register_openmp_construct( "CancellationPointParallel", "cancellation point parallel", [], [], :fortran_no_end => true )
440
457
 
441
- register_openmp_construct( :CancellationPointSections, "cancellation point sections", [], [], :fortran_no_end => true )
458
+ register_openmp_construct( "CancellationPointSections", "cancellation point sections", [], [], :fortran_no_end => true )
442
459
 
443
- register_openmp_construct( :CancellationPointFor, "cancellation point for", [], [], :fortran_no_end => true )
460
+ register_openmp_construct( "CancellationPointFor", "cancellation point for", [], [], :fortran_no_end => true )
444
461
 
445
- register_openmp_construct( :CancellationPointTaskgroup, "cancellation point taskgroup", [], [], :fortran_no_end => true )
462
+ register_openmp_construct( "CancellationPointTaskgroup", "cancellation point taskgroup", [], [], :fortran_no_end => true )
446
463
 
447
- register_openmp_construct( :Threadprivate, "threadprivate", [:threadprivate_list], [], :fortran_no_end => true )
464
+ register_openmp_construct( "Threadprivate", "threadprivate", [:threadprivate_list], [], :fortran_no_end => true )
448
465
 
449
466
  end
450
467
 
@@ -304,6 +304,7 @@ module BOAST
304
304
 
305
305
  end
306
306
 
307
+ # @!parse module Functors; functorize Set; end
307
308
  class Set < Operator
308
309
  extend Functor
309
310
  include Intrinsics
@@ -375,6 +376,7 @@ module BOAST
375
376
 
376
377
  end
377
378
 
379
+ # @!parse module Functors; functorize Load; end
378
380
  class Load < Operator
379
381
  extend Functor
380
382
  include Intrinsics
@@ -439,6 +441,7 @@ module BOAST
439
441
 
440
442
  end
441
443
 
444
+ # @!parse module Functors; functorize MaskLoad; end
442
445
  class MaskLoad < Operator
443
446
  extend Functor
444
447
  include Intrinsics
@@ -502,6 +505,7 @@ module BOAST
502
505
 
503
506
  end
504
507
 
508
+ # @!parse module Functors; functorize Store; end
505
509
  class Store < Operator
506
510
  extend Functor
507
511
  include Intrinsics
@@ -555,6 +559,7 @@ module BOAST
555
559
 
556
560
  end
557
561
 
562
+ # @!parse module Functors; functorize MaskStore; end
558
563
  class MaskStore < Operator
559
564
  extend Functor
560
565
  include Intrinsics
@@ -615,6 +620,7 @@ module BOAST
615
620
 
616
621
  end
617
622
 
623
+ # @!parse module Functors; functorize FMA; end
618
624
  class FMA < Operator
619
625
  extend Functor
620
626
  include Intrinsics
@@ -685,6 +691,7 @@ module BOAST
685
691
 
686
692
  end
687
693
 
694
+ # @!parse module Functors; functorize FMS; end
688
695
  class FMS < Operator
689
696
  extend Functor
690
697
  include Intrinsics
@@ -756,6 +763,7 @@ module BOAST
756
763
 
757
764
  end
758
765
 
766
+ # @!parse module Functors; functorize Ternary; end
759
767
  class Ternary
760
768
  extend Functor
761
769
  include Arithmetic
@@ -772,23 +780,22 @@ module BOAST
772
780
  @operand3 = z
773
781
  end
774
782
 
775
- def op_to_var
776
- op1 = @operand1.respond_to?(:to_var) ? @operand1.to_var : @operand1
777
- op1 = @operand1 unless op1
778
- op2 = @operand2.respond_to?(:to_var) ? @operand2.to_var : @operand2
779
- op2 = @operand2 unless op2
780
- op3 = @operand3.respond_to?(:to_var) ? @operand3.to_var : @operand3
781
- op3 = @operand3 unless op3
782
- return [op1, op2, op3]
783
- end
784
-
785
- private :op_to_var
786
-
787
783
  def to_s
788
784
  return to_s_fortran if lang == FORTRAN
789
785
  return to_s_c if [C, CL, CUDA].include?( lang )
790
786
  end
791
787
 
788
+ def pr
789
+ s=""
790
+ s += indent
791
+ s += to_s
792
+ s += ";" if [C, CL, CUDA].include?( lang )
793
+ output.puts s
794
+ return self
795
+ end
796
+
797
+ private
798
+
792
799
  def to_s_fortran
793
800
  op1, op2, op3 = op_to_var
794
801
  "merge(#{op2}, #{op3}, #{op1})"
@@ -799,13 +806,14 @@ module BOAST
799
806
  "(#{op1} ? #{op2} : #{op3})"
800
807
  end
801
808
 
802
- def pr
803
- s=""
804
- s += indent
805
- s += to_s
806
- s += ";" if [C, CL, CUDA].include?( lang )
807
- output.puts s
808
- return self
809
+ def op_to_var
810
+ op1 = @operand1.respond_to?(:to_var) ? @operand1.to_var : @operand1
811
+ op1 = @operand1 unless op1
812
+ op2 = @operand2.respond_to?(:to_var) ? @operand2.to_var : @operand2
813
+ op2 = @operand2 unless op2
814
+ op3 = @operand3.respond_to?(:to_var) ? @operand3.to_var : @operand3
815
+ op3 = @operand3 unless op3
816
+ return [op1, op2, op3]
809
817
  end
810
818
 
811
819
  end