Class: Yadriggy::C::Program

Inherits:
Object
  • Object
show all
Includes:
CType
Defined in:
lib/yadriggy/c/opencl.rb,
lib/yadriggy/c/program.rb

Constant Summary

Constants included from CType

CType::Float32Array, CType::FloatArray, CType::Int, CType::IntArray, CType::Void

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CType

#arrayof, #typedecl

Class Method Details

.compile(module_name = nil, lib_name = nil, dir: Config::WorkDir) ⇒ Module

Compiles this class and makes a module including the compiled methods.

Parameters:

  • module_name (String) (defaults to: nil)

    the name of the module where methods are attached. If it is not nil, a Ruby script is generated. When it is executed later, the methods are attached to the module with module_name. The name of the generated Ruby script is #{lib_name}.rb.

  • lib_name (String) (defaults to: nil)

    the name of the generated library.

  • dir (String) (defaults to: Config::WorkDir)

    the directory name where generated files are stored.

Returns:

  • (Module)

    the module where methods are attached. Note that the name of this module is nil. It is not method_name.



25
26
27
28
# File 'lib/yadriggy/c/program.rb', line 25

def self.compile(module_name=nil, lib_name=nil, dir: Config::WorkDir)
  obj = self.new
  Yadriggy::C.compile(obj, lib_name, dir, module_name)
end

.ocl_compile(module_name = nil, lib_name = nil, dir: Config::WorkDir, args: nil) ⇒ Module

Compiles this class and makes a module including the compiled OpenCL methods.

Parameters:

  • module_name (String) (defaults to: nil)

    a module name.

  • lib_name (String) (defaults to: nil)

    the name of the generated library.

  • dir (String) (defaults to: Config::WorkDir)

    the directory name where generated files are stored. The default value is ..

  • args (Array<Object>) (defaults to: nil)

    an array of the arguments to the initialize method. The default value is nil (no arguments).

Returns:

  • (Module)

    the module where methods are attached.



31
32
33
34
35
36
37
38
39
# File 'lib/yadriggy/c/opencl.rb', line 31

def self.ocl_compile(module_name=nil, lib_name=nil,
                     dir: Config::WorkDir, args: nil)
  if args.nil?
    obj = self.new
  else
    obj = self.new(*args)
  end
  Yadriggy::C.ocl_compile(obj, lib_name, dir, module_name)
end

Instance Method Details

#current_timeTime

Gets the current time in micro sec.

Returns:

  • (Time)

    the current time. In C, an integer is returned.



41
42
43
44
45
46
# File 'lib/yadriggy/c/program.rb', line 41

def current_time() ! Int
  typedecl native: "struct timespec time;\n\
clock_gettime(CLOCK_MONOTONIC, &time);\n\
return time.tv_sec * 1000000 + time.tv_nsec / 1000;"
  Time.now * 1000000
end

#exp(f) ⇒ Object

Exponential function.



67
68
69
70
# File 'lib/yadriggy/c/program.rb', line 67

def exp(f)
  typedecl f: Float, foreign: Float
  Math.exp(f)
end

#expf(f) ⇒ Object

Exponential function with single precision.



61
62
63
64
# File 'lib/yadriggy/c/program.rb', line 61

def expf(f)
  typedecl f: Float, foreign: Float
  Math.exp(f)
end

#log(f) ⇒ Object

Logarithm function.



79
80
81
82
# File 'lib/yadriggy/c/program.rb', line 79

def log(f)
  typedecl f: Float, foreign: Float
  Math.log(f)
end

#logf(f) ⇒ Object

Logarithm function with single precision.



73
74
75
76
# File 'lib/yadriggy/c/program.rb', line 73

def logf(f)
  typedecl f: Float, foreign: Float
  Math.log(f)
end

#printf(s) ⇒ Object

Prints arguments. This method is available from C code. It takes arguments as printf in C. For example, printf('value %d', 7) is a valid call. Note that the argument types are not checked.



34
35
36
37
# File 'lib/yadriggy/c/program.rb', line 34

def printf(s) ! Void
  typedecl s: String, foreign: Void
  puts s
end

#sqrt(f) ⇒ Object

Square root function.



55
56
57
58
# File 'lib/yadriggy/c/program.rb', line 55

def sqrt(f)
  typedecl f: Float, foreign: Float
  Math.sqrt(f)
end

#sqrtf(f) ⇒ Object

Square root function with single precision.



49
50
51
52
# File 'lib/yadriggy/c/program.rb', line 49

def sqrtf(f)
  typedecl f: Float, foreign: Float
  Math.sqrt(f)
end