Class: Yadriggy::C::Program
- Inherits:
-
Object
- Object
- Yadriggy::C::Program
- 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
-
.compile(module_name = nil, lib_name = nil, dir: Config::WorkDir) ⇒ Module
Compiles this class and makes a module including the compiled methods.
-
.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.
Instance Method Summary collapse
-
#current_time ⇒ Time
Gets the current time in micro sec.
-
#exp(f) ⇒ Object
Exponential function.
-
#expf(f) ⇒ Object
Exponential function with single precision.
-
#log(f) ⇒ Object
Logarithm function.
-
#logf(f) ⇒ Object
Logarithm function with single precision.
-
#printf(s) ⇒ Object
Prints arguments.
-
#sqrt(f) ⇒ Object
Square root function.
-
#sqrtf(f) ⇒ Object
Square root function with single precision.
Methods included from CType
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.
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.
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_time ⇒ Time
Gets the current time in micro sec.
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 |