Class: BOAST::CKernel
- Inherits:
-
Object
- Object
- BOAST::CKernel
- Includes:
- Compilers, Inspectable, PrivateStateAccessor, TypeTransition, Rake::DSL
- Defined in:
- lib/BOAST/Runtime/CKernel.rb,
lib/BOAST/Runtime/NonRegression.rb
Instance Attribute Summary collapse
-
#architecture ⇒ Object
Returns the value of attribute architecture.
-
#code ⇒ Object
Returns the value of attribute code.
-
#cost_function ⇒ Object
Returns the value of attribute cost_function.
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#kernels ⇒ Object
Returns the value of attribute kernels.
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#procedure ⇒ Object
Returns the value of attribute procedure.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
Builds the computing kernel.
- #compare_ref(ref_outputs, outputs, epsilon = nil) ⇒ Object
-
#cost(*args) ⇒ Object
If a cost function is provided returns the cost of running the function on the provided arguments.
- #dump_ref_inputs(values, path = ".", suffix = ".in") ⇒ Object
- #dump_ref_outputs(values, path = ".", suffix = ".out") ⇒ Object
-
#initialize(options = {}) ⇒ CKernel
constructor
Creates a new CKernel object.
- #load_ref_inputs(path = ".", suffix = ".in") ⇒ Object
- #load_ref_outputs(path = ".", suffix = ".out") ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
- #print ⇒ Object deprecated Deprecated.
-
#run(*args, options = {}) ⇒ Hash
Runs the computing kernel using the given arguments.
-
#to_s ⇒ String
Source code of the kernel.
Methods included from TypeTransition
#get_transition, #set_transition, #transition
Methods included from PrivateStateAccessor
#address_size, #address_size=, #annotate, #annotate=, #annotate?, #annotate_indepth_list, #annotate_indepth_list=, #annotate_level, #annotate_level=, #annotate_list, #annotate_list=, #array_start, #array_start=, #chain_code, #chain_code=, #chain_code?, #debug, #debug=, #debug?, #debug_kernel_source, #debug_kernel_source=, #debug_kernel_source?, #debug_source, #debug_source=, #debug_source?, #decl_module, #decl_module=, #decl_module?, #default_align, #default_align=, #default_int_signed, #default_int_signed=, #default_int_signed?, #default_int_size, #default_int_size=, #default_real_size, #default_real_size=, #default_type, #default_type=, #disable_openmp, #disable_openmp=, #disable_openmp?, #executable, #executable=, #executable?, #ffi, #ffi=, #ffi?, #fortran_line_length, #fortran_line_length=, #get_address_size, #get_annotate, #get_annotate_indepth_list, #get_annotate_level, #get_annotate_list, #get_architecture, #get_array_start, #get_chain_code, #get_debug, #get_debug_kernel_source, #get_debug_source, #get_decl_module, #get_default_align, #get_default_int_signed, #get_default_int_size, #get_default_real_size, #get_default_type, #get_disable_openmp, #get_executable, #get_ffi, #get_fortran_line_length, #get_indent_increment, #get_indent_level, #get_keep_temp, #get_lang, #get_model, #get_optimizer_log, #get_optimizer_log_file, #get_output, #get_replace_constants, #get_use_vla, #get_verbose, #indent_increment, #indent_increment=, #indent_level, #indent_level=, #keep_temp, #keep_temp=, #keep_temp?, #model, #model=, #optimizer_log, #optimizer_log=, #optimizer_log?, #optimizer_log_file, #optimizer_log_file=, #output, #output=, private_boolean_state_accessor, private_state_accessor, #replace_constants, #replace_constants=, #replace_constants?, #set_address_size, #set_annotate, #set_annotate_indepth_list, #set_annotate_level, #set_annotate_list, #set_architecture, #set_array_start, #set_chain_code, #set_debug, #set_debug_kernel_source, #set_debug_source, #set_decl_module, #set_default_align, #set_default_int_signed, #set_default_int_size, #set_default_real_size, #set_default_type, #set_disable_openmp, #set_executable, #set_ffi, #set_fortran_line_length, #set_indent_increment, #set_indent_level, #set_keep_temp, #set_lang, #set_model, #set_optimizer_log, #set_optimizer_log_file, #set_output, #set_replace_constants, #set_use_vla, #set_verbose, #use_vla, #use_vla=, #use_vla?, #verbose, #verbose=, #verbose?
Methods included from Inspectable
Methods included from Compilers
#get_includes, #get_narray_path, #get_openmp_flags, #setup_c_compiler, #setup_compilers, #setup_cuda_compiler, #setup_cxx_compiler, #setup_fortran_compiler, #setup_linker, #setup_linker_mppa
Constructor Details
#initialize(options = {}) ⇒ CKernel
Creates a new CKernel object. BOAST output is redirected to the CKernel. If the chain_code state is set the current BOAST output, as returned by BOAST.get_output, is used.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 34 def initialize(={}) if [:code] then @code = [:code] elsif get_chain_code @code = get_output @code.seek(0,SEEK_END) else @code = StringIO::new end set_output(@code) if [:kernels] then @kernels = [:kernels] else @kernels = [] end if [:lang] then @lang = [:lang] else @lang = get_lang end if [:architecture] then @architecture = [:architecture] else @architecture = get_architecture end @includes = [] @includes = [[:includes]].flatten if [:includes] case @lang when CL extend OpenCLRuntime when CUDA extend CUDARuntime @probes = [] when FORTRAN extend FORTRANRuntime extend FFIRuntime if ffi? else if @architecture == MPPA then extend MPPARuntime else extend CRuntime extend FFIRuntime if ffi? end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 98 def method_missing(meth, *args, &block) if meth.to_s == "run" then build run(*args, &block) else super end end |
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture.
23 24 25 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 23 def architecture @architecture end |
#code ⇒ Object
Returns the value of attribute code.
20 21 22 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 20 def code @code end |
#cost_function ⇒ Object
Returns the value of attribute cost_function.
25 26 27 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 25 def cost_function @cost_function end |
#includes ⇒ Object
Returns the value of attribute includes.
26 27 28 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 26 def includes @includes end |
#kernels ⇒ Object
Returns the value of attribute kernels.
24 25 26 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 24 def kernels @kernels end |
#lang ⇒ Object
Returns the value of attribute lang.
22 23 24 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 22 def lang @lang end |
#procedure ⇒ Object
Returns the value of attribute procedure.
21 22 23 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 21 def procedure @procedure end |
Instance Method Details
#build(options = {}) ⇒ Object
Builds the computing kernel.
|
|
# File 'lib/BOAST/Runtime/CKernel.rb', line 112
|
#compare_ref(ref_outputs, outputs, epsilon = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/BOAST/Runtime/NonRegression.rb', line 21 def compare_ref(ref_outputs, outputs, epsilon = nil) res = {} @procedure.parameters.each_with_index { |param, indx| if param.direction == :in or param.constant then next end if param.dimension then diff = (outputs[indx] - ref_outputs[indx]).abs if epsilon then diff.each { |elem| raise "Error: #{param.name} different from ref by: #{elem}!" if elem > epsilon } end res[param.name] = diff.max else raise "Error: #{param.name} different from ref: #{outputs[indx]} != #{ref_outputs[indx]} !" if epsilon and (outputs[indx] - ref_outputs[indx]).abs > epsilon res[param.name] = (outputs[indx] - ref_outputs[indx]).abs end } return res end |
#cost(*args) ⇒ Object
If a cost function is provided returns the cost of running the function on the provided arguments.
108 109 110 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 108 def cost(*args) @cost_function.call(*args) end |
#dump_ref_inputs(values, path = ".", suffix = ".in") ⇒ Object
13 14 15 |
# File 'lib/BOAST/Runtime/NonRegression.rb', line 13 def dump_ref_inputs(values, path = ".", suffix = ".in" ) return dump_ref_files(values, path, suffix, :in ) end |
#dump_ref_outputs(values, path = ".", suffix = ".out") ⇒ Object
17 18 19 |
# File 'lib/BOAST/Runtime/NonRegression.rb', line 17 def dump_ref_outputs(values, path = ".", suffix = ".out" ) return dump_ref_files(values, path, suffix, :out ) end |
#load_ref_inputs(path = ".", suffix = ".in") ⇒ Object
5 6 7 |
# File 'lib/BOAST/Runtime/NonRegression.rb', line 5 def load_ref_inputs(path = ".", suffix = ".in" ) return load_ref_files( path, suffix, :in ) end |
#load_ref_outputs(path = ".", suffix = ".out") ⇒ Object
9 10 11 |
# File 'lib/BOAST/Runtime/NonRegression.rb', line 9 def load_ref_outputs(path = ".", suffix = ".out" ) return load_ref_files( path, suffix, :out ) end |
#print ⇒ Object
82 83 84 85 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 82 def print @code.rewind puts @code.read end |
#run(*args, options = {}) ⇒ Hash
Runs the computing kernel using the given arguments.
|
|
# File 'lib/BOAST/Runtime/CKernel.rb', line 133
|
#to_s ⇒ String
Returns source code of the kernel.
88 89 90 91 92 93 94 95 |
# File 'lib/BOAST/Runtime/CKernel.rb', line 88 def to_s if @lang == FORTRAN then return line_limited_source else @code.rewind return code.read end end |