BOAST 0.1 → 0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70e302d3019847a191f670dd7c3b9988a2fc1e02
4
+ data.tar.gz: cacec85165ae25deb86319b6c35e18220f76e9c9
5
+ SHA512:
6
+ metadata.gz: 493beab807ea8b2d932f2b916faae3443f7b2193e894caf1865ae8d0463d8baaa639e10cd04129baae4dd637f2657e41987490982e281689d816e27b6a3ccd4a
7
+ data.tar.gz: 940fcbb439c4dcff8b3c4ef1dc9fc37f282407ad777b99a277c946e32be585e4f3009f16039b2380ace20b1979babec8bd566f599c7af94413f8d7cf56200de7
data/BOAST.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'BOAST'
3
- s.version = "0.1"
3
+ s.version = "0.2"
4
4
  s.author = "Brice Videau"
5
5
  s.email = "brice.videau@imag.fr"
6
6
  s.homepage = "https://forge.imag.fr/projects/boast/"
7
7
  s.summary = "BOAST is a computing kernel metaprogramming tool."
8
8
  s.description = "BOAST aims at providing a framework to metaprogram, benchmark and validate computing kernels"
9
- s.files = %w( BOAST.gemspec LICENSE lib/BOAST.rb lib/BOAST/Algorithm.rb lib/BOAST/CKernel.rb lib/BOAST/BOAST_OpenCL.rb )
9
+ s.files = %w( BOAST.gemspec LICENSE lib/BOAST.rb lib/BOAST/Algorithm.rb lib/BOAST/CKernel.rb lib/BOAST/BOAST_OpenCL.rb lib/BOAST/Transitions.rb)
10
10
  s.has_rdoc = true
11
11
  s.license = 'BSD'
12
12
  s.required_ruby_version = '>= 1.9.3'
@@ -19,6 +19,8 @@ end
19
19
 
20
20
  module BOAST
21
21
 
22
+ extend TypeTransition
23
+
22
24
  FORTRAN = 1
23
25
  C = 2
24
26
  CL = 3
@@ -36,7 +38,6 @@ module BOAST
36
38
 
37
39
  @@env = Hash.new{|h, k| h[k] = []}
38
40
 
39
-
40
41
  def BOAST::push_env(vars = {})
41
42
  vars.each { |key,value|
42
43
  var = nil
@@ -267,24 +268,57 @@ module BOAST
267
268
  def -@
268
269
  return Expression::new("-",nil,self)
269
270
  end
270
-
271
+
272
+ def to_var
273
+ op1 = nil
274
+ op1 = @operand1.to_var if @operand1 and @operand1.respond_to?(:to_var)
275
+ op2 = nil
276
+ op2 = @operand2.to_var if @operand2 and @operand2.respond_to?(:to_var)
277
+ res_exp = Expression::new(@operator, op1.nil? ? @operand1 : op1, op2.nil? ? @operand2 : op2)
278
+ if op1 and op2 then
279
+ r_t, oper = BOAST::transition(op1, op2, @operator)
280
+ return r_t.copy("#{res_exp}", :const => nil, :constant => nil)
281
+ elsif op1
282
+ return op1.copy("#{res_exp}", :const => nil, :constant => nil)
283
+ elsif op2
284
+ return op2.copy("#{res_exp}", :const => nil, :constant => nil)
285
+ else
286
+ STDERR.puts "#{@operand1} #{@operand2}"
287
+ raise "Expression on no operand!"
288
+ end
289
+ end
290
+
271
291
  def to_str
292
+ op1 = nil
293
+ op1 = @operand1.to_var if @operand1 and @operand1.respond_to?(:to_var)
294
+ op2 = nil
295
+ op2 = @operand2.to_var if @operand2 and @operand2.respond_to?(:to_var)
296
+ if op1 and op2 then
297
+ r_t, oper = BOAST::transition(op1, op2, @operator)
298
+ else
299
+ oper = @operator
300
+ end
301
+
302
+ op1 = @operand1 if not op1
303
+ op2 = @operand2 if not op2
304
+
272
305
  s = ""
273
- if @operand1 then
274
- s += "(" if (@operator == "*" or @operator == "/")
275
- s += @operand1.to_s
276
- s += ")" if (@operator == "*" or @operator == "/")
306
+ if op1 then
307
+ s += "(" if (oper == "*" or oper == "/")
308
+ s += op1.to_s
309
+ s += ")" if (oper == "*" or oper == "/")
277
310
  end
278
- s += " " unless @operator.to_s == "++" or @operator.to_s == "."
279
- s += @operator.to_s
280
- s += " " unless @operator.to_s == "." or @operator.to_s == "&" or ( @operator.to_s == "*" and @operand1.nil? )
281
- if @operand2 then
282
- s += "(" if (@operator == "*" or @operator == "/" or @operator == "-")
283
- s += @operand2.to_s
284
- s += ")" if (@operator == "*" or @operator == "/" or @operator == "-")
311
+ s += " " unless oper == "++" or oper == "."
312
+ s += oper
313
+ s += " " unless oper == "." or oper == "&" or ( oper == "*" and op1.nil? )
314
+ if op2 then
315
+ s += "(" if (oper == "*" or oper == "/" or oper == "-")
316
+ s += op2.to_s
317
+ s += ")" if (oper == "*" or oper == "/" or oper == "-")
285
318
  end
286
319
  return s
287
320
  end
321
+
288
322
  def print(final=true)
289
323
  s=""
290
324
  s += " "*BOAST::get_indent_level if final
@@ -320,6 +354,11 @@ module BOAST
320
354
  @source = source
321
355
  @indexes = indexes
322
356
  end
357
+
358
+ def to_var
359
+ return @source.copy("#{self}", :const => nil, :constant => nil, :dim => nil, :dimension => nil)
360
+ end
361
+
323
362
  def to_s
324
363
  self.to_str
325
364
  end
@@ -532,7 +571,7 @@ module BOAST
532
571
  attr_reader :local
533
572
  attr_reader :texture
534
573
  attr_reader :sampler
535
- attr_reader :replace_constant
574
+ attr_accessor :replace_constant
536
575
  attr_accessor :force_replace_constant
537
576
 
538
577
  def initialize(name,type,hash={})
@@ -558,8 +597,12 @@ module BOAST
558
597
  @hash = hash
559
598
  end
560
599
 
561
- def copy(name=@name)
562
- return Variable::new(name, @type.class, @hash)
600
+ def copy(name=@name,options={})
601
+ hash = @hash.clone
602
+ options.each { |k,v|
603
+ hash[k] = v
604
+ }
605
+ return Variable::new(name, @type.class, hash)
563
606
  end
564
607
 
565
608
  def to_s
@@ -575,6 +618,10 @@ module BOAST
575
618
  return @name.to_str
576
619
  end
577
620
 
621
+ def to_var
622
+ return self
623
+ end
624
+
578
625
  def ===(x)
579
626
  return Expression::new("=",self,x)
580
627
  end
@@ -1055,7 +1102,7 @@ module BOAST
1055
1102
  end
1056
1103
  end
1057
1104
  def decl
1058
- return "integer(kind=#{BOAST::get_default_int_signed})" if BOAST::get_lang == FORTRAN
1105
+ return "integer(kind=#{BOAST::get_default_int_size})" if BOAST::get_lang == FORTRAN
1059
1106
  if not @signed then
1060
1107
  return "size_t" if [C, CL, CUDA].include?( BOAST::get_lang )
1061
1108
  else
@@ -1213,6 +1260,8 @@ module BOAST
1213
1260
  end
1214
1261
 
1215
1262
  class FuncCall
1263
+ @return_type
1264
+ @options
1216
1265
  def self.parens(*args,&block)
1217
1266
  return self::new(*args,&block)
1218
1267
  end
@@ -1223,7 +1272,24 @@ module BOAST
1223
1272
 
1224
1273
  def initialize(func_name, *args)
1225
1274
  @func_name = func_name
1226
- @args = args
1275
+ if args.last.kind_of?(Hash) then
1276
+ @options = args.last
1277
+ @args = args[0..-2]
1278
+ else
1279
+ @args = args
1280
+ end
1281
+ @return_type = @options[:returns] if @options
1282
+ end
1283
+
1284
+ def to_var
1285
+ if @return_type then
1286
+ if @return_type.kind_of?(Variable)
1287
+ return @return_type.copy("#{self}")
1288
+ else
1289
+ return Variable::new("#{self}", @return_type)
1290
+ end
1291
+ end
1292
+ return nil
1227
1293
  end
1228
1294
 
1229
1295
  def to_s
@@ -1755,5 +1821,32 @@ module BOAST
1755
1821
  Var = Variable
1756
1822
  Dim = Dimension
1757
1823
  Call = FuncCall
1824
+
1825
+ set_transition(Int, Int, :default, Int)
1826
+ set_transition(Real, Int, :default, Real)
1827
+ set_transition(Int, Real, :default, Real)
1828
+ set_transition(Real, Real, :default, Real)
1829
+ set_transition(Sizet, Sizet, :default, Sizet)
1830
+ set_transition(Sizet, Int, :default, Sizet)
1831
+ set_transition(Int, Sizet, :default, Sizet)
1832
+
1758
1833
  end
1834
+
1759
1835
  ConvolutionGenerator = BOAST
1836
+
1837
+ class Integer
1838
+ def to_var
1839
+ if self < 0 then
1840
+ return BOAST::Variable::new("#{self}", BOAST::Int, :signed => true, :constant => self )
1841
+ else
1842
+ return BOAST::Variable::new("#{self}", BOAST::Int, :signed => false, :constant => self )
1843
+ end
1844
+ end
1845
+ end
1846
+
1847
+ class Float
1848
+ def to_var
1849
+ return BOAST::Variable::new("#{self}", BOAST::Real, :constant => self )
1850
+ end
1851
+ end
1852
+
@@ -1,6 +1,11 @@
1
1
  module BOAST
2
2
  @@ocl_cuda_dim_assoc = { 0 => "x", 1 => "y", 2 => "z" }
3
3
 
4
+ @@cuda_threadIdx = CStruct("threadIdx",:type_name => "cuda_trheadIdx", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
5
+ @@cuda_blockIdx = CStruct("blockIdx",:type_name => "cuda_blockIdx", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
6
+ @@cuda_blockDim = CStruct("blockDim",:type_name => "cuda_blockDim", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
7
+ @@cuda_gridDim = CStruct("gridDim",:type_name => "cuda_gridDim", :members => [Int("x", :signed => false),Int("y", :signed => false),Int("z", :signed => false)])
8
+
4
9
  def BOAST::barrier(*locality)
5
10
  if @@lang == CL then
6
11
  loc=""
@@ -23,7 +28,7 @@ module BOAST
23
28
 
24
29
  def BOAST::get_work_dim
25
30
  if @@lang == CL then
26
- return FuncCall::new("get_work_dim")
31
+ return FuncCall::new("get_work_dim", :returns => Int("wd", :signed => false))
27
32
  else
28
33
  raise "Unsupported language!"
29
34
  end
@@ -31,11 +36,11 @@ module BOAST
31
36
 
32
37
  def BOAST::get_global_size(dim)
33
38
  if @@lang == CL then
34
- return FuncCall::new("get_global_size",dim)
39
+ return FuncCall::new("get_global_size", dim, :returns => Sizet)
35
40
  elsif @@lang == CUDA then
36
41
  d = @@ocl_cuda_dim_assoc[dim]
37
42
  raise "Unsupported dimension!" if not d
38
- return Expression::new(".", "gridDim", d)*Expression::new(".", "blockDim", d)
43
+ return eval "@@cuda_gridDim.#{d}*@@cuda_blockDim.#{d}"
39
44
  else
40
45
  raise "Unsupported language!"
41
46
  end
@@ -43,11 +48,11 @@ module BOAST
43
48
 
44
49
  def BOAST::get_global_id(dim)
45
50
  if @@lang == CL then
46
- return FuncCall::new("get_global_id",dim)
51
+ return FuncCall::new("get_global_id",dim, :returns => Sizet)
47
52
  elsif @@lang == CUDA then
48
53
  d = @@ocl_cuda_dim_assoc[dim]
49
54
  raise "Unsupported dimension!" if not d
50
- return Expression::new(".", "threadIdx", d)+Expression::new(".", "blockIdx", d)*Expression::new(".", "blockDim", d)
55
+ return eval "@@cuda_threadIdx.#{d}+@@cuda_blockIdx.#{d}*@@cuda_blockDim.#{d}"
51
56
  else
52
57
  raise "Unsupported language!"
53
58
  end
@@ -55,11 +60,11 @@ module BOAST
55
60
 
56
61
  def BOAST::get_local_size(dim)
57
62
  if @@lang == CL then
58
- return FuncCall::new("get_local_size",dim)
63
+ return FuncCall::new("get_local_size",dim, :returns => Sizet)
59
64
  elsif @@lang == CUDA then
60
65
  d = @@ocl_cuda_dim_assoc[dim]
61
66
  raise "Unsupported dimension!" if not d
62
- return Expression::new(".", "blockDim", d)
67
+ return eval "@@cuda_blockDim.#{d}"
63
68
  else
64
69
  raise "Unsupported language!"
65
70
  end
@@ -67,11 +72,11 @@ module BOAST
67
72
 
68
73
  def BOAST::get_local_id(dim)
69
74
  if @@lang == CL then
70
- return FuncCall::new("get_local_id",dim)
75
+ return FuncCall::new("get_local_id",dim, :returns => Sizet)
71
76
  elsif @@lang == CUDA then
72
77
  d = @@ocl_cuda_dim_assoc[dim]
73
78
  raise "Unsupported dimension!" if not d
74
- return Expression::new(".", "threadIdx", d)
79
+ return eval "@@cuda_threadIdx.#{d}"
75
80
  else
76
81
  raise "Unsupported language!"
77
82
  end
@@ -79,11 +84,11 @@ module BOAST
79
84
 
80
85
  def BOAST::get_num_groups(dim)
81
86
  if @@lang == CL then
82
- return FuncCall::new("get_num_groups",dim)
87
+ return FuncCall::new("get_num_groups",dim, :returns => Sizet)
83
88
  elsif @@lang == CUDA then
84
89
  d = @@ocl_cuda_dim_assoc[dim]
85
90
  raise "Unsupported dimension!" if not d
86
- return Expression::new(".", "gridDim", d)
91
+ return eval "@@cuda_gridDim.#{d}"
87
92
  else
88
93
  raise "Unsupported language!"
89
94
  end
@@ -91,11 +96,11 @@ module BOAST
91
96
 
92
97
  def BOAST::get_group_id(dim)
93
98
  if @@lang == CL then
94
- return FuncCall::new("get_group_id",dim)
99
+ return FuncCall::new("get_group_id",dim, :returns => Sizet)
95
100
  elsif @@lang == CUDA then
96
101
  d = @@ocl_cuda_dim_assoc[dim]
97
102
  raise "Unsupported dimension!" if not d
98
- return Expression::new(".", "blockIdx", d)
103
+ return eval "@@cuda_blockIdx.#{d}"
99
104
  else
100
105
  raise "Unsupported language!"
101
106
  end
data/lib/BOAST/CKernel.rb CHANGED
@@ -88,6 +88,7 @@ module BOAST
88
88
 
89
89
  includes = "-I#{RbConfig::CONFIG["archdir"]}"
90
90
  includes += " -I#{RbConfig::CONFIG["rubyhdrdir"]} -I#{RbConfig::CONFIG["rubyhdrdir"]}/#{RbConfig::CONFIG["arch"]}"
91
+ includes += " -I#{RbConfig::CONFIG["rubyarchhdrdir"]}" if RbConfig::CONFIG["rubyarchhdrdir"]
91
92
  ld_flags += " -L#{RbConfig::CONFIG["libdir"]} #{RbConfig::CONFIG["LIBRUBYARG"]} -lrt"
92
93
  ld_flags += " -lcudart" if @lang == BOAST::CUDA
93
94
  narray_path = nil
@@ -0,0 +1,47 @@
1
+ module BOAST
2
+ module TypeTransition
3
+ @@transitions = Hash::new { |hash, key| hash[key] = Hash::new{ |has, ke| has[ke] = Hash::new } }
4
+ def get_transition(type1, type2, operator)
5
+ #STDERR.puts @@transitions.inspect
6
+ match_type1 = @@transitions.keys.select { |e1| true if type1 <= e1 }
7
+ raise "Unknown type!" if match_type1.length == 0
8
+ match_type1.sort!
9
+ #STDERR.puts match_type1.inspect
10
+ match_type1.each { |t1|
11
+ match_type2 = @@transitions[t1].keys.select{ |e2| true if type2 <= e2 }
12
+ match_type2.sort!
13
+ #STDERR.puts match_type2.inspect
14
+ match_type2.each { |t2|
15
+ #STDERR.puts @@transitions[t1][t2].inspect
16
+ return [@@transitions[t1][t2][operator], operator] if @@transitions[t1][t2][operator]
17
+ return [@@transitions[t1][t2][:default], operator] if @@transitions[t1][t2][:default]
18
+ }
19
+ }
20
+ raise "Unresolvable transition!"
21
+ end
22
+
23
+ def set_transition(type1, type2, operator, return_type)
24
+ @@transitions[type1][type2][operator] = return_type
25
+ end
26
+
27
+ def transition(var1, var2, operator)
28
+ signed = false
29
+ size = nil
30
+ return_type, operator = get_transition(var1.type.class, var2.type.class, operator)
31
+ #STDERR.puts "#{return_type} : #{var1.type.class} #{operator} #{var2.type.class}"
32
+ if var1.type.class <= return_type and var2.type.class <= return_type then
33
+ signed = signed or var1.type.signed if var1.type.respond_to?(:signed)
34
+ signed = signed or var2.type.signed if var2.type.respond_to?(:signed)
35
+ if var1.type.respond_to?(:size) and var2.type.respond_to?(:size) then
36
+ size = [var1.type.size, var2.type.size].max
37
+ end
38
+ [BOAST::Variable::new("dummy", return_type, :size => size, :signed => signed), operator]
39
+ elsif var1.type.class <= return_type then
40
+ return [var1, operator]
41
+ elsif var2.type.class <= return_type then
42
+ return [var2, operator]
43
+ end
44
+ end
45
+ end
46
+
47
+ end
data/lib/BOAST.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'BOAST/Transitions.rb'
1
2
  require 'BOAST/Algorithm.rb'
2
3
  require 'BOAST/CKernel.rb'
3
4
  require 'BOAST/BOAST_OpenCL.rb'
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BOAST
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
5
- prerelease:
4
+ version: '0.2'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brice Videau
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-25 00:00:00.000000000 Z
11
+ date: 2014-04-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: narray
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.6.0.8
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.6.0.8
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: opencl_ruby_ffi
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0.4'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0.4'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: systemu
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 2.2.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 2.2.0
62
55
  description: BOAST aims at providing a framework to metaprogram, benchmark and validate
@@ -72,29 +65,29 @@ files:
72
65
  - lib/BOAST/Algorithm.rb
73
66
  - lib/BOAST/CKernel.rb
74
67
  - lib/BOAST/BOAST_OpenCL.rb
68
+ - lib/BOAST/Transitions.rb
75
69
  homepage: https://forge.imag.fr/projects/boast/
76
70
  licenses:
77
71
  - BSD
72
+ metadata: {}
78
73
  post_install_message:
79
74
  rdoc_options: []
80
75
  require_paths:
81
76
  - lib
82
77
  required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
78
  requirements:
85
- - - ! '>='
79
+ - - '>='
86
80
  - !ruby/object:Gem::Version
87
81
  version: 1.9.3
88
82
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
83
  requirements:
91
- - - ! '>='
84
+ - - '>='
92
85
  - !ruby/object:Gem::Version
93
86
  version: '0'
94
87
  requirements: []
95
88
  rubyforge_project:
96
- rubygems_version: 1.8.23
89
+ rubygems_version: 2.0.14
97
90
  signing_key:
98
- specification_version: 3
91
+ specification_version: 4
99
92
  summary: BOAST is a computing kernel metaprogramming tool.
100
93
  test_files: []