BOAST 1.0.3 → 1.0.4
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 +4 -4
- data/BOAST.gemspec +2 -31
- data/README.md +240 -0
- data/lib/BOAST/{OpenMP.rb → Language/OpenMP.rb} +1 -0
- data/lib/BOAST/{Variable.rb → Language/Variable.rb} +2 -1
- data/lib/BOAST/Runtime/CKernel.rb +94 -0
- data/lib/BOAST/Runtime/CRuntime.rb +32 -0
- data/lib/BOAST/Runtime/CUDARuntime.rb +158 -0
- data/lib/BOAST/Runtime/CompiledRuntime.rb +398 -0
- data/lib/BOAST/Runtime/Compilers.rb +205 -0
- data/lib/BOAST/Runtime/Config.rb +94 -0
- data/lib/BOAST/Runtime/FFIRuntime.rb +104 -0
- data/lib/BOAST/Runtime/FORTRANRuntime.rb +45 -0
- data/lib/BOAST/Runtime/MPPARuntime.rb +464 -0
- data/lib/BOAST/Runtime/NonRegression.rb +157 -0
- data/lib/BOAST/Runtime/OpenCLRuntime.rb +181 -0
- data/lib/BOAST/Runtime/Probe.rb +136 -0
- data/lib/BOAST.rb +37 -26
- metadata +40 -28
- data/lib/BOAST/CKernel.rb +0 -1236
- /data/lib/BOAST/{Algorithm.rb → Language/Algorithm.rb} +0 -0
- /data/lib/BOAST/{Arithmetic.rb → Language/Arithmetic.rb} +0 -0
- /data/lib/BOAST/{BOAST_OpenCL.rb → Language/BOAST_OpenCL.rb} +0 -0
- /data/lib/BOAST/{Case.rb → Language/Case.rb} +0 -0
- /data/lib/BOAST/{ControlStructure.rb → Language/ControlStructure.rb} +0 -0
- /data/lib/BOAST/{DataTypes.rb → Language/DataTypes.rb} +0 -0
- /data/lib/BOAST/{Expression.rb → Language/Expression.rb} +0 -0
- /data/lib/BOAST/{For.rb → Language/For.rb} +0 -0
- /data/lib/BOAST/{FuncCall.rb → Language/FuncCall.rb} +0 -0
- /data/lib/BOAST/{Functors.rb → Language/Functors.rb} +0 -0
- /data/lib/BOAST/{If.rb → Language/If.rb} +0 -0
- /data/lib/BOAST/{Index.rb → Language/Index.rb} +0 -0
- /data/lib/BOAST/{Inspectable.rb → Language/Inspectable.rb} +0 -0
- /data/lib/BOAST/{Operators.rb → Language/Operators.rb} +0 -0
- /data/lib/BOAST/{Optimization.rb → Language/Optimization.rb} +0 -0
- /data/lib/BOAST/{Parens.rb → Language/Parens.rb} +0 -0
- /data/lib/BOAST/{Pragma.rb → Language/Pragma.rb} +0 -0
- /data/lib/BOAST/{Print.rb → Language/Print.rb} +0 -0
- /data/lib/BOAST/{Procedure.rb → Language/Procedure.rb} +0 -0
- /data/lib/BOAST/{Slice.rb → Language/Slice.rb} +0 -0
- /data/lib/BOAST/{State.rb → Language/State.rb} +0 -0
- /data/lib/BOAST/{Transitions.rb → Language/Transitions.rb} +0 -0
- /data/lib/BOAST/{While.rb → Language/While.rb} +0 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
module BOAST
|
2
|
+
|
3
|
+
module FFIRuntime
|
4
|
+
|
5
|
+
def target
|
6
|
+
return library_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def target_depends
|
10
|
+
return [ library_object ]
|
11
|
+
end
|
12
|
+
|
13
|
+
def target_sources
|
14
|
+
return [ library_source ]
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_module
|
18
|
+
create_ffi_module
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_sources
|
22
|
+
create_library_source
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_ffi_module
|
26
|
+
s =<<EOF
|
27
|
+
require 'ffi'
|
28
|
+
require 'narray_ffi'
|
29
|
+
module #{module_name}
|
30
|
+
extend FFI::Library
|
31
|
+
ffi_lib "#{library_path}"
|
32
|
+
attach_function :#{method_name}, [ #{@procedure.parameters.collect{ |p| ":"+p.decl_ffi.to_s }.join(", ")} ], :#{@procedure.properties[:return] ? @procedure.properties[:return].type.decl_ffi : "void" }
|
33
|
+
def run(*args)
|
34
|
+
if args.length < @procedure.parameters.length or args.length > @procedure.parameters.length + 1 then
|
35
|
+
raise "Wrong number of arguments for \#{@procedure.name} (\#{args.length} for \#{@procedure.parameters.length})"
|
36
|
+
else
|
37
|
+
ev_set = nil
|
38
|
+
if args.length == @procedure.parameters.length + 1 then
|
39
|
+
options = args.last
|
40
|
+
if options[:PAPI] then
|
41
|
+
require 'PAPI'
|
42
|
+
ev_set = PAPI::EventSet::new
|
43
|
+
ev_set.add_named(options[:PAPI])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
t_args = []
|
47
|
+
r_args = {}
|
48
|
+
if @lang == FORTRAN then
|
49
|
+
@procedure.parameters.each_with_index { |p, i|
|
50
|
+
if p.decl_ffi(true) != :pointer then
|
51
|
+
arg_p = FFI::MemoryPointer::new(p.decl_ffi(true))
|
52
|
+
arg_p.send("write_\#{p.decl_ffi(true)}",args[i])
|
53
|
+
t_args.push(arg_p)
|
54
|
+
r_args[p] = arg_p if p.scalar_output?
|
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))
|
63
|
+
arg_p.send("write_\#{p.decl_ffi(true)}",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
|
83
|
+
end
|
84
|
+
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)}")
|
91
|
+
}
|
92
|
+
results[:reference_return] = ref_return
|
93
|
+
end
|
94
|
+
return results
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
EOF
|
99
|
+
BOAST::class_eval s
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module BOAST
|
2
|
+
|
3
|
+
module FORTRANRuntime
|
4
|
+
include CompiledRuntime
|
5
|
+
|
6
|
+
def method_name
|
7
|
+
return @procedure.name + "_"
|
8
|
+
end
|
9
|
+
|
10
|
+
def fill_library_source
|
11
|
+
@code.rewind
|
12
|
+
@code.each_line { |line|
|
13
|
+
# check for omp pragmas
|
14
|
+
if line.match(/^\s*!\$/) then
|
15
|
+
if line.match(/^\s*!\$(omp|OMP)/) then
|
16
|
+
chunks = line.scan(/.{1,#{FORTRAN_LINE_LENGTH-7}}/)
|
17
|
+
get_output.puts chunks.join("&\n!$omp&")
|
18
|
+
else
|
19
|
+
chunks = line.scan(/.{1,#{FORTRAN_LINE_LENGTH-4}}/)
|
20
|
+
get_output.puts chunks.join("&\n!$&")
|
21
|
+
end
|
22
|
+
elsif line.match(/^\w*!/) then
|
23
|
+
get_output.write line
|
24
|
+
else
|
25
|
+
chunks = line.scan(/.{1,#{FORTRAN_LINE_LENGTH-2}}/)
|
26
|
+
get_output.puts chunks.join("&\n&")
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_procedure_call_parameters
|
32
|
+
params = []
|
33
|
+
@procedure.parameters.each { |param|
|
34
|
+
if param.dimension then
|
35
|
+
params.push( param.name )
|
36
|
+
else
|
37
|
+
params.push( "&"+param.name )
|
38
|
+
end
|
39
|
+
}
|
40
|
+
return params
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,464 @@
|
|
1
|
+
module BOAST
|
2
|
+
|
3
|
+
module MPPARuntime
|
4
|
+
include CRuntime
|
5
|
+
|
6
|
+
alias create_targets_old create_targets
|
7
|
+
alias cleanup_old cleanup
|
8
|
+
alias fill_module_header_old fill_module_header
|
9
|
+
alias get_params_value_old get_params_value
|
10
|
+
alias fill_decl_module_params_old fill_decl_module_params
|
11
|
+
alias get_results_old get_results
|
12
|
+
alias store_results_old store_results
|
13
|
+
|
14
|
+
def cleanup(kernel_files)
|
15
|
+
cleanup_old(kernel_files)
|
16
|
+
([io_bin, comp_bin, io_object, comp_object]).each { |fn|
|
17
|
+
File::unlink(fn)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def target_depends
|
22
|
+
return [ module_file_object ]
|
23
|
+
end
|
24
|
+
|
25
|
+
def target_sources
|
26
|
+
return [ module_file_source, io_source, comp_source ]
|
27
|
+
end
|
28
|
+
|
29
|
+
def multibinary_path
|
30
|
+
return "#{base_path}.mpk"
|
31
|
+
end
|
32
|
+
|
33
|
+
def io_bin
|
34
|
+
return "#{base_path}.binio"
|
35
|
+
end
|
36
|
+
|
37
|
+
def comp_bin
|
38
|
+
return "#{base_path}.bincomp"
|
39
|
+
end
|
40
|
+
|
41
|
+
def io_object
|
42
|
+
return "#{base_path}.#{RbConfig::CONFIG["OBJEXT"]}io"
|
43
|
+
end
|
44
|
+
|
45
|
+
def comp_object
|
46
|
+
return "#{base_path}.#{RbConfig::CONFIG["OBJEXT"]}comp"
|
47
|
+
end
|
48
|
+
|
49
|
+
def io_source
|
50
|
+
return "#{base_path}.cio"
|
51
|
+
end
|
52
|
+
|
53
|
+
def comp_source
|
54
|
+
return "#{base_path}.ccomp"
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_io
|
58
|
+
set_output(@code_io)
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_comp
|
62
|
+
@code_comp = StringIO::new unless @code_comp
|
63
|
+
set_output(@code_comp)
|
64
|
+
end
|
65
|
+
|
66
|
+
attr_accessor :code_comp
|
67
|
+
attr_accessor :procedure_comp
|
68
|
+
attr_accessor :binary_comp
|
69
|
+
attr_accessor :multibinary
|
70
|
+
|
71
|
+
def save_binary
|
72
|
+
f = File::open(io_object,"rb")
|
73
|
+
@binary = StringIO::new
|
74
|
+
@binary.write( f.read )
|
75
|
+
f.close
|
76
|
+
f = File::open(comp_object,"rb")
|
77
|
+
@binary_comp = StringIO::new
|
78
|
+
@binary_comp.write( f.read )
|
79
|
+
f.close
|
80
|
+
f = File::open(multibinary_path,"rb")
|
81
|
+
@multibinary = StringIO::new
|
82
|
+
@multibinary.write( f.read )
|
83
|
+
f.close
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_targets( linker, ldshared, ldflags, kernel_files )
|
87
|
+
create_targets_old( linker, ldshared, ldflags, kernel_files )
|
88
|
+
file multibinary_path => [io_bin, comp_bin] do
|
89
|
+
sh "k1-create-multibinary --clusters #{comp_bin} --clusters-names \"comp-part\" --boot #{io_bin} --bootname \"io-part\" -T #{multibinary_path}"
|
90
|
+
end
|
91
|
+
Rake::Task[multibinary_path].invoke
|
92
|
+
end
|
93
|
+
|
94
|
+
def fill_multibinary_header
|
95
|
+
fill_library_header
|
96
|
+
get_output.puts "#include <mppaipc.h>"
|
97
|
+
get_output.puts "#include <mppa/osconfig.h>"
|
98
|
+
end
|
99
|
+
|
100
|
+
def copy_array_param_from_host( param )
|
101
|
+
get_output.write <<EOF
|
102
|
+
mppa_read(_mppa_from_host_size, &_mppa_#{param}_size, sizeof(_mppa_#{param}_size));
|
103
|
+
#{param} = malloc(_mppa_#{param}_size);
|
104
|
+
mppa_read(_mppa_from_host_var, #{param}, _mppa_#{param}_size);
|
105
|
+
EOF
|
106
|
+
end
|
107
|
+
|
108
|
+
def copy_scalar_param_from_host( param )
|
109
|
+
get_output.write <<EOF
|
110
|
+
mppa_read(_mppa_from_host_var, &#{param}, sizeof(#{param}));
|
111
|
+
EOF
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_cluster_list_from_host
|
115
|
+
get_output.write <<EOF
|
116
|
+
mppa_read(_mppa_from_host_size, &_mppa_clust_list_size, sizeof(_mppa_clust_list_size));
|
117
|
+
_clust_list = malloc(_mppa_clust_list_size);
|
118
|
+
_nb_clust = _mppa_clust_list_size / sizeof(*_clust_list);
|
119
|
+
mppa_read(_mppa_from_host_var, _clust_list, _mppa_clust_list_size);
|
120
|
+
EOF
|
121
|
+
end
|
122
|
+
|
123
|
+
def copy_array_param_to_host(param)
|
124
|
+
get_output.write <<EOF
|
125
|
+
mppa_write(_mppa_to_host_var, #{param}, _mppa_#{param}_size);
|
126
|
+
EOF
|
127
|
+
end
|
128
|
+
|
129
|
+
def copy_scalar_param_to_host(param)
|
130
|
+
get_output.write <<EOF
|
131
|
+
mppa_write(_mppa_to_host_var, &#{param}, sizeof(#{param}));
|
132
|
+
EOF
|
133
|
+
end
|
134
|
+
|
135
|
+
def multibinary_main_io_source_decl
|
136
|
+
#Parameters declaration
|
137
|
+
@procedure.parameters.each { |param|
|
138
|
+
get_output.write " #{param.type.decl} "
|
139
|
+
get_output.write "*" if param.dimension or param.scalar_output?
|
140
|
+
get_output.puts "#{param.name};"
|
141
|
+
if param.dimension then
|
142
|
+
get_output.puts " size_t _mppa_#{param}_size;"
|
143
|
+
end
|
144
|
+
}
|
145
|
+
|
146
|
+
#Return value declaration
|
147
|
+
get_output.puts " #{@procedure.properties[:return].type.decl} _mppa_ret;" if @procedure.properties[:return]
|
148
|
+
|
149
|
+
#Cluster list declaration
|
150
|
+
get_output.write <<EOF
|
151
|
+
uint32_t *_clust_list;
|
152
|
+
int _nb_clust;
|
153
|
+
int _mppa_clust_list_size;
|
154
|
+
EOF
|
155
|
+
|
156
|
+
#Communication variables
|
157
|
+
get_output.write <<EOF
|
158
|
+
int _mppa_from_host_size, _mppa_from_host_var;
|
159
|
+
int _mppa_to_host_size, _mppa_to_host_var;
|
160
|
+
int _mppa_pid[16], _mppa_i;
|
161
|
+
EOF
|
162
|
+
end
|
163
|
+
|
164
|
+
def multibinary_main_io_source_get_params
|
165
|
+
#Receiving parameters from Host
|
166
|
+
get_output.write <<EOF
|
167
|
+
_mppa_from_host_size = mppa_open("/mppa/buffer/board0#mppa0#pcie0#2/host#2", O_RDONLY);
|
168
|
+
_mppa_from_host_var = mppa_open("/mppa/buffer/board0#mppa0#pcie0#3/host#3", O_RDONLY);
|
169
|
+
EOF
|
170
|
+
@procedure.parameters.each { |param|
|
171
|
+
if param.dimension then
|
172
|
+
copy_array_param_from_host(param)
|
173
|
+
else
|
174
|
+
copy_scalar_param_from_host(param)
|
175
|
+
end
|
176
|
+
}
|
177
|
+
|
178
|
+
#Receiving cluster list
|
179
|
+
get_cluster_list_from_host
|
180
|
+
|
181
|
+
get_output.write <<EOF
|
182
|
+
mppa_close(_mppa_from_host_size);
|
183
|
+
mppa_close(_mppa_from_host_var);
|
184
|
+
EOF
|
185
|
+
end
|
186
|
+
|
187
|
+
def multibinary_main_io_source_send_results
|
188
|
+
#Sending results to Host
|
189
|
+
get_output.write <<EOF
|
190
|
+
_mppa_to_host_var = mppa_open("/mppa/buffer/host#4/board0#mppa0#pcie0#4", O_WRONLY);
|
191
|
+
EOF
|
192
|
+
@procedure.parameters.each { |param|
|
193
|
+
if param.direction == :out or param.direction == :inout then
|
194
|
+
if param.dimension then
|
195
|
+
copy_array_param_to_host(param)
|
196
|
+
else
|
197
|
+
copy_scalar_param_to_host(param)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
}
|
201
|
+
copy_scalar_param_to_host("_mppa_ret") if @procedure.properties[:return]
|
202
|
+
get_output.write <<EOF
|
203
|
+
mppa_close(_mppa_to_host_var);
|
204
|
+
EOF
|
205
|
+
end
|
206
|
+
|
207
|
+
def fill_multibinary_main_io_source
|
208
|
+
multibinary_main_io_source_decl
|
209
|
+
|
210
|
+
multibinary_main_io_source_get_params
|
211
|
+
|
212
|
+
#Spawning cluster
|
213
|
+
get_output.write <<EOF
|
214
|
+
for(_mppa_i=0; _mppa_i<_nb_clust; _mppa_i++){
|
215
|
+
_mppa_pid[_mppa_i] = mppa_spawn(_clust_list[_mppa_i], NULL, "comp-part", NULL, NULL);
|
216
|
+
}
|
217
|
+
EOF
|
218
|
+
#Calling IO procedure
|
219
|
+
get_output.write " _mppa_ret =" if @procedure.properties[:return]
|
220
|
+
get_output.write " #{@procedure.name}("
|
221
|
+
get_output.write @procedure.parameters.map(&:name).join(", ")
|
222
|
+
get_output.puts ");"
|
223
|
+
|
224
|
+
#Waiting for clusters
|
225
|
+
get_output.write <<EOF
|
226
|
+
for(_mppa_i=0; _mppa_i<_nb_clust; _mppa_i++){
|
227
|
+
mppa_waitpid(_mppa_pid[_mppa_i], NULL, 0);
|
228
|
+
}
|
229
|
+
EOF
|
230
|
+
|
231
|
+
multibinary_main_io_source_send_results
|
232
|
+
end
|
233
|
+
|
234
|
+
def fill_multibinary_main_comp_source
|
235
|
+
if @procedure_comp then
|
236
|
+
get_output.puts " #{@procedure_comp.name}();"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def fill_multibinary_source(mode)
|
241
|
+
fill_multibinary_header
|
242
|
+
code = nil
|
243
|
+
if mode == :io then
|
244
|
+
code = @code
|
245
|
+
else
|
246
|
+
code = @code_comp
|
247
|
+
end
|
248
|
+
if code then
|
249
|
+
code.rewind
|
250
|
+
get_output.write code.read
|
251
|
+
end
|
252
|
+
get_output.puts "int main(int argc, const char* argv[]) {"
|
253
|
+
if mode == :io then
|
254
|
+
fill_multibinary_main_io_source
|
255
|
+
else
|
256
|
+
fill_multibinary_main_comp_source
|
257
|
+
end
|
258
|
+
get_output.write <<EOF
|
259
|
+
mppa_exit(0);
|
260
|
+
return 0;
|
261
|
+
}
|
262
|
+
EOF
|
263
|
+
end
|
264
|
+
|
265
|
+
def create_multibinary_source(mode)
|
266
|
+
f = File::open(self.send("#{mode}_source"),"w+")
|
267
|
+
previous_lang = get_lang
|
268
|
+
previous_output = get_output
|
269
|
+
set_output(f)
|
270
|
+
set_lang(@lang)
|
271
|
+
|
272
|
+
fill_multibinary_source(mode)
|
273
|
+
|
274
|
+
if debug_source? then
|
275
|
+
f.rewind
|
276
|
+
puts f.read
|
277
|
+
end
|
278
|
+
set_output(previous_output)
|
279
|
+
set_lang(previous_lang)
|
280
|
+
f.close
|
281
|
+
end
|
282
|
+
|
283
|
+
def create_multibinary_sources
|
284
|
+
create_multibinary_source(:io)
|
285
|
+
create_multibinary_source(:comp)
|
286
|
+
end
|
287
|
+
|
288
|
+
def create_sources
|
289
|
+
create_multibinary_sources
|
290
|
+
create_module_file_source
|
291
|
+
end
|
292
|
+
|
293
|
+
def fill_module_header
|
294
|
+
fill_module_header_old
|
295
|
+
get_output.puts "#include <mppaipc.h>"
|
296
|
+
get_output.puts "#include <mppa_mon.h>"
|
297
|
+
end
|
298
|
+
|
299
|
+
def fill_decl_module_params
|
300
|
+
fill_decl_module_params_old
|
301
|
+
get_output.print <<EOF
|
302
|
+
int _mppa_i;
|
303
|
+
int _mppa_load_id;
|
304
|
+
int _mppa_pid;
|
305
|
+
int _mppa_fd_size;
|
306
|
+
int _mppa_fd_var;
|
307
|
+
float _mppa_avg_pwr;
|
308
|
+
float _mppa_energy;
|
309
|
+
float _mppa_duration;
|
310
|
+
int _mppa_clust_list_size;
|
311
|
+
int _mppa_clust_nb;
|
312
|
+
uint32_t * _mppa_clust_list;
|
313
|
+
mppa_mon_ctx_t * _mppa_ctx;
|
314
|
+
mppa_mon_sensor_t _mppa_pwr_sensor[] = {MPPA_MON_PWR_MPPA0};
|
315
|
+
mppa_mon_measure_report_t * _mppa_report;
|
316
|
+
mppa_mon_open(0, &_mppa_ctx);
|
317
|
+
mppa_mon_measure_set_sensors(_mppa_ctx, _mppa_pwr_sensor, 1);
|
318
|
+
_mppa_load_id = mppa_load(0, 0, 0, \"#{multibinary_path}\");
|
319
|
+
mppa_mon_measure_start(_mppa_ctx);
|
320
|
+
_mppa_pid = mppa_spawn(_mppa_load_id, NULL, \"io-part\", NULL, NULL);
|
321
|
+
EOF
|
322
|
+
end
|
323
|
+
|
324
|
+
def copy_array_param_from_ruby( param, ruby_param )
|
325
|
+
rb_ptr = Variable::new("_boast_rb_ptr", CustomType, :type_name => "VALUE")
|
326
|
+
(rb_ptr === ruby_param).pr
|
327
|
+
get_output.print <<EOF
|
328
|
+
if ( IsNArray(_boast_rb_ptr) ) {
|
329
|
+
struct NARRAY *_boast_n_ary;
|
330
|
+
size_t _boast_array_size;
|
331
|
+
Data_Get_Struct(_boast_rb_ptr, struct NARRAY, _boast_n_ary);
|
332
|
+
_boast_array_size = _boast_n_ary->total * na_sizeof[_boast_n_ary->type];
|
333
|
+
mppa_write(_mppa_fd_size, &_boast_array_size, sizeof(_boast_array_size));
|
334
|
+
#{param} = (void *) _boast_n_ary->ptr;
|
335
|
+
mppa_write(_mppa_fd_var, #{param}, _boast_array_size);
|
336
|
+
} else {
|
337
|
+
rb_raise(rb_eArgError, "Wrong type of argument for %s, expecting array!", "#{param}");
|
338
|
+
}
|
339
|
+
EOF
|
340
|
+
end
|
341
|
+
|
342
|
+
def copy_scalar_param_from_ruby( param, ruby_param )
|
343
|
+
case param.type
|
344
|
+
when Int
|
345
|
+
(param === FuncCall::new("NUM2INT", ruby_param)).pr if param.type.size == 4
|
346
|
+
(param === FuncCall::new("NUM2LONG", ruby_param)).pr if param.type.size == 8
|
347
|
+
when Real
|
348
|
+
(param === FuncCall::new("NUM2DBL", ruby_param)).pr
|
349
|
+
end
|
350
|
+
get_output.puts " mppa_write(_mppa_fd_var, &#{param}, sizeof(#{param}));"
|
351
|
+
end
|
352
|
+
|
353
|
+
def get_params_value
|
354
|
+
get_output.print <<EOF
|
355
|
+
_mppa_fd_size = mppa_open(\"/mppa/buffer/board0#mppa0#pcie0#2/host#2\", O_WRONLY);
|
356
|
+
_mppa_fd_var = mppa_open(\"/mppa/buffer/board0#mppa0#pcie0#3/host#3\", O_WRONLY);
|
357
|
+
EOF
|
358
|
+
get_params_value_old
|
359
|
+
get_output.print <<EOF
|
360
|
+
if(_boast_rb_opts != Qnil) {
|
361
|
+
_boast_rb_ptr = rb_hash_aref(_boast_rb_opts, ID2SYM(rb_intern("clusters")));
|
362
|
+
if (_boast_rb_ptr != Qnil ) {
|
363
|
+
int _boast_i;
|
364
|
+
_mppa_clust_nb = RARRAY_LEN(_boast_rb_ptr);
|
365
|
+
_mppa_clust_list = malloc(sizeof(uint32_t)*_mppa_clust_nb);
|
366
|
+
for(_boast_i=0; _boast_i < _mppa_clust_nb; _boast_i++){
|
367
|
+
_mppa_clust_list[_boast_i] = NUM2INT(rb_ary_entry(_boast_rb_ptr, _boast_i));
|
368
|
+
}
|
369
|
+
} else {
|
370
|
+
_mppa_clust_list = malloc(sizeof(uint32_t));
|
371
|
+
_mppa_clust_list[0] = 0;
|
372
|
+
_mppa_clust_nb = 1;
|
373
|
+
}
|
374
|
+
} else {
|
375
|
+
_mppa_clust_list = malloc(sizeof(uint32_t));
|
376
|
+
_mppa_clust_list[0] = 0;
|
377
|
+
_mppa_clust_nb = 1;
|
378
|
+
}
|
379
|
+
|
380
|
+
_mppa_clust_list_size = sizeof(uint32_t)*_mppa_clust_nb;
|
381
|
+
mppa_write(_mppa_fd_size, &_mppa_clust_list_size, sizeof(_mppa_clust_list_size));
|
382
|
+
mppa_write(_mppa_fd_var, _mppa_clust_list, _mppa_clust_list_size);
|
383
|
+
free(_mppa_clust_list);
|
384
|
+
mppa_close(_mppa_fd_var);
|
385
|
+
mppa_close(_mppa_fd_size);
|
386
|
+
EOF
|
387
|
+
end
|
388
|
+
|
389
|
+
def create_procedure_call
|
390
|
+
end
|
391
|
+
|
392
|
+
def copy_array_param_to_ruby(param, ruby_param)
|
393
|
+
rb_ptr = Variable::new("_boast_rb_ptr", CustomType, :type_name => "VALUE")
|
394
|
+
(rb_ptr === ruby_param).pr
|
395
|
+
get_output.print <<EOF
|
396
|
+
if ( IsNArray(_boast_rb_ptr) ) {
|
397
|
+
EOF
|
398
|
+
if param.direction == :out or param.direction == :inout then
|
399
|
+
get_output.print <<EOF
|
400
|
+
struct NARRAY *_boast_n_ary;
|
401
|
+
size_t _boast_array_size;
|
402
|
+
Data_Get_Struct(_boast_rb_ptr, struct NARRAY, _boast_n_ary);
|
403
|
+
_boast_array_size = _boast_n_ary->total * na_sizeof[_boast_n_ary->type];
|
404
|
+
mppa_read(_mppa_fd_var, #{param}, _boast_array_size);
|
405
|
+
EOF
|
406
|
+
end
|
407
|
+
get_output.print <<EOF
|
408
|
+
} else {
|
409
|
+
rb_raise(rb_eArgError, "Wrong type of argument for %s, expecting array!", "#{param}");
|
410
|
+
}
|
411
|
+
EOF
|
412
|
+
end
|
413
|
+
|
414
|
+
def copy_scalar_param_to_ruby(param, ruby_param)
|
415
|
+
if param.scalar_output? then
|
416
|
+
get_output.print <<EOF
|
417
|
+
mppa_read(_mppa_fd_var, &#{param}, sizeof(#{param}));
|
418
|
+
EOF
|
419
|
+
case param.type
|
420
|
+
when Int
|
421
|
+
get_output.puts " rb_hash_aset(_boast_refs, ID2SYM(rb_intern(\"#{param}\")),rb_int_new((long long)#{param}));" if param.type.signed?
|
422
|
+
get_output.puts " rb_hash_aset(_boast_refs, ID2SYM(rb_intern(\"#{param}\")),rb_int_new((unsigned long long)#{param}));" if not param.type.signed?
|
423
|
+
when Real
|
424
|
+
get_output.puts " rb_hash_aset(_boast_refs, ID2SYM(rb_intern(\"#{param}\")),rb_float_new((double)#{param}));"
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
def get_results
|
430
|
+
get_output.print <<EOF
|
431
|
+
_mppa_fd_var = mppa_open(\"/mppa/buffer/host#4/board0#mppa0#pcie0#4\", O_RDONLY);
|
432
|
+
EOF
|
433
|
+
get_results_old
|
434
|
+
get_output.puts "mppa_read(_mppa_fd_var, &#{_boast_ret}, sizeof(#{_boast_ret}));" if @procedure.properties[:return]
|
435
|
+
get_output.print <<EOF
|
436
|
+
mppa_close(_mppa_fd_var);
|
437
|
+
mppa_waitpid(_mppa_pid, NULL, 0);
|
438
|
+
mppa_mon_measure_stop(_mppa_ctx, &_mppa_report);
|
439
|
+
mppa_unload(_mppa_load_id);
|
440
|
+
_mppa_avg_pwr = 0;
|
441
|
+
_mppa_energy = 0;
|
442
|
+
for(_mppa_i=0; _mppa_i < _mppa_report->count; _mppa_i++){
|
443
|
+
_mppa_avg_pwr += _mppa_report->measures[_mppa_i].avg_power;
|
444
|
+
_mppa_energy += _mppa_report->measures[_mppa_i].total_energy;
|
445
|
+
}
|
446
|
+
_mppa_avg_pwr = _mppa_avg_pwr/(float) _mppa_report->count;
|
447
|
+
_mppa_duration = _mppa_report->total_time;
|
448
|
+
mppa_mon_measure_free_report(_mppa_report);
|
449
|
+
mppa_mon_close(_mppa_ctx);
|
450
|
+
EOF
|
451
|
+
end
|
452
|
+
|
453
|
+
def store_results
|
454
|
+
store_results_old
|
455
|
+
get_output.print <<EOF
|
456
|
+
rb_hash_aset(_boast_stats,ID2SYM(rb_intern("mppa_avg_pwr")),rb_float_new(_mppa_avg_pwr));
|
457
|
+
rb_hash_aset(_boast_stats,ID2SYM(rb_intern("mppa_energy")),rb_float_new(_mppa_energy));
|
458
|
+
rb_hash_aset(_boast_stats,ID2SYM(rb_intern("mppa_duration")), rb_float_new(_mppa_duration));
|
459
|
+
EOF
|
460
|
+
end
|
461
|
+
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|