Class: SGC::Cuda::CudaFunction
- Inherits:
-
Object
- Object
- SGC::Cuda::CudaFunction
- Defined in:
- lib/cuda/runtime/function.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.configure(grid_dim, block_dim, shared_mem_size = 0, stream = 0) ⇒ Class
Configure the settings for the next kernel launch.
-
.load_lib(name) ⇒ Class
Load a dynamic library with name from dynamic library path.
-
.load_lib_file(path) ⇒ Class
Load a dynamic library from the given path.
-
.setup(*args) ⇒ Class
Set the argument list of subsequent kernel function launch.
-
.unload_all_libs ⇒ Class
Unload all the loaded dynamic libraries.
Instance Method Summary collapse
-
#attributes ⇒ CudaFunctionAttributes
The attributes of this kernel function.
-
#cache_config=(conf) ⇒ Object
Set the preferred cache configuration to use for next launch on this kernel function.
-
#initialize(name) ⇒ CudaFunction
constructor
Create an instance to function name.
-
#launch ⇒ Class
Launch this kernel function with pre-configured settings.
Constructor Details
#initialize(name) ⇒ CudaFunction
Create an instance to function name.
42 43 44 |
# File 'lib/cuda/runtime/function.rb', line 42 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/cuda/runtime/function.rb', line 38 def name @name end |
Class Method Details
.configure(grid_dim, block_dim, shared_mem_size = 0, stream = 0) ⇒ Class
Configure the settings for the next kernel launch.
82 83 84 85 86 87 88 89 90 |
# File 'lib/cuda/runtime/function.rb', line 82 def self.configure(grid_dim, block_dim, shared_mem_size = 0, stream = 0) s = Pvt::parse_stream(stream) status = API::cudaConfigureCall(grid_dim.to_api, block_dim.to_api, shared_mem_size, s) Pvt::handle_error(status, "Failed to configure kernel function launch settings.\n" + "* #{grid_dim.x} x #{grid_dim.y} x #{grid_dim.z} grid\n" + "* #{block_dim.x} x #{block_dim.y} x #{block_dim.z} blocks\n" + "* shared memory size = #{shared_mem_size}") self end |
.load_lib(name) ⇒ Class
Load a dynamic library with name from dynamic library path.
125 126 127 |
# File 'lib/cuda/runtime/function.rb', line 125 def self.load_lib(name) raise NotImplementedError end |
.load_lib_file(path) ⇒ Class
Load a dynamic library from the given path.
133 134 135 136 |
# File 'lib/cuda/runtime/function.rb', line 133 def self.load_lib_file(path) @@libs << DL::dlopen(path) self end |
.setup(*args) ⇒ Class
Set the argument list of subsequent kernel function launch.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cuda/runtime/function.rb', line 96 def self.setup(*args) offset = 0 args.each do |x| case x when Fixnum p = FFI::MemoryPointer.new(:int).write_int(x) size = 4 when Float p = FFI::MemoryPointer.new(:float).write_float(x) size = 4 when SGC::Memory::MemoryPointer p = x.ref size = FFI::TypeDefs[:pointer].size else raise TypeError, "Invalid type of kernel parameters #{x}." end offset = align_up(offset, size) status = API::cudaSetupArgument(p, size, offset) Pvt::handle_error(status, "Failed to setup kernel argument for #{x}.") offset += size end self end |
.unload_all_libs ⇒ Class
Unload all the loaded dynamic libraries.
141 142 143 144 145 146 147 |
# File 'lib/cuda/runtime/function.rb', line 141 def self.unload_all_libs @@libs.each do |h| h.close end @@libs = [] self end |
Instance Method Details
#attributes ⇒ CudaFunctionAttributes
Returns The attributes of this kernel function.
48 49 50 51 52 53 |
# File 'lib/cuda/runtime/function.rb', line 48 def attributes a = CudaFunctionAttributes.new status = API::cudaFuncGetAttributes(a.to_ptr, @name) Pvt::handle_error(status, "Failed to query function attributes.") a end |
#cache_config=(conf) ⇒ Object
Set the preferred cache configuration to use for next launch on this kernel function.
58 59 60 61 |
# File 'lib/cuda/runtime/function.rb', line 58 def cache_config=(conf) status = API::cudaFuncSetCacheConfig(@name, conf) Pvt::handle_error(status, "Failed to set function cache config: config = #{conf}.") end |
#launch ⇒ Class
Launch this kernel function with pre-configured settings.
68 69 70 71 72 |
# File 'lib/cuda/runtime/function.rb', line 68 def launch status = API::cudaLaunch(@name) Pvt::handle_error(status, "Failed to launch kernel function: name = #{@name}.") self end |