Class: OpenCL::Kernel
- Inherits:
-
ExtendedStruct
- Object
- ManagedStruct
- ExtendedStruct
- OpenCL::Kernel
- Includes:
- KHRSubGroups, OpenCL11, OpenCL12, OpenCL20, OpenCL21
- 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,
lib/opencl_ruby_ffi/khr/sub_groups.rb
Overview
Maps the cl_kernel object
Defined Under Namespace
Modules: KHRSubGroups, OpenCL11, OpenCL12, OpenCL20, OpenCL21 Classes: Arg
Constant Summary collapse
- FUNCTION_NAME =
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
- MAX_SUB_GROUP_SIZE_FOR_NDRANGE =
0x2033
- SUB_GROUP_COUNT_FOR_NDRANGE =
0x2034
- LOCAL_SIZE_FOR_SUB_GROUP_COUNT =
0x11B8
- MAX_NUM_SUB_GROUPS =
0x11B9
- COMPILE_NUM_SUB_GROUPS =
0x11BA
- EXEC_INFO_SVM_PTRS =
0x11B6
- EXEC_INFO_SVM_FINE_GRAIN_SYSTEM =
0x11B7
- MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR =
0x2033
- SUB_GROUP_COUNT_FOR_NDRANGE_KHR =
0x2034
Instance Method Summary collapse
-
#args ⇒ Object
Returns an Array of Arg corresponding to the arguments of the Kernel.
- #compile_work_group_size(device = program.devices.first) ⇒ Object
-
#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.
-
#function_name ⇒ Object
(also: #name)
Returns the OpenCL::Kernel::function_name info.
-
#initialize(ptr, retain = true) ⇒ Kernel
constructor
Creates a new Kernel and retains it if specified and aplicable.
- #inspect ⇒ Object
- #local_mem_size(device = program.devices.first) ⇒ Object
-
#num_args ⇒ Object
Returns the OpenCL::Kernel::num_args info.
-
#program ⇒ Object
Returns the Program the Kernel was created from.
-
#reference_count ⇒ Object
Returns the OpenCL::Kernel::reference_count info.
-
#set_arg(index, value, size = nil) ⇒ Object
Set the index th argument of the Kernel to value.
-
#set_args(*args) ⇒ Object
Set the arguments of the kernel, arguments can be a scalar or an [ arg, size ] duplet.
- #work_group_size(device = program.devices.first) ⇒ Object
Methods included from KHRSubGroups
#max_sub_group_size_for_ndrange_khr, #sub_groups_count_for_ndrange_khr
Methods included from OpenCL21
#clone, #compile_num_sub_groups, #local_size_for_sub_group_count, #max_num_sub_groups, #max_sub_group_size_for_ndrange, #sub_groups_count_for_ndrange
Methods included from OpenCL20
#set_arg_svm_pointer, #set_svm_fine_grain_system, #set_svm_ptrs
Methods included from OpenCL12
#attributes, #global_work_size
Methods included from OpenCL11
#preferred_work_group_size_multiple, #private_mem_size
Methods inherited from ExtendedStruct
Constructor Details
#initialize(ptr, retain = true) ⇒ Kernel
Creates a new Kernel and retains it if specified and aplicable
1398 1399 1400 1401 1402 |
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1398 def initialize(ptr, retain = true) super(ptr) OpenCL.clRetainKernel(ptr) if retain #STDERR.puts "Allocating Kernel: #{ptr}" end |
Instance Method Details
#args ⇒ Object
Returns an Array of Arg corresponding to the arguments of the Kernel
168 169 170 171 172 173 174 175 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 168 def args n = self.num_args a = [] n.times { |i| a.push Arg::new(self, i) } return a end |
#compile_work_group_size(device = program.devices.first) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 207 def compile_work_group_size(device = program.devices.first) ptr = MemoryPointer::new( :size_t, 3 ) error = OpenCL.clGetKernelWorkGroupInfo(self, device, COMPILE_WORK_GROUP_SIZE, ptr.size, ptr, nil) error_check(error) return ptr.get_array_of_size_t(0,3) end |
#context ⇒ Object
Returns the Context the Kernel is associated with
185 186 187 188 189 190 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 185 def context ptr = 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, they can be scalar or [arg, size]. Last, a hash containing options for enqueu_ndrange kernel can be specified
234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 234 def enqueue_with_args(command_queue, global_work_size, *args) n = 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.pop else = {} end set_args(*args) command_queue.enqueue_ndrange_kernel(self, global_work_size, ) end |
#function_name ⇒ Object Also known as: name
Returns the OpenCL::Kernel::function_name info
177 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 177 get_info("Kernel", :string, "function_name") |
#inspect ⇒ Object
52 53 54 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 52 def inspect return "#<#{self.class.name}: #{name}>" end |
#local_mem_size(device = program.devices.first) ⇒ Object
214 215 216 217 218 219 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 214 def local_mem_size(device = program.devices.first) ptr = MemoryPointer::new( :cl_ulong ) error = OpenCL.clGetKernelWorkGroupInfo(self, device, LOCAL_MEM_SIZE, ptr.size, ptr, nil) error_check(error) return ptr.read_cl_ulong end |
#num_args ⇒ Object
Returns the OpenCL::Kernel::num_args info
181 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 181 get_info("Kernel", :cl_uint, "num_args") |
#program ⇒ Object
Returns the Program the Kernel was created from
193 194 195 196 197 198 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 193 def program ptr = MemoryPointer::new( Program ) error = OpenCL.clGetKernelInfo(self, PROGRAM, Program.size, ptr, nil) error_check(error) return Program::new(ptr.read_pointer) end |
#reference_count ⇒ Object
Returns the OpenCL::Kernel::reference_count info
182 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 182 get_info("Kernel", :cl_uint, "reference_count") |
#set_arg(index, value, size = nil) ⇒ Object
Set the index th argument of the Kernel to value. The size of value can be specified.
222 223 224 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 222 def set_arg(index, value, size = nil) OpenCL.set_kernel_arg(self, index, value, size) end |
#set_args(*args) ⇒ Object
Set the arguments of the kernel, arguments can be a scalar or an [ arg, size ] duplet.
227 228 229 230 231 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 227 def set_args(*args) num_args.times { |i| OpenCL.set_kernel_arg(self, i, *[args[i]].flatten ) } end |
#work_group_size(device = program.devices.first) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 200 def work_group_size(device = program.devices.first) ptr = MemoryPointer::new( :size_t ) error = OpenCL.clGetKernelWorkGroupInfo(self, device, WORK_GROUP_SIZE, ptr.size, ptr, nil) error_check(error) return ptr.read_size_t end |