Class: OpenCL::Kernel
- Inherits:
-
FFI::ManagedStruct
- Object
- FFI::ManagedStruct
- OpenCL::Kernel
- Defined in:
- lib/opencl_ruby_ffi/Kernel.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb,
lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb
Overview
Maps the cl_kernel object
Defined Under Namespace
Classes: Arg
Constant Summary collapse
- FUNCTION_NAME =
:stopdoc:
0x1190
- NUM_ARGS =
0x1191
- REFERENCE_COUNT =
0x1192
- CONTEXT =
0x1193
- PROGRAM =
0x1194
- ATTRIBUTES =
0x1195
- ARG_ADDRESS_QUALIFIER =
0x1196
- ARG_ACCESS_QUALIFIER =
0x1197
- ARG_TYPE_NAME =
0x1198
- ARG_TYPE_QUALIFIER =
0x1199
- ARG_NAME =
0x119A
- ARG_ADDRESS_GLOBAL =
0x119B
- ARG_ADDRESS_LOCAL =
0x119C
- ARG_ADDRESS_CONSTANT =
0x119D
- ARG_ADDRESS_PRIVATE =
0x119E
- ARG_ACCESS_READ_ONLY =
0x11A0
- ARG_ACCESS_WRITE_ONLY =
0x11A1
- ARG_ACCESS_READ_WRITE =
0x11A2
- ARG_ACCESS_NONE =
0x11A3
- ARG_TYPE_NONE =
0
- ARG_TYPE_CONST =
(1 << 0)
- ARG_TYPE_RESTRICT =
(1 << 1)
- ARG_TYPE_VOLATILE =
(1 << 2)
- ARG_TYPE_PIPE =
(1 << 3)
- WORK_GROUP_SIZE =
0x11B0
- COMPILE_WORK_GROUP_SIZE =
0x11B1
- LOCAL_MEM_SIZE =
0x11B2
- PREFERRED_WORK_GROUP_SIZE_MULTIPLE =
0x11B3
- PRIVATE_MEM_SIZE =
0x11B4
- GLOBAL_WORK_SIZE =
0x11B5
- EXEC_INFO_SVM_PTRS =
0x11B6
- EXEC_INFO_SVM_FINE_GRAIN_SYSTEM =
0x11B7
Class Method Summary collapse
-
.release(ptr) ⇒ Object
method called at Kernel deletion, releases the object if aplicable.
Instance Method Summary collapse
-
#args ⇒ Object
Returns an Array of Arg corresponding to the arguments of the Kernel.
-
#context ⇒ Object
Returns the Context the Kernel is associated with.
-
#enqueue_with_args(command_queue, global_work_size, *args) ⇒ Object
Enqueues the Kernel in the given queue, specifying the global_work_size.
-
#initialize(ptr, retain = true) ⇒ Kernel
constructor
Creates a new Kernel and retains it if specified and aplicable.
-
#program ⇒ Object
Returns the Program the Kernel was created from.
-
#prop ⇒ Object
:method: reference_count Returns the reference counter for the Kernel.
-
#set_arg(index, value, size = nil) ⇒ Object
Set the index th argument of the Kernel to value.
-
#set_arg_svm_pointer(index, svm_pointer) ⇒ Object
Set the index th argument of the Kernel to an svm pointer value.
-
#set_svm_fine_grain_system(flag) ⇒ Object
Specifies the granularity of the SVM system.
-
#set_svm_ptrs(ptrs) ⇒ Object
Specifies the list of SVM pointers the kernel will be using.
- #to_s ⇒ Object
Constructor Details
#initialize(ptr, retain = true) ⇒ Kernel
Creates a new Kernel and retains it if specified and aplicable
1449 1450 1451 1452 1453 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1449 def initialize(ptr, retain = true) super(ptr) OpenCL.clRetainKernel(ptr) if retain #STDERR.puts "Allocating Kernel: #{ptr}" end |
Class Method Details
.release(ptr) ⇒ Object
method called at Kernel deletion, releases the object if aplicable
1464 1465 1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1464 def self.release(ptr) #STDERR.puts "Releasing Kernel: #{ptr}" #ref_count = FFI::MemoryPointer::new( :cl_uint ) #OpenCL.clGetKernelInfo(ptr, OpenCL::Kernel::REFERENCE_COUNT, ref_count.size, ref_count, nil) #STDERR.puts "reference counter: #{ref_count.read_cl_uint}" error = OpenCL.clReleaseKernel(ptr) #STDERR.puts "Object released! #{error}" OpenCL.error_check( error ) end |
Instance Method Details
#args ⇒ Object
Returns an Array of Arg corresponding to the arguments of the Kernel
117 118 119 120 121 122 123 124 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 117 def args n = self.num_args a = [] n.times { |i| a.push OpenCL::Kernel::Arg::new(self, i) } return a end |
#context ⇒ Object
Returns the Context the Kernel is associated with
174 175 176 177 178 179 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 174 def context ptr = FFI::MemoryPointer::new( Context ) error = OpenCL.clGetKernelInfo(self, OpenCL::Kernel::CONTEXT, Context.size, ptr, nil) OpenCL.error_check(error) return OpenCL::Context::new( ptr.read_pointer ) end |
#enqueue_with_args(command_queue, global_work_size, *args) ⇒ Object
Enqueues the Kernel in the given queue, specifying the global_work_size. Arguments for the kernel are specified afterwards. Last, a hash containing options for enqueuNDrange kernel can be specified
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 200 def enqueue_with_args(command_queue, global_work_size, *args) n = self.num_args OpenCL.error_check(OpenCL::INVALID_KERNEL_ARGS) if args.length < n OpenCL.error_check(OpenCL::INVALID_KERNEL_ARGS) if args.length > n + 1 if args.length == n + 1 = args.last else = {} end n.times { |i| if args[i].class == OpenCL::SVMPointer and self.context.platform.version_number >= 2.0 then self.set_arg_svm_pointer(i, args[i]) else self.set_arg(i, args[i]) end } command_queue.enqueue_NDrange_kernel(self, global_work_size, ) end |
#program ⇒ Object
Returns the Program the Kernel was created from
182 183 184 185 186 187 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 182 def program ptr = FFI::MemoryPointer::new( Program ) error = OpenCL.clGetKernelInfo(self, OpenCL::Kernel::PROGRAM, Program.size, ptr, nil) OpenCL.error_check(error) return OpenCL::Program::new(ptr.read_pointer) end |
#prop ⇒ Object
:method: reference_count Returns the reference counter for the Kernel
156 157 158 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 156 %w( FUNCTION_NAME ATTRIBUTES ).each { |prop| eval OpenCL.get_info("Kernel", :string, prop) } |
#set_arg(index, value, size = nil) ⇒ Object
Set the index th argument of the Kernel to value. The size of value can be specified.
190 191 192 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 190 def set_arg(index, value, size = nil) OpenCL.set_kernel_arg(self, index, value, size) end |
#set_arg_svm_pointer(index, svm_pointer) ⇒ Object
Set the index th argument of the Kernel to an svm pointer value.
195 196 197 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 195 def set_arg_svm_pointer(index, svm_pointer) OpenCL.set_kernel_arg_svm_pointer(self, index, svm_pointer) end |
#set_svm_fine_grain_system(flag) ⇒ Object
Specifies the granularity of the SVM system.
140 141 142 143 144 145 146 147 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 140 def set_svm_fine_grain_system( flag ) OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.context.platform.version_number < 2.0 pt = FFI::MemoryPointer::new( :cl_bool ) pt.write_cl_bool( flag ) error = OpenCL.clSetKernelExecInfo( self, OpenCL::Kernel::EXEC_INFO_SVM_FINE_GRAIN_SYSTEL, pt.size, pt) OpenCL.error_check(error) return self end |
#set_svm_ptrs(ptrs) ⇒ Object
Specifies the list of SVM pointers the kernel will be using
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 127 def set_svm_ptrs( ptrs ) OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.context.platform.version_number < 2.0 pointers = [ptrs].flatten pt = FFI::MemoryPointer::new( :pointer, pointers.length ) pointers.each_with_index { |p, i| pt[i].write_pointer(p) } error = OpenCL.clSetKernelExecInfo( self, OpenCL::Kernel::EXEC_INFO_SVM_PTRS, pt.size, pt) OpenCL.error_check(error) return self end |
#to_s ⇒ Object
1455 1456 1457 1458 1459 1460 1461 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1455 def to_s if self.respond_to?(:name) then return self.name else return super end end |