class Yadriggy::C::Program
Public Class Methods
Compiles this class and makes a module including the compiled methods.
@param [String] module_name 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`.
@param [String] lib_name the name of the generated library. @param [String] dir the directory name where generated files
are stored.
@return [Module] the module where methods are attached.
Note that the name of this module is nil. It is not `method_name`.
# 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
Compiles this class and makes a module including the compiled OpenCL methods.
@param [String] module_name a module name. @param [String] lib_name the name of the generated library. @param [String] dir the directory name where generated files
are stored. The default value is `.`.
@param [Array<Object>] args an array of the arguments to the
`initialize` method. The default value is `nil` (no arguments).
@return [Module] the module where methods are attached.
# 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
Public Instance Methods
Gets the current time in micro sec. @return [Time] the current time. In C
, an integer is returned.
# 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
Exponential function.
# File lib/yadriggy/c/program.rb, line 67 def exp(f) typedecl f: Float, foreign: Float Math.exp(f) end
Exponential function with single precision.
# File lib/yadriggy/c/program.rb, line 61 def expf(f) typedecl f: Float, foreign: Float Math.exp(f) end
Logarithm function.
# File lib/yadriggy/c/program.rb, line 79 def log(f) typedecl f: Float, foreign: Float Math.log(f) end
Logarithm function with single precision.
# File lib/yadriggy/c/program.rb, line 73 def logf(f) typedecl f: Float, foreign: Float Math.log(f) end
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.
# File lib/yadriggy/c/program.rb, line 34 def printf(s) ! Void typedecl s: String, foreign: Void puts s end
Square root function.
# File lib/yadriggy/c/program.rb, line 55 def sqrt(f) typedecl f: Float, foreign: Float Math.sqrt(f) end
Square root function with single precision.
# File lib/yadriggy/c/program.rb, line 49 def sqrtf(f) typedecl f: Float, foreign: Float Math.sqrt(f) end