Module: BOAST::MPPARuntime

Includes:
CRuntime
Defined in:
lib/BOAST/Runtime/MPPARuntime.rb

Instance Attribute Summary collapse

Attributes included from CompiledRuntime

#binary, #source

Instance Method Summary collapse

Methods included from CompiledRuntime

#build, #dump_binary, #dump_executable, #dump_module, #dump_source, #maqao_analysis, #reload_module

Instance Attribute Details

#binary_compObject

Returns the value of attribute binary_comp.



124
125
126
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 124

def binary_comp
  @binary_comp
end

#code_compObject

Returns the value of attribute code_comp.



122
123
124
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 122

def code_comp
  @code_comp
end

#multibinaryObject

Returns the value of attribute multibinary.



126
127
128
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 126

def multibinary
  @multibinary
end

#procedure_compObject

Returns the value of attribute procedure_comp.



123
124
125
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 123

def procedure_comp
  @procedure_comp
end

#source_compObject

Returns the value of attribute source_comp.



125
126
127
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 125

def source_comp
  @source_comp
end

Instance Method Details

#cleanup(kernel_files) ⇒ Object



70
71
72
73
74
75
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 70

def cleanup(kernel_files)
  cleanup_old(kernel_files)
  ([io_bin, comp_bin, io_object, comp_object]).each { |fn|
    File::unlink(fn)
  }
end

#cleanup_oldObject



63
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 63

alias cleanup_old cleanup

#comp_binObject



93
94
95
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 93

def comp_bin
  return "#{base_path}.bincomp"
end

#comp_objectObject



101
102
103
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 101

def comp_object
  return "#{base_path}.#{RbConfig::CONFIG["OBJEXT"]}comp"
end

#comp_sourceObject



109
110
111
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 109

def comp_source
  return "#{base_path}.ccomp"
end

#copy_array_param_from_host(param) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 169

