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
:startdoc:.
Constructor Details
#initialize(ptr, retain = true) ⇒ Kernel
Creates a new Kernel and retains it if specified and aplicable
3119 3120 3121 3122 3123 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 3119 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
3126 3127 3128 3129 3130 3131 3132 3133 3134 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 3126 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}" error_check( error ) end |
Instance Method Details
#args ⇒ Object
Returns an Array of Arg corresponding to the arguments of the Kernel
127 128 129 130 131 132 133 134 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 127 def args n = self.num_args a = [] n.times { |i| a.push Arg::new(self, i) } return a end |
#context ⇒ Object
Returns the Context the Kernel is associated with
184 185 186 187 188 189 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 184 def context ptr = FFI::MemoryPointer::new( Context ) error = OpenCL.clGetKernelInfo(self, CONTEXT, Context.size, ptr, nil) error_check(error) return 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
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 210 def enqueue_with_args(command_queue, global_work_size, *args) n = self.num_args error_check(INVALID_KERNEL_ARGS) if args.length < n error_check(INVALID_KERNEL_ARGS) if args.length > n + 1 if args.length == n + 1 = args.last else = {} end n.times { |i| if args[i].class == 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
192 193 194 195 196 197 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 192 def program ptr = FFI::MemoryPointer::new( Program ) error = OpenCL.clGetKernelInfo(self, PROGRAM, Program.size, ptr, nil) error_check(error) return Program::new(ptr.read_pointer) end |
#prop ⇒ Object
:method: reference_count Returns the reference counter for the Kernel
166 167 168 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 166 %w( FUNCTION_NAME ATTRIBUTES ).each { |prop| eval 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.
200 201 202 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 200 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.
205 206 207 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 205 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.
150 151 152 153 154 155 156 157 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 150 def set_svm_fine_grain_system( flag ) error_check(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, EXEC_INFO_SVM_FINE_GRAIN_SYSTEL, pt.size, pt) error_check(error) return self end |
#set_svm_ptrs(ptrs) ⇒ Object
Specifies the list of SVM pointers the kernel will be using
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 137 def set_svm_ptrs( ptrs ) error_check(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, EXEC_INFO_SVM_PTRS, pt.size, pt) error_check(error) return self end |
#to_s ⇒ Object
:startdoc:
3137 3138 3139 3140 3141 3142 3143 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 3137 def to_s if self.respond_to?(:name) then return self.name else return super end end |