BOAST 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BOAST.gemspec +3 -3
- data/lib/BOAST/Language/Algorithm.rb +0 -90
- data/lib/BOAST/Language/Config.rb +141 -0
- data/lib/BOAST/Language/Inspectable.rb +0 -3
- data/lib/BOAST/Language/Intrinsics.rb +0 -3
- data/lib/BOAST/Language/State.rb +2 -1
- data/lib/BOAST/Runtime/CKernel.rb +1 -1
- data/lib/BOAST/Runtime/CompiledRuntime.rb +15 -0
- data/lib/BOAST/Runtime/Compilers.rb +1 -1
- data/lib/BOAST/Runtime/Config.rb +34 -8
- data/lib/BOAST/Runtime/FFIRuntime.rb +54 -58
- data/lib/BOAST/Runtime/OpenCLRuntime.rb +38 -42
- data/lib/BOAST/Runtime/OpenCLTypes.rb +24 -0
- data/lib/BOAST.rb +1 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fab0f4b52a0cd282c1abfc5778a690c5c90baae
|
4
|
+
data.tar.gz: 7e8adb0b43d8913a825a2349a8806af4097dd494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc23c211872b5bd42ae68cd18be4dacdcdc8a235c14bd5c40e80359bbff25a8c0433bdc52cf9d4b5a605ad0342f025384cf2c32cb94d3ed9241d4b058932d70
|
7
|
+
data.tar.gz: 29db1a68750851b3ce5a1f4e1b8e8495a8f553d0b979628ab132cf7cc3c4e96bc8672ffed74b7a938bead7e0e6a5c212b89041f73be8b7647d68c188a603452c
|
data/BOAST.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'BOAST'
|
3
|
-
s.version = "1.2.
|
3
|
+
s.version = "1.2.2"
|
4
4
|
s.author = "Brice Videau"
|
5
5
|
s.email = "brice.videau@imag.fr"
|
6
6
|
s.homepage = "https://github.com/Nanosim-LIG/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
9
|
s.files = Dir['BOAST.gemspec', 'LICENSE', 'README.md', 'lib/**/*']
|
10
|
-
s.has_rdoc =
|
11
|
-
s.license = 'BSD'
|
10
|
+
s.has_rdoc = false
|
11
|
+
s.license = 'BSD-2-Clause'
|
12
12
|
s.required_ruby_version = '>= 1.9.3'
|
13
13
|
s.add_dependency 'narray', '~> 0.6.0', '>=0.6.0.8'
|
14
14
|
s.add_dependency 'narray_ffi', '~> 1.2', '>=1.2.0'
|
@@ -2,36 +2,8 @@ module BOAST
|
|
2
2
|
|
3
3
|
extend TypeTransition
|
4
4
|
|
5
|
-
FORTRAN = 1
|
6
|
-
C = 2
|
7
|
-
CL = 3
|
8
|
-
CUDA = 4
|
9
|
-
#X86 = 1
|
10
|
-
#ARM = 2
|
11
|
-
MPPA = 3
|
12
|
-
|
13
5
|
module PrivateStateAccessor
|
14
6
|
|
15
|
-
private_state_accessor :output, :lang, :architecture, :model, :address_size
|
16
|
-
private_state_accessor :default_int_size, :default_real_size
|
17
|
-
private_state_accessor :default_align
|
18
|
-
private_state_accessor :array_start
|
19
|
-
private_state_accessor :indent_level, :indent_increment
|
20
|
-
private_state_accessor :annotate_list
|
21
|
-
private_state_accessor :annotate_indepth_list
|
22
|
-
private_state_accessor :annotate_level
|
23
|
-
private_state_accessor :optimizer_log_file
|
24
|
-
|
25
|
-
private_boolean_state_accessor :replace_constants
|
26
|
-
private_boolean_state_accessor :default_int_signed
|
27
|
-
private_boolean_state_accessor :chain_code
|
28
|
-
private_boolean_state_accessor :debug
|
29
|
-
private_boolean_state_accessor :use_vla
|
30
|
-
private_boolean_state_accessor :decl_module
|
31
|
-
private_boolean_state_accessor :annotate
|
32
|
-
private_boolean_state_accessor :optimizer_log
|
33
|
-
private_boolean_state_accessor :disable_openmp
|
34
|
-
|
35
7
|
private
|
36
8
|
def push_env(*args)
|
37
9
|
BOAST::push_env(*args)
|
@@ -67,69 +39,8 @@ module BOAST
|
|
67
39
|
|
68
40
|
end
|
69
41
|
|
70
|
-
state_accessor :output, :lang, :architecture, :model, :address_size
|
71
|
-
state_accessor :default_int_size, :default_real_size
|
72
|
-
state_accessor :default_align
|
73
|
-
state_accessor :array_start
|
74
|
-
state_accessor :indent_level, :indent_increment
|
75
|
-
state_accessor :annotate_list
|
76
|
-
state_accessor :annotate_indepth_list
|
77
|
-
state_accessor :annotate_level
|
78
|
-
state_accessor :optimizer_log_file
|
79
|
-
|
80
|
-
boolean_state_accessor :replace_constants
|
81
|
-
boolean_state_accessor :default_int_signed
|
82
|
-
boolean_state_accessor :chain_code
|
83
|
-
boolean_state_accessor :debug
|
84
|
-
boolean_state_accessor :use_vla
|
85
|
-
boolean_state_accessor :decl_module
|
86
|
-
boolean_state_accessor :annotate
|
87
|
-
boolean_state_accessor :optimizer_log
|
88
|
-
boolean_state_accessor :disable_openmp
|
89
|
-
|
90
|
-
default_state_getter :address_size, OS.bits/8
|
91
|
-
default_state_getter :lang, FORTRAN, '"const_get(#{envs})"', :BOAST_LANG
|
92
|
-
default_state_getter :model, "native"
|
93
|
-
default_state_getter :debug, false
|
94
|
-
default_state_getter :use_vla, false
|
95
|
-
default_state_getter :replace_constants, true
|
96
|
-
default_state_getter :default_int_signed, true
|
97
|
-
default_state_getter :default_int_size, 4
|
98
|
-
default_state_getter :default_real_size, 8
|
99
|
-
default_state_getter :default_align, 1
|
100
|
-
default_state_getter :indent_level, 0
|
101
|
-
default_state_getter :indent_increment, 2
|
102
|
-
default_state_getter :array_start, 1
|
103
|
-
default_state_getter :annotate, false
|
104
|
-
default_state_getter :annotate_list, ["For"], '"#{envs}.split(\",\").collect { |arg| YAML::load(arg) }"'
|
105
|
-
default_state_getter :annotate_indepth_list, ["For"], '"#{envs}.split(\",\").collect { |arg| YAML::load(arg) }"'
|
106
|
-
default_state_getter :annotate_level, 0
|
107
|
-
default_state_getter :optimizer_log, false
|
108
|
-
default_state_getter :optimizer_log_file, nil
|
109
|
-
default_state_getter :disable_openmp, false
|
110
|
-
|
111
|
-
alias use_vla_old? use_vla?
|
112
|
-
class << self
|
113
|
-
alias use_vla_old? use_vla?
|
114
|
-
end
|
115
|
-
|
116
|
-
def use_vla?
|
117
|
-
return false if [CL,CUDA].include?(lang)
|
118
|
-
return use_vla_old?
|
119
|
-
end
|
120
|
-
|
121
|
-
module_function :use_vla?
|
122
|
-
|
123
42
|
module_function
|
124
43
|
|
125
|
-
def get_default_architecture
|
126
|
-
architecture = const_get(ENV["ARCHITECTURE"]) if ENV["ARCHITECTURE"]
|
127
|
-
architecture = const_get(ENV["ARCH"]) if not architecture and ENV["ARCH"]
|
128
|
-
return architecture if architecture
|
129
|
-
return ARM if YAML::load( OS.report )["host_cpu"].match("arm")
|
130
|
-
return X86
|
131
|
-
end
|
132
|
-
|
133
44
|
def get_architecture_name
|
134
45
|
case architecture
|
135
46
|
when X86
|
@@ -160,7 +71,6 @@ module BOAST
|
|
160
71
|
|
161
72
|
@@output = STDOUT
|
162
73
|
@@chain_code = false
|
163
|
-
@@architecture = get_default_architecture
|
164
74
|
@@decl_module = false
|
165
75
|
@@annotate_numbers = Hash::new { |h,k| h[k] = 0 }
|
166
76
|
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'os'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module BOAST
|
5
|
+
FORTRAN = 1
|
6
|
+
C = 2
|
7
|
+
CL = 3
|
8
|
+
CUDA = 4
|
9
|
+
X86 = 1
|
10
|
+
ARM = 2
|
11
|
+
MPPA = 3
|
12
|
+
|
13
|
+
@@boast_config = {
|
14
|
+
:fortran_line_length => 72
|
15
|
+
}
|
16
|
+
|
17
|
+
def assert_boast_config_dir
|
18
|
+
home_config_dir = ENV["XDG_CONFIG_HOME"]
|
19
|
+
home_config_dir = "#{Dir.home}/.config" if not home_config_dir
|
20
|
+
Dir.mkdir( home_config_dir ) if not File::exist?( home_config_dir )
|
21
|
+
return nil if not File::directory?(home_config_dir)
|
22
|
+
boast_config_dir = "#{home_config_dir}/BOAST"
|
23
|
+
Dir.mkdir( boast_config_dir ) if not File::exist?( boast_config_dir )
|
24
|
+
return nil if not File::directory?(boast_config_dir)
|
25
|
+
return boast_config_dir
|
26
|
+
end
|
27
|
+
|
28
|
+
module_function :assert_boast_config_dir
|
29
|
+
|
30
|
+
def read_boast_config
|
31
|
+
boast_config_dir = assert_boast_config_dir
|
32
|
+
return unless boast_config_dir
|
33
|
+
boast_config_file = "#{boast_config_dir}/config"
|
34
|
+
if File::exist?( boast_config_file ) then
|
35
|
+
File::open( boast_config_file, "r" ) { |f|
|
36
|
+
@@boast_config.update( YAML::load( f.read ) )
|
37
|
+
}
|
38
|
+
else
|
39
|
+
File::open( boast_config_file, "w" ) { |f|
|
40
|
+
f.write YAML::dump( @@boast_config )
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module_function :read_boast_config
|
46
|
+
|
47
|
+
read_boast_config
|
48
|
+
|
49
|
+
module PrivateStateAccessor
|
50
|
+
|
51
|
+
private_state_accessor :output, :lang, :architecture, :model, :address_size
|
52
|
+
private_state_accessor :default_int_size, :default_real_size
|
53
|
+
private_state_accessor :default_align
|
54
|
+
private_state_accessor :array_start
|
55
|
+
private_state_accessor :indent_level, :indent_increment
|
56
|
+
private_state_accessor :annotate_list
|
57
|
+
private_state_accessor :annotate_indepth_list
|
58
|
+
private_state_accessor :annotate_level
|
59
|
+
private_state_accessor :optimizer_log_file
|
60
|
+
|
61
|
+
private_boolean_state_accessor :replace_constants
|
62
|
+
private_boolean_state_accessor :default_int_signed
|
63
|
+
private_boolean_state_accessor :chain_code
|
64
|
+
private_boolean_state_accessor :debug
|
65
|
+
private_boolean_state_accessor :use_vla
|
66
|
+
private_boolean_state_accessor :decl_module
|
67
|
+
private_boolean_state_accessor :annotate
|
68
|
+
private_boolean_state_accessor :optimizer_log
|
69
|
+
private_boolean_state_accessor :disable_openmp
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
state_accessor :output, :lang, :architecture, :model, :address_size
|
74
|
+
state_accessor :default_int_size, :default_real_size
|
75
|
+
state_accessor :default_align
|
76
|
+
state_accessor :array_start
|
77
|
+
state_accessor :indent_level, :indent_increment
|
78
|
+
state_accessor :annotate_list
|
79
|
+
state_accessor :annotate_indepth_list
|
80
|
+
state_accessor :annotate_level
|
81
|
+
state_accessor :optimizer_log_file
|
82
|
+
|
83
|
+
boolean_state_accessor :replace_constants
|
84
|
+
boolean_state_accessor :default_int_signed
|
85
|
+
boolean_state_accessor :chain_code
|
86
|
+
boolean_state_accessor :debug
|
87
|
+
boolean_state_accessor :use_vla
|
88
|
+
boolean_state_accessor :decl_module
|
89
|
+
boolean_state_accessor :annotate
|
90
|
+
boolean_state_accessor :optimizer_log
|
91
|
+
boolean_state_accessor :disable_openmp
|
92
|
+
boolean_state_accessor :boast_inspect
|
93
|
+
|
94
|
+
|
95
|
+
default_state_getter :address_size, OS.bits/8
|
96
|
+
default_state_getter :lang, FORTRAN, '"const_get(#{envs})"', :BOAST_LANG
|
97
|
+
default_state_getter :model, "native"
|
98
|
+
default_state_getter :debug, false
|
99
|
+
default_state_getter :use_vla, false
|
100
|
+
default_state_getter :replace_constants, true
|
101
|
+
default_state_getter :default_int_signed, true
|
102
|
+
default_state_getter :default_int_size, 4
|
103
|
+
default_state_getter :default_real_size, 8
|
104
|
+
default_state_getter :default_align, 1
|
105
|
+
default_state_getter :indent_level, 0
|
106
|
+
default_state_getter :indent_increment, 2
|
107
|
+
default_state_getter :array_start, 1
|
108
|
+
default_state_getter :annotate, false
|
109
|
+
default_state_getter :annotate_list, ["For"], '"#{envs}.split(\",\").collect { |arg| YAML::load(arg) }"'
|
110
|
+
default_state_getter :annotate_indepth_list, ["For"], '"#{envs}.split(\",\").collect { |arg| YAML::load(arg) }"'
|
111
|
+
default_state_getter :annotate_level, 0
|
112
|
+
default_state_getter :optimizer_log, false
|
113
|
+
default_state_getter :optimizer_log_file, nil
|
114
|
+
default_state_getter :disable_openmp, false
|
115
|
+
default_state_getter :boast_inspect, false, nil, :INSPECT
|
116
|
+
|
117
|
+
alias use_vla_old? use_vla?
|
118
|
+
class << self
|
119
|
+
alias use_vla_old? use_vla?
|
120
|
+
end
|
121
|
+
|
122
|
+
def use_vla?
|
123
|
+
return false if [CL,CUDA].include?(lang)
|
124
|
+
return use_vla_old?
|
125
|
+
end
|
126
|
+
|
127
|
+
module_function :use_vla?
|
128
|
+
|
129
|
+
def get_default_architecture
|
130
|
+
architecture = const_get(ENV["ARCHITECTURE"]) if ENV["ARCHITECTURE"]
|
131
|
+
architecture = const_get(ENV["ARCH"]) if not architecture and ENV["ARCH"]
|
132
|
+
return architecture if architecture
|
133
|
+
return ARM if YAML::load( OS.report )["host_cpu"].match("arm")
|
134
|
+
return X86
|
135
|
+
end
|
136
|
+
|
137
|
+
module_function :get_default_architecture
|
138
|
+
|
139
|
+
@@architecture = get_default_architecture
|
140
|
+
|
141
|
+
end
|
data/lib/BOAST/Language/State.rb
CHANGED
@@ -41,7 +41,8 @@ EOF
|
|
41
41
|
envs = "ENV['#{env}']"
|
42
42
|
s = <<EOF
|
43
43
|
def get_default_#{arg}
|
44
|
-
#{arg} = #{
|
44
|
+
#{arg} = @@boast_config[#{arg.inspect}]
|
45
|
+
#{arg} = #{default.inspect} unless #{arg}
|
45
46
|
#{arg} = #{get_env_string ? eval( "#{get_env_string}" ) : "YAML::load(#{envs})" } if #{envs}
|
46
47
|
return #{arg}
|
47
48
|
end
|
@@ -190,6 +190,19 @@ EOF
|
|
190
190
|
EOF
|
191
191
|
end
|
192
192
|
|
193
|
+
def add_run_options
|
194
|
+
get_output.print <<EOF
|
195
|
+
VALUE _boast_run_opts;
|
196
|
+
_boast_run_opts = rb_const_get(rb_cObject, rb_intern("BOAST"));
|
197
|
+
_boast_run_opts = rb_funcall(_boast_run_opts, rb_intern("get_run_config"), 0);
|
198
|
+
if ( NUM2UINT(rb_funcall(_boast_run_opts, rb_intern("size"), 0)) > 0 ) {
|
199
|
+
if ( _boast_rb_opts != Qnil )
|
200
|
+
rb_funcall(_boast_run_opts, rb_intern("update"), 1, _boast_rb_opts);
|
201
|
+
_boast_rb_opts = _boast_run_opts;
|
202
|
+
}
|
203
|
+
EOF
|
204
|
+
end
|
205
|
+
|
193
206
|
def fill_decl_module_params
|
194
207
|
push_env(:decl_module => true)
|
195
208
|
@procedure.parameters.each { |param|
|
@@ -314,6 +327,8 @@ EOF
|
|
314
327
|
|
315
328
|
fill_check_args
|
316
329
|
|
330
|
+
add_run_options
|
331
|
+
|
317
332
|
fill_decl_module_params
|
318
333
|
|
319
334
|
@probes.reverse.map(&:decl)
|
@@ -112,7 +112,7 @@ module BOAST
|
|
112
112
|
def setup_cuda_compiler(options, runner)
|
113
113
|
cuda_compiler = options[:NVCC]
|
114
114
|
cudaflags = options[:NVCCFLAGS]
|
115
|
-
cudaflags += " --compiler-options '-fPIC'"
|
115
|
+
cudaflags += " --compiler-options '-fPIC','-D_FORCE_INLINES'"
|
116
116
|
|
117
117
|
rule ".#{RbConfig::CONFIG["OBJEXT"]}" => '.cu' do |t|
|
118
118
|
cuda_call_string = "#{cuda_compiler} #{cudaflags} -c -o #{t.name} #{t.source}"
|
data/lib/BOAST/Runtime/Config.rb
CHANGED
@@ -31,6 +31,13 @@ module BOAST
|
|
31
31
|
"icpc" => "-openmp"
|
32
32
|
}
|
33
33
|
|
34
|
+
@@run_options = [
|
35
|
+
:PAPI
|
36
|
+
]
|
37
|
+
|
38
|
+
@@run_config = {
|
39
|
+
}
|
40
|
+
|
34
41
|
module PrivateStateAccessor
|
35
42
|
private_boolean_state_accessor :verbose
|
36
43
|
private_boolean_state_accessor :debug_source
|
@@ -52,13 +59,9 @@ module BOAST
|
|
52
59
|
|
53
60
|
module_function
|
54
61
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
Dir.mkdir( home_config_dir ) if not File::exist?( home_config_dir )
|
59
|
-
return if not File::directory?(home_config_dir)
|
60
|
-
boast_config_dir = "#{home_config_dir}/BOAST"
|
61
|
-
Dir.mkdir( boast_config_dir ) if not File::exist?( boast_config_dir )
|
62
|
+
def read_boast_compiler_config
|
63
|
+
boast_config_dir = assert_boast_config_dir
|
64
|
+
return unless boast_config_dir
|
62
65
|
compiler_options_file = "#{boast_config_dir}/compiler_options"
|
63
66
|
if File::exist?( compiler_options_file ) then
|
64
67
|
File::open( compiler_options_file, "r" ) { |f|
|
@@ -85,7 +88,7 @@ module BOAST
|
|
85
88
|
@@compiler_default_options[:LD] = ENV["LD"] if ENV["LD"]
|
86
89
|
end
|
87
90
|
|
88
|
-
|
91
|
+
read_boast_compiler_config
|
89
92
|
|
90
93
|
def get_openmp_flags
|
91
94
|
return @@openmp_default_flags.clone
|
@@ -95,4 +98,27 @@ module BOAST
|
|
95
98
|
return @@compiler_default_options.clone
|
96
99
|
end
|
97
100
|
|
101
|
+
def read_boast_run_config
|
102
|
+
boast_config_dir = assert_boast_config_dir
|
103
|
+
run_config_file = "#{boast_config_dir}/run_config"
|
104
|
+
if File::exist?( run_config_file ) then
|
105
|
+
File::open( run_config_file, "r" ) { |f|
|
106
|
+
@@run_config.update( YAML::load( f.read ) )
|
107
|
+
}
|
108
|
+
else
|
109
|
+
File::open( run_config_file, "w" ) { |f|
|
110
|
+
f.write YAML::dump( @@run_config )
|
111
|
+
}
|
112
|
+
end
|
113
|
+
@@run_options.each { |o|
|
114
|
+
@@run_config[o] = YAML::load(ENV[o.to_s]) if ENV[o.to_s]
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
read_boast_run_config
|
119
|
+
|
120
|
+
def get_run_config
|
121
|
+
return @@run_config.clone
|
122
|
+
end
|
123
|
+
|
98
124
|
end
|
@@ -31,68 +31,64 @@ module BOAST
|
|
31
31
|
ffi_lib "#{library_path}"
|
32
32
|
attach_function :#{method_name}, [ #{@procedure.parameters.collect{ |p| ":"+p.decl_ffi(false,@lang).to_s }.join(", ")} ], :#{@procedure.properties[:return] ? @procedure.properties[:return].type.decl_ffi(false,@lang) : "void" }
|
33
33
|
def run(*args)
|
34
|
-
if args.length < @procedure.parameters.length or args.length > @procedure.parameters.length + 1
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
raise "Wrong number of arguments for \#{@procedure.name} (\#{args.length} for \#{@procedure.parameters.length})" if args.length < @procedure.parameters.length or args.length > @procedure.parameters.length + 1
|
35
|
+
ev_set = nil
|
36
|
+
options = BOAST::get_run_config
|
37
|
+
options.update(args.last) if args.length == @procedure.parameters.length + 1
|
38
|
+
if options[:PAPI] then
|
39
|
+
require 'PAPI'
|
40
|
+
ev_set = PAPI::EventSet::new
|
41
|
+
ev_set.add_named(options[:PAPI])
|
42
|
+
end
|
43
|
+
t_args = []
|
44
|
+
r_args = {}
|
45
|
+
if @lang == FORTRAN then
|
46
|
+
@procedure.parameters.each_with_index { |p, i|
|
47
|
+
if p.decl_ffi(true,@lang) != :pointer then
|
48
|
+
arg_p = FFI::MemoryPointer::new(p.decl_ffi(true, @lang))
|
49
|
+
arg_p.send("write_\#{p.decl_ffi(true, @lang)}",args[i])
|
50
|
+
t_args.push(arg_p)
|
51
|
+
r_args[p] = arg_p if p.scalar_output?
|
52
|
+
else
|
53
|
+
t_args.push( args[i] )
|
44
54
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
else
|
56
|
-
t_args.push( args[i] )
|
57
|
-
end
|
58
|
-
}
|
59
|
-
else
|
60
|
-
@procedure.parameters.each_with_index { |p, i|
|
61
|
-
if p.scalar_output? then
|
62
|
-
arg_p = FFI::MemoryPointer::new(p.decl_ffi(true, @lang))
|
63
|
-
arg_p.send("write_\#{p.decl_ffi(true,@lang)}",args[i])
|
64
|
-
t_args.push(arg_p)
|
65
|
-
r_args[p] = arg_p
|
66
|
-
else
|
67
|
-
t_args.push( args[i] )
|
68
|
-
end
|
69
|
-
}
|
70
|
-
end
|
71
|
-
results = {}
|
72
|
-
counters = nil
|
73
|
-
ev_set.start if ev_set
|
74
|
-
begin
|
75
|
-
start = Time::new
|
76
|
-
ret = #{method_name}(*t_args)
|
77
|
-
stop = Time::new
|
78
|
-
ensure
|
79
|
-
if ev_set then
|
80
|
-
counters = ev_set.stop
|
81
|
-
ev_set.cleanup
|
82
|
-
ev_set.destroy
|
55
|
+
}
|
56
|
+
else
|
57
|
+
@procedure.parameters.each_with_index { |p, i|
|
58
|
+
if p.scalar_output? then
|
59
|
+
arg_p = FFI::MemoryPointer::new(p.decl_ffi(true, @lang))
|
60
|
+
arg_p.send("write_\#{p.decl_ffi(true,@lang)}",args[i])
|
61
|
+
t_args.push(arg_p)
|
62
|
+
r_args[p] = arg_p
|
63
|
+
else
|
64
|
+
t_args.push( args[i] )
|
83
65
|
end
|
66
|
+
}
|
67
|
+
end
|
68
|
+
results = {}
|
69
|
+
counters = nil
|
70
|
+
ev_set.start if ev_set
|
71
|
+
begin
|
72
|
+
start = Time::new
|
73
|
+
ret = #{method_name}(*t_args)
|
74
|
+
stop = Time::new
|
75
|
+
ensure
|
76
|
+
if ev_set then
|
77
|
+
counters = ev_set.stop
|
78
|
+
ev_set.cleanup
|
79
|
+
ev_set.destroy
|
84
80
|
end
|
85
|
-
results = { :start => start, :stop => stop, :duration => stop - start, :return => ret }
|
86
|
-
results[:PAPI] = Hash[[options[:PAPI]].flatten.zip(counters)] if ev_set
|
87
|
-
if r_args.length > 0 then
|
88
|
-
ref_return = {}
|
89
|
-
r_args.each { |p, p_arg|
|
90
|
-
ref_return[p.name.to_sym] = p_arg.send("read_\#{p.decl_ffi(true, @lang)}")
|
91
|
-
}
|
92
|
-
results[:reference_return] = ref_return
|
93
|
-
end
|
94
|
-
return results
|
95
81
|
end
|
82
|
+
results = { :start => start, :stop => stop, :duration => stop - start, :return => ret }
|
83
|
+
results[:PAPI] = Hash[[options[:PAPI]].flatten.zip(counters)] if ev_set
|
84
|
+
if r_args.length > 0 then
|
85
|
+
ref_return = {}
|
86
|
+
r_args.each { |p, p_arg|
|
87
|
+
ref_return[p.name.to_sym] = p_arg.send("read_\#{p.decl_ffi(true, @lang)}")
|
88
|
+
}
|
89
|
+
results[:reference_return] = ref_return
|
90
|
+
end
|
91
|
+
return results
|
96
92
|
end
|
97
93
|
end
|
98
94
|
EOF
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module BOAST
|
2
2
|
module OpenCLRuntime
|
3
3
|
|
4
|
-
|
4
|
+
attr_reader :context
|
5
|
+
attr_reader :queue
|
6
|
+
|
7
|
+
def select_cl_platforms(options)
|
5
8
|
platforms = OpenCL::get_platforms
|
6
9
|
if options[:platform_vendor] then
|
7
10
|
platforms.select!{ |p|
|
@@ -17,53 +20,41 @@ module BOAST
|
|
17
20
|
p.name.match(options[:CLPLATFORM])
|
18
21
|
}
|
19
22
|
end
|
20
|
-
return platforms
|
23
|
+
return platforms
|
21
24
|
end
|
22
25
|
|
23
|
-
def select_cl_device(options)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def select_cl_device(options, context = nil)
|
27
|
+
return options[:CLDEVICE] if options[:CLDEVICE] and options[:CLDEVICE].is_a?(OpenCL::Device)
|
28
|
+
devices = nil
|
29
|
+
if context then
|
30
|
+
devices = context.devices
|
31
|
+
else
|
32
|
+
platforms = select_cl_platforms(options)
|
33
|
+
type = options[:device_type] ? OpenCL::Device::Type.const_get(options[:device_type]) : options[:CLDEVICETYPE] ? OpenCL::Device::Type.const_get(options[:CLDEVICETYPE]) : OpenCL::Device::Type::ALL
|
34
|
+
devices = platforms.collect { |plt| plt.devices(type) }
|
35
|
+
devices.flatten!
|
36
|
+
end
|
37
|
+
name_pattern = options[:device_name]
|
38
|
+
name_pattern = options[:CLDEVICE] unless name_pattern
|
39
|
+
if name_pattern then
|
32
40
|
devices.select!{ |d|
|
33
|
-
d.name.match(
|
41
|
+
d.name.match(name_pattern)
|
34
42
|
}
|
35
43
|
end
|
36
44
|
return devices.first
|
37
45
|
end
|
38
46
|
|
39
|
-
def init_opencl_types
|
40
|
-
@@opencl_real_types = {
|
41
|
-
2 => OpenCL::Half1,
|
42
|
-
4 => OpenCL::Float1,
|
43
|
-
8 => OpenCL::Double1
|
44
|
-
}
|
45
|
-
|
46
|
-
@@opencl_int_types = {
|
47
|
-
true => {
|
48
|
-
1 => OpenCL::Char1,
|
49
|
-
2 => OpenCL::Short1,
|
50
|
-
4 => OpenCL::Int1,
|
51
|
-
8 => OpenCL::Long1
|
52
|
-
},
|
53
|
-
false => {
|
54
|
-
1 => OpenCL::UChar1,
|
55
|
-
2 => OpenCL::UShort1,
|
56
|
-
4 => OpenCL::UInt1,
|
57
|
-
8 => OpenCL::ULong1
|
58
|
-
}
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
47
|
def init_opencl(options)
|
63
48
|
require 'opencl_ruby_ffi'
|
64
|
-
|
65
|
-
device =
|
66
|
-
|
49
|
+
require 'BOAST/Runtime/OpenCLTypes.rb'
|
50
|
+
device = nil
|
51
|
+
if options[:CLCONTEXT] then
|
52
|
+
@context = options[:CLCONTEXT]
|
53
|
+
device = select_cl_device(options, @context)
|
54
|
+
else
|
55
|
+
device = select_cl_device(options)
|
56
|
+
@context = OpenCL::create_context([device])
|
57
|
+
end
|
67
58
|
program = @context.create_program_with_source([@code.string])
|
68
59
|
opts = options[:CLFLAGS]
|
69
60
|
begin
|
@@ -88,6 +79,7 @@ module BOAST
|
|
88
79
|
end
|
89
80
|
|
90
81
|
def create_opencl_array(arg, parameter)
|
82
|
+
return arg if arg.kind_of? OpenCL::Mem
|
91
83
|
if parameter.direction == :in then
|
92
84
|
flags = OpenCL::Mem::Flags::READ_ONLY
|
93
85
|
elsif parameter.direction == :out then
|
@@ -107,9 +99,9 @@ module BOAST
|
|
107
99
|
|
108
100
|
def create_opencl_scalar(arg, parameter)
|
109
101
|
if parameter.type.is_a?(Real) then
|
110
|
-
return
|
102
|
+
return OPENCL_REAL_TYPES[parameter.type.size]::new(arg)
|
111
103
|
elsif parameter.type.is_a?(Int) then
|
112
|
-
return
|
104
|
+
return OPENCL_INT_TYPES[parameter.type.signed][parameter.type.size]::new(arg)
|
113
105
|
else
|
114
106
|
return arg
|
115
107
|
end
|
@@ -124,6 +116,7 @@ module BOAST
|
|
124
116
|
end
|
125
117
|
|
126
118
|
def read_opencl_param(param, arg, parameter)
|
119
|
+
return arg if arg.kind_of? OpenCL::Mem
|
127
120
|
if parameter.texture then
|
128
121
|
@queue.enqueue_read_image( param, arg, :blocking => true )
|
129
122
|
else
|
@@ -140,8 +133,8 @@ module BOAST
|
|
140
133
|
def self.run(*args)
|
141
134
|
raise "Wrong number of arguments \#{args.length} for #{@procedure.parameters.length}" if args.length > #{@procedure.parameters.length+1} or args.length < #{@procedure.parameters.length}
|
142
135
|
params = []
|
143
|
-
opts =
|
144
|
-
opts = args.pop if args.length == #{@procedure.parameters.length+1}
|
136
|
+
opts = BOAST::get_run_config
|
137
|
+
opts = opts.update(args.pop) if args.length == #{@procedure.parameters.length+1}
|
145
138
|
@procedure.parameters.each_index { |i|
|
146
139
|
params[i] = create_opencl_param( args[i], @procedure.parameters[i] )
|
147
140
|
}
|
@@ -150,8 +143,10 @@ def self.run(*args)
|
|
150
143
|
}
|
151
144
|
gws = opts[:global_work_size]
|
152
145
|
if not gws then
|
146
|
+
raise ":global_work_size or :block_number are required to run OpenCL kernels!" unless opts[:block_number]
|
153
147
|
gws = []
|
154
148
|
opts[:block_number].each_index { |i|
|
149
|
+
raise "if using :block_number, :block_size is required to run OpenCL kernels!" unless opts[:block_size]
|
155
150
|
gws.push(opts[:block_number][i]*opts[:block_size][i])
|
156
151
|
}
|
157
152
|
end
|
@@ -165,6 +160,7 @@ def self.run(*args)
|
|
165
160
|
read_opencl_param( params[i], args[i], @procedure.parameters[i] )
|
166
161
|
end
|
167
162
|
}
|
163
|
+
@queue.finish
|
168
164
|
result = {}
|
169
165
|
result[:start] = event.profiling_command_start
|
170
166
|
result[:end] = event.profiling_command_end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module BOAST
|
2
|
+
module OpenCLRuntime
|
3
|
+
OPENCL_REAL_TYPES = {
|
4
|
+
2 => OpenCL::Half1,
|
5
|
+
4 => OpenCL::Float1,
|
6
|
+
8 => OpenCL::Double1
|
7
|
+
}
|
8
|
+
|
9
|
+
OPENCL_INT_TYPES = {
|
10
|
+
true => {
|
11
|
+
1 => OpenCL::Char1,
|
12
|
+
2 => OpenCL::Short1,
|
13
|
+
4 => OpenCL::Int1,
|
14
|
+
8 => OpenCL::Long1
|
15
|
+
},
|
16
|
+
false => {
|
17
|
+
1 => OpenCL::UChar1,
|
18
|
+
2 => OpenCL::UShort1,
|
19
|
+
4 => OpenCL::UInt1,
|
20
|
+
8 => OpenCL::ULong1
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
data/lib/BOAST.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: BOAST
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brice Videau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: narray
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- lib/BOAST/Language/Case.rb
|
205
205
|
- lib/BOAST/Language/CodeBlock.rb
|
206
206
|
- lib/BOAST/Language/Comment.rb
|
207
|
+
- lib/BOAST/Language/Config.rb
|
207
208
|
- lib/BOAST/Language/ControlStructure.rb
|
208
209
|
- lib/BOAST/Language/DataTypes.rb
|
209
210
|
- lib/BOAST/Language/Error.rb
|
@@ -239,10 +240,11 @@ files:
|
|
239
240
|
- lib/BOAST/Runtime/MPPARuntime.rb
|
240
241
|
- lib/BOAST/Runtime/NonRegression.rb
|
241
242
|
- lib/BOAST/Runtime/OpenCLRuntime.rb
|
243
|
+
- lib/BOAST/Runtime/OpenCLTypes.rb
|
242
244
|
- lib/BOAST/Runtime/Probe.rb
|
243
245
|
homepage: https://github.com/Nanosim-LIG/boast
|
244
246
|
licenses:
|
245
|
-
- BSD
|
247
|
+
- BSD-2-Clause
|
246
248
|
metadata: {}
|
247
249
|
post_install_message:
|
248
250
|
rdoc_options: []
|
@@ -260,8 +262,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
262
|
version: '0'
|
261
263
|
requirements: []
|
262
264
|
rubyforge_project:
|
263
|
-
rubygems_version: 2.
|
265
|
+
rubygems_version: 2.5.1
|
264
266
|
signing_key:
|
265
267
|
specification_version: 4
|
266
268
|
summary: BOAST is a computing kernel metaprogramming tool.
|
267
269
|
test_files: []
|
270
|
+
has_rdoc: false
|