def copy_array_param_from_host( param )
  get_output.print <<EOF
  mppa_read(_mppa_from_host_size, &_mppa_#{param}_size, sizeof(_mppa_#{param}_size));
  #{param} = malloc(_mppa_#{param}_size);
  mppa_read(_mppa_from_host_var, #{param}, _mppa_#{param}_size);
EOF
end

#copy_array_param_from_ruby(param, ruby_param) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 395

def copy_array_param_from_ruby( param, ruby_param )
  rb_ptr = Variable::new("_boast_rb_ptr", CustomType, :type_name => "VALUE")
  (rb_ptr === ruby_param).pr
  get_output.print <<EOF
  if ( IsNArray(_boast_rb_ptr) ) {
struct NARRAY *_boast_n_ary;
size_t _boast_array_size;
Data_Get_Struct(_boast_rb_ptr, struct NARRAY, _boast_n_ary);
_boast_array_size = _boast_n_ary->total * na_sizeof[_boast_n_ary->type];
mppa_write(_mppa_fd_size, &_boast_array_size, sizeof(_boast_array_size));
#{param} = (void *) _boast_n_ary->ptr;
mppa_write(_mppa_fd_var, #{param}, _boast_array_size);
  } else {
rb_raise(rb_eArgError, "Wrong type of argument for %s, expecting array!", "#{param}");
  }
EOF
end

#copy_array_param_to_host(param) ⇒ Object



192
193
194
195
196
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 192

def copy_array_param_to_host(param)
  get_output.print <<EOF
  mppa_write(_mppa_to_host_var, #{param}, _mppa_#{param}_size);
EOF
end

#copy_array_param_to_ruby(param, ruby_param) ⇒ Object



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 463

def copy_array_param_to_ruby(param, ruby_param)
  rb_ptr = Variable::new("_boast_rb_ptr", CustomType, :type_name => "VALUE")
  (rb_ptr === ruby_param).pr
  get_output.print <<EOF
  if ( IsNArray(_boast_rb_ptr) ) {
EOF
  if param.direction == :out or param.direction == :inout then
    get_output.print <<EOF
struct NARRAY *_boast_n_ary;
size_t _boast_array_size;
Data_Get_Struct(_boast_rb_ptr, struct NARRAY, _boast_n_ary);
_boast_array_size = _boast_n_ary->total * na_sizeof[_boast_n_ary->type];
mppa_read(_mppa_fd_var, #{param}, _boast_array_size);
EOF
  end
    get_output.print <<EOF
  } else {
rb_raise(rb_eArgError, "Wrong type of argument for %s, expecting array!", "#{param}");
  }
EOF
end

#copy_scalar_param_from_host(param) ⇒ Object



177
178
179
180
181
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 177

def copy_scalar_param_from_host( param )
  get_output.print  <<EOF
  mppa_read(_mppa_from_host_var, &#{param}, sizeof(#{param}));
EOF
end

#copy_scalar_param_from_ruby(param, ruby_param) ⇒ Object



413
414
415
416
417
418
419
420
421
422
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 413

def copy_scalar_param_from_ruby( param, ruby_param )
  case param.type
  when Int
    (param === FuncCall::new("NUM2INT", ruby_param)).pr if param.type.size == 4
    (param === FuncCall::new("NUM2LONG", ruby_param)).pr if param.type.size == 8
  when Real
    (param === FuncCall::new("NUM2DBL", ruby_param)).pr
  end
  get_output.puts "  mppa_write(_mppa_fd_var, &#{param}, sizeof(#{param}));"
end

#copy_scalar_param_to_host(param) ⇒ Object



198
199
200
201
202
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 198

def copy_scalar_param_to_host(param)
  get_output.print <<EOF
  mppa_write(_mppa_to_host_var, &#{param}, sizeof(#{param}));
EOF
end

#copy_scalar_param_to_ruby(param, ruby_param) ⇒ Object



485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 485

def copy_scalar_param_to_ruby(param, ruby_param)
  if param.scalar_output? then
    get_output.print <<EOF
  mppa_read(_mppa_fd_var, &#{param}, sizeof(#{param}));
EOF
    case param.type
    when Int
      get_output.puts "  rb_hash_aset(_boast_refs, ID2SYM(rb_intern(\"#{param}\")),rb_int_new((long long)#{param}));" if param.type.signed?
      get_output.puts "  rb_hash_aset(_boast_refs, ID2SYM(rb_intern(\"#{param}\")),rb_int_new((unsigned long long)#{param}));" if not param.type.signed?
    when Real
      get_output.puts "  rb_hash_aset(_boast_refs, ID2SYM(rb_intern(\"#{param}\")),rb_float_new((double)#{param}));"
    end
  end
end

#create_multibinary_source(mode) ⇒ Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 345

def create_multibinary_source(mode)
  f = File::open(self.send("#{mode}_source"),"w+")
  previous_lang = get_lang
  previous_output = get_output
  set_output(f)
  set_lang(@lang)

  fill_multibinary_source(mode)

  if debug_source? then
    f.rewind
    puts f.read
  end
  set_output(previous_output)
  set_lang(previous_lang)
  f.close
end

#create_multibinary_sourcesObject



363
364
365
366
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 363

def create_multibinary_sources
  create_multibinary_source(:io)
  create_multibinary_source(:comp)
end

#create_procedure_callObject



460
461
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 460

def create_procedure_call
end

#create_sourcesObject



368
369
370
371
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 368

def create_sources
  create_multibinary_sources
  create_module_file_source
end

#create_targets(linker, ldshared, ldflags, kernel_files) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 154

def create_targets( linker, ldshared, ldflags, kernel_files )
  create_targets_old( linker, ldshared, ldflags, kernel_files )
  file multibinary_path => [io_bin, comp_bin] do
    sh "k1-create-multibinary --clusters #{comp_bin} --clusters-names \"comp-part\" --boot #{io_bin} --bootname \"io-part\" -T #{multibinary_path}"
  end
  Rake::Task[multibinary_path].invoke
end

#create_targets_oldObject



62
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 62

alias create_targets_old create_targets

#fill_decl_module_paramsObject



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 378

def fill_decl_module_params
  fill_decl_module_params_old
  get_output.print <<EOF
  int _mppa_i;
  int _mppa_load_id;
  int _mppa_pid;
  int _mppa_fd_size;
  int _mppa_fd_var;
  int _mppa_clust_list_size;
  int _mppa_clust_nb;
  int64_t _boast_duration;
  uint32_t * _mppa_clust_list;
  _mppa_load_id = mppa_load(0, 0, 0, \"#{multibinary_path}\");
  _mppa_pid = mppa_spawn(_mppa_load_id, NULL, \"io-part\", NULL, NULL);
EOF
end

#fill_decl_module_params_oldObject



66
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 66

alias fill_decl_module_params_old fill_decl_module_params

#fill_module_headerObject



373
374
375
376
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 373

def fill_module_header
  fill_module_header_old
  get_output.puts "#include <mppaipc.h>"
end

#fill_module_header_oldObject



64
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 64

alias fill_module_header_old fill_module_header

#fill_multibinary_headerObject



162
163
164
165
166
167
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 162

def fill_multibinary_header
  fill_library_header
  get_output.puts "#include <mppaipc.h>"
  get_output.puts "#include <mppa/osconfig.h>"
  get_output.puts "#include <time.h>"
end

#fill_multibinary_main_comp_sourceObject



314
315
316
317
318
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 314

def fill_multibinary_main_comp_source
  if @procedure_comp then
    get_output.puts "    #{@procedure_comp.name}();"
  end
end

#fill_multibinary_main_io_sourceObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 283

def fill_multibinary_main_io_source
  multibinary_main_io_source_decl

  multibinary_main_io_source_get_params

  #Spawning cluster
  get_output.print <<EOF

  clock_gettime(CLOCK_REALTIME, &_mppa_start);
  for(_mppa_i=0; _mppa_i<_nb_clust; _mppa_i++){
_mppa_pid[_mppa_i] = mppa_spawn(_clust_list[_mppa_i], NULL, "comp-part", NULL, NULL);
  }
EOF
  #Calling IO procedure
  get_output.print "  _mppa_ret =" if @procedure.properties[:return]
  get_output.print "  #{@procedure.name}("
  get_output.print @procedure.parameters.map(&:name).join(", ")
  get_output.puts ");"

  #Waiting for clusters
  get_output.print <<EOF
  for(_mppa_i=0; _mppa_i<_nb_clust; _mppa_i++){
mppa_waitpid(_mppa_pid[_mppa_i], NULL, 0);
  }
  clock_gettime(CLOCK_REALTIME, &_mppa_stop);
  _mppa_duration = (int64_t)(_mppa_stop.tv_sec - _mppa_start.tv_sec) * 1000000000ll + _mppa_stop.tv_nsec - _mppa_start.tv_nsec;
EOF

  multibinary_main_io_source_send_results
end

#fill_multibinary_source(mode) ⇒ Object



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 320

def fill_multibinary_source(mode)
  fill_multibinary_header
  code = nil
  if mode == :io then
    code = @code
  else
    code = @code_comp
  end
  if code then
    code.rewind
    get_output.print code.read
  end
  get_output.puts "int main(int argc, const char* argv[]) {"
  if mode == :io then
    fill_multibinary_main_io_source
  else
    fill_multibinary_main_comp_source
  end
  get_output.print <<EOF
  mppa_exit(0);
  return 0;
}
EOF
end

#get_cluster_list_from_hostObject



183
184
185
186
187
188
189
190
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 183

def get_cluster_list_from_host
  get_output.print <<EOF
  mppa_read(_mppa_from_host_size, &_mppa_clust_list_size, sizeof(_mppa_clust_list_size));
  _clust_list = malloc(_mppa_clust_list_size);
  _nb_clust = _mppa_clust_list_size / sizeof(*_clust_list);
  mppa_read(_mppa_from_host_var, _clust_list, _mppa_clust_list_size);
EOF
end

#get_params_valueObject



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 424

def get_params_value
  get_output.print <<EOF
  _mppa_fd_size = mppa_open(\"/mppa/buffer/board0#mppa0#pcie0#2/host#2\", O_WRONLY);
  _mppa_fd_var = mppa_open(\"/mppa/buffer/board0#mppa0#pcie0#3/host#3\", O_WRONLY);
EOF
  get_params_value_old
  get_output.print <<EOF
  if(_boast_rb_opts != Qnil) {
_boast_rb_ptr = rb_hash_aref(_boast_rb_opts, ID2SYM(rb_intern("clusters")));
if (_boast_rb_ptr != Qnil ) {
  int _boast_i;
  _mppa_clust_nb = RARRAY_LEN(_boast_rb_ptr);
  _mppa_clust_list = malloc(sizeof(uint32_t)*_mppa_clust_nb);
  for(_boast_i=0; _boast_i < _mppa_clust_nb; _boast_i++){
    _mppa_clust_list[_boast_i] = NUM2INT(rb_ary_entry(_boast_rb_ptr, _boast_i));
  }
} else {
  _mppa_clust_list = malloc(sizeof(uint32_t));
  _mppa_clust_list[0] = 0;
  _mppa_clust_nb = 1;
}
  } else {
_mppa_clust_list = malloc(sizeof(uint32_t));
_mppa_clust_list[0] = 0;
_mppa_clust_nb = 1;
  }
  
  _mppa_clust_list_size = sizeof(uint32_t)*_mppa_clust_nb;
  mppa_write(_mppa_fd_size, &_mppa_clust_list_size, sizeof(_mppa_clust_list_size));
  mppa_write(_mppa_fd_var, _mppa_clust_list, _mppa_clust_list_size);
  free(_mppa_clust_list);
  mppa_close(_mppa_fd_var);
  mppa_close(_mppa_fd_size);
EOF
end

#get_params_value_oldObject



65
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 65

alias get_params_value_old get_params_value

#get_resultsObject



500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 500

def get_results
  get_output.print <<EOF
  _mppa_fd_var = mppa_open(\"/mppa/buffer/host#4/board0#mppa0#pcie0#4\", O_RDONLY);
EOF
  get_results_old
  get_output.puts "  mppa_read(_mppa_fd_var, &_boast_ret, sizeof(_boast_ret));" if @procedure.properties[:return]
  get_output.puts "  mppa_read(_mppa_fd_var, &_boast_duration, sizeof(_boast_duration));"
  get_output.print <<EOF
  mppa_close(_mppa_fd_var);
  mppa_waitpid(_mppa_pid, NULL, 0);
  mppa_unload(_mppa_load_id);
EOF
end

#get_results_oldObject



67
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 67

alias get_results_old get_results

#io_binObject



89
90
91
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 89

def io_bin
  return "#{base_path}.binio"
end

#io_objectObject



97
98
99
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 97

def io_object
  return "#{base_path}.#{RbConfig::CONFIG["OBJEXT"]}io"
end

#io_sourceObject



105
106
107
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 105

def io_source
  return "#{base_path}.cio"
end

#multibinary_main_io_source_declObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 204

def multibinary_main_io_source_decl
  #Parameters declaration
  @procedure.parameters.each { |param|
    get_output.print "  #{param.type.decl} "
    get_output.print "*" if param.dimension or param.scalar_output? or param.reference?
    get_output.puts "#{param.name};"
    if param.dimension then
      get_output.puts "  size_t _mppa_#{param}_size;"
    end
  }

  #Return value declaration
  get_output.puts "  #{@procedure.properties[:return].type.decl} _mppa_ret;" if @procedure.properties[:return]

  #Cluster list declaration
  get_output.print <<EOF
  uint32_t *_clust_list;
  int _nb_clust;
  int _mppa_clust_list_size;
EOF

  #Timer
  get_output.print <<EOF
  struct timespec _mppa_start, _mppa_stop;
  int64_t _mppa_duration;
EOF

  #Communication variables
  get_output.print <<EOF
  int _mppa_from_host_size, _mppa_from_host_var;
  int _mppa_to_host_size,   _mppa_to_host_var;
  int _mppa_pid[16], _mppa_i;
EOF
end

#multibinary_main_io_source_get_paramsObject



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 239

def multibinary_main_io_source_get_params
  #Receiving parameters from Host
  get_output.print <<EOF
  _mppa_from_host_size = mppa_open("/mppa/buffer/board0#mppa0#pcie0#2/host#2", O_RDONLY);
  _mppa_from_host_var = mppa_open("/mppa/buffer/board0#mppa0#pcie0#3/host#3", O_RDONLY);
EOF
  @procedure.parameters.each { |param|
    if param.dimension then
      copy_array_param_from_host(param)
    else
      copy_scalar_param_from_host(param)
    end
  }

  #Receiving cluster list
  get_cluster_list_from_host

  get_output.print <<EOF
  mppa_close(_mppa_from_host_size);
  mppa_close(_mppa_from_host_var);
EOF
end

#multibinary_main_io_source_send_resultsObject



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 262

def multibinary_main_io_source_send_results
  #Sending results to Host
  get_output.print <<EOF
  _mppa_to_host_var = mppa_open("/mppa/buffer/host#4/board0#mppa0#pcie0#4", O_WRONLY);
EOF
  @procedure.parameters.each { |param| 
    if param.direction == :out or param.direction == :inout then
      if param.dimension then
        copy_array_param_to_host(param)
      else
        copy_scalar_param_to_host(param)
      end
    end
  }
  copy_scalar_param_to_host("_mppa_ret") if @procedure.properties[:return]
  copy_scalar_param_to_host("_mppa_duration")
  get_output.print <<EOF
  mppa_close(_mppa_to_host_var);
EOF
end

#multibinary_pathObject



85
86
87
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 85

def multibinary_path
  return "#{base_path}.mpk"
end

#save_binaryObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 139

def save_binary
  f = File::open(io_object,"rb")
  @binary = StringIO::new
  @binary.write( f.read )
  f.close
  f = File::open(comp_object,"rb")
  @binary_comp = StringIO::new
  @binary_comp.write( f.read )
  f.close
  f = File::open(multibinary_path,"rb")
  @multibinary = StringIO::new
  @multibinary.write( f.read )
  f.close
end

#save_sourceObject



128
129
130
131
132
133
134
135
136
137
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 128

def save_source
  f = File::open(io_source, "r")
  @source = StringIO::new
  @source.write( f.read )
  f.close
  f = File::open(comp_source, "r")
  @source_comp = StringIO::new
  @source_comp.write( f.read )
  f.close
end

#set_compObject



117
118
119
120
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 117

def set_comp
  @code_comp = StringIO::new unless @code_comp
  set_output(@code_comp)
end

#set_ioObject



113
114
115
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 113

def set_io
  set_output(@code_io)
end

#store_resultsObject



514
515
516
517
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 514

def store_results
  store_results_old
  get_output.print "  rb_hash_aset(_boast_stats,ID2SYM(rb_intern(\"duration\")),rb_float_new((double)_boast_duration*(double)1e-9));\n"
end

#store_results_oldObject



68
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 68

alias store_results_old store_results

#target_dependsObject



77
78
79
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 77

def target_depends
  return [ module_file_object ]
end

#target_sourcesObject



81
82
83
# File 'lib/BOAST/Runtime/MPPARuntime.rb', line 81

def target_sources
  return [ module_file_source, io_source, comp_source ]
end