Class: BOAST::CKernel

Inherits:
Object
  • Object
show all
Includes:
Compilers, Inspectable, PrivateStateAccessor, TypeTransition, Rake::DSL
Defined in:
lib/BOAST/Runtime/CKernel.rb,
lib/BOAST/Runtime/NonRegression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#inspect

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.

Parameters:

  • options (Hash) (defaults to: {})

    contains named options

Options Hash (options):

  • :code (StringIO)

    specify a StringIO to use rather than create a new one.

  • :kernels (Array)

    list of kernels this kernel depends on. The kernels will be linked at build time.

  • :lang (Integer)

    specify the language to use. Default is current language state as returned by BOAST.get_lang.

  • :architecture (Integer)

    specify the architecture to use. Default is the current BOAST architecture as returned by BOAST.get_architecture.



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(options={})
  if options[:code] then
    @code = options[:code]
  elsif get_chain_code
    @code = get_output
    @code.seek(0,SEEK_END)
  else
    @code = StringIO::new
  end
  set_output(@code)
  if options[:kernels] then
    @kernels = options[:kernels]
  else
    @kernels  = []
  end
  if options[:lang] then
    @lang = options[:lang]
  else
    @lang = get_lang
  end
  if options[:architecture] then
    @architecture = options[:architecture]
  else
    @architecture = get_architecture
  end
  @includes = []
  @includes = [options[:includes]].flatten if options[: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

#architectureObject

Returns the value of attribute architecture.



23
24
25
# File 'lib/BOAST/Runtime/CKernel.rb', line 23

def architecture
  @architecture
end

#codeObject

Returns the value of attribute code.



20
21
22
# File 'lib/BOAST/Runtime/CKernel.rb', line 20

def code
  @code
end

#cost_functionObject

Returns the value of attribute cost_function.



25
26
27
# File 'lib/BOAST/Runtime/CKernel.rb', line 25

def cost_function
  @cost_function
end

#includesObject

Returns the value of attribute includes.



26
27
28
# File 'lib/BOAST/Runtime/CKernel.rb', line 26

def includes
  @includes
end

#kernelsObject

Returns the value of attribute kernels.



24
25
26
# File 'lib/BOAST/Runtime/CKernel.rb', line 24

def kernels
  @kernels
end

#langObject

Returns the value of attribute lang.



22
23
24
# File 'lib/BOAST/Runtime/CKernel.rb', line 22

def lang
  @lang
end

#procedureObject

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.

Parameters:

  • options (Hash) (defaults to: {})

    contains build time options. Usual compiling flags are supported. Default values can be overriden in $XDG_CONFIG_HOME/.config/BOAST/compiler_options or $HOME/.config/BOAST/compiler_options. The same flags can be set as environment variables. Flags given here override environment variable ones.

Options Hash (options):

  • :CC (String)

    C compiler

  • :CFLAGS (String)

    C compiler flags

  • :FC (String)

    Fortran compiler

  • :FCFLAGS (String)

    Fortran compiler flags

  • :CXX (String)

    C++ compiler

  • :CXXFLAGS (String)

    C++ compiler flags

  • :LD (String)

    linker

  • :LDFLAGS (String)

    linker flags

  • :OPENMP (Boolean)

    activate OpenMP support. Correct flag should be set for your compiler in $XDG_CONFIG_HOME/.config/BOAST/openmp_flags or $HOME/.config/BOAST/openmp_flags.

  • :NVCC (String)

    cuda compiler

  • :NVCCFLAGS (String)

    cuda compiler flags

  • :CLFLAGS (String)

    opencl compiation flags

  • :CLVENDOR (String)

    restrict selected OpenCL platforms to the ones which vendor match the option

  • :CLPLATFORM (String)

    restrict selected OpenCL platforms to the ones which name match the option

  • :CLDEVICE (String)

    restrict selected OpenCL devices to the ones which mame match the option or use the provided OpenCL::Device

  • :CLCONTEXT (String)

    use the devices in the given OpenCL::Context

  • :CLDEVICETYPE (String)

    restrict selected OpenCL devices to the corresponding types



# 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
Deprecated.


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.

Parameters:

  • args

    the arguments corresponding to the list of parameters of the #procedure attribute

  • options (Hash) (defaults to: {})

    contains runtime options.

Options Hash (options):

  • :global_work_size (Array)

    only considered for CUDA and OpenCL kernels. See corresponding OpenCL documentation

  • :local_work_size (Array)

    only considered for CUDA and OpenCL kernels. See corresponding OpenCL documentation

  • :block_number (Array)

    only considered for CUDA and OpenCL kernels. See corresponding CUDA documentation

  • :block_size (Array)

    only considered for CUDA and OpenCL kernels. See corresponding CUDA documentation

  • :PAPI (Array)

    list of PAPI counters to monitor. ( ex: [‘PAPI_L1_DCM’, ‘PAPI_L2_DCM’], see PAPI documentation.

Returns:

  • (Hash)

    contains at least the :duration entry which is the runtime of the kernel in seconds. If the kernel is a function then the :return field will contain the returned value. For :inout or :out scalars the :reference_return field will be a Hash with each parameter name associated to the corresponding value. If :PAPI options was given will contain a :PAPI entry with the corresponding counters value.



# File 'lib/BOAST/Runtime/CKernel.rb', line 133

#to_sString

Returns source code of the kernel.

Returns:

  • (String)

    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