Class: OpenCL::Kernel

Inherits:
ExtendedStruct show all
Includes:
KHRSubGroups, KernelProfilingINTEL, OpenCL11, OpenCL12, OpenCL20, OpenCL21, UnifiedSharedMemoryPreviewINTEL
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,
lib/opencl_ruby_ffi/intel/unofficial.rb,
lib/opencl_ruby_ffi/intel/kernel_profiling.rb,
lib/opencl_ruby_ffi/intel/unified_shared_memory_preview.rb,
lib/opencl_ruby_ffi/intel/unified_shared_memory_preview.rb

Overview

Maps the cl_kernel object

Defined Under Namespace

Modules: KHRSubGroups, KernelProfilingINTEL, OpenCL11, OpenCL12, OpenCL20, OpenCL21, UnifiedSharedMemoryPreviewINTEL Classes: Arg

Instance Method Summary collapse

Methods included from UnifiedSharedMemoryPreviewINTEL

#clSetKernelArgMemPointerINTEL, #set_arg_mem_pointer_intel, #set_indirect_device_access_intel, #set_indirect_host_access_intel, #set_shared_device_access_intel, #set_usm_ptrs_intel

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

register_extension

Constructor Details

#initialize(ptr, retain = true) ⇒ Kernel

Creates a new Kernel and retains it if specified and aplicable



1467
1468
1469
1470
1471
# File 'lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb', line 1467

def initialize(ptr, retain = true)
  super(ptr)
  OpenCL.clRetainKernel(ptr) if retain
  #STDERR.puts "Allocating Kernel: #{ptr}"
end

Instance Method Details

#argsObject

Returns an Array of Arg corresponding to the arguments of the Kernel



187
188
189
190
191
192
193
194
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 187

def args
  n = self.num_args
  a = []
  n.times { |i|
    a.push Arg::new(self, i)
  }
  return a
end

#binaries_intelObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/opencl_ruby_ffi/intel/unofficial.rb', line 47

def binaries_intel
  sizes = self.binary_sizes_intel
  bin_array = MemoryPointer::new( :pointer, sizes.length )
  total_size = 0
  pointers = []
  sizes.each_with_index { |s, i|
    total_size += s
    pointers[i] = MemoryPointer::new(s)
    bin_array[i].write_pointer(pointers[i])
  }
  error = OpenCL.clGetKernelInfo(self, BINARIES_INTEL, total_size, bin_array, nil)
  error_check(error)
  bins = []
  devs = self.program.devices
  sizes.each_with_index { |s, i|
    bins.push [devs[i], pointers[i].read_bytes(s)]
  }
  return bins
end

#binary_program_intel(device = program.devices.first) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/opencl_ruby_ffi/intel/unofficial.rb', line 24

def binary_program_intel(device = program.devices.first)
  sz = MemoryPointer::new( :size_t )
  begin
    error = OpenCL.clGetKernelWorkGroupInfo(self, device, BINARY_PROGRAM_INTEL, 0, nil, sz)
    error_check(error)
    sz = sz.read_size_t
    bin = MemoryPointer::new(sz)
    error = OpenCL.clGetKernelWorkGroupInfo(self, device, BINARY_PROGRAM_INTEL, sz, bin, nil)
    error_check(error)
    return bin.read_bytes(sz)
  rescue
    error = OpenCL.clGetKernelInfo(self, BINARY_PROGRAM_INTEL, 0, nil, sz)
    error_check(error)
    sz = sz.read_size_t
    bin = MemoryPointer::new(sz)
    error = OpenCL.clGetKernelInfo(self, BINARY_PROGRAM_INTEL, sz, bin, nil)
    error_check(error)
    return bin.read_bytes(sz)
  end
end

#binary_sizes_intelObject

Returns the OpenCL::Kernel::binary_sizes_intel info

Returns:

  • an Array of size_t



45
# File 'lib/opencl_ruby_ffi/intel/unofficial.rb', line 45

get_info_array("Kernel", :size_t, "binary_sizes_intel")

#compile_work_group_size(device = program.devices.first) ⇒ Object



235
236
237
238
239
240
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 235

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

#contextObject

Returns the Context the Kernel is associated with



209
210
211
212
213
214
215
216
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 209

def context
  @_context ||= begin
    ptr = MemoryPointer::new( Context )
    error = OpenCL.clGetKernelInfo(self, CONTEXT, Context.size, ptr, nil)
    error_check(error)
    Context::new( ptr.read_pointer )
  end
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



262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 262

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
    options = args.pop
  else
    options = {}
  end
  set_args(*args)
  command_queue.enqueue_ndrange_kernel(self, global_work_size, options)
end

#function_nameObject Also known as: name

Returns the OpenCL::Kernel::function_name info

Returns:

  • string



196
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 196

get_info("Kernel", :string, "function_name", true)

#inspectObject



56
57
58
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 56

def inspect
  return "#<#{self.class.name}: #{name}>"
end

#local_mem_size(device = program.devices.first) ⇒ Object



242
243
244
245
246
247
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 242

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_argsObject

Returns the OpenCL::Kernel::num_args info

Returns:

  • cl_uint



200
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 200

get_info("Kernel", :cl_uint, "num_args", true)

#platformObject

Returns the Platform associated with the Kernel



204
205
206
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 204

def platform
  @_platform ||= self.context.platform
end

#programObject

Returns the Program the Kernel was created from



219
220
221
222
223
224
225
226
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 219

def program
  @_program ||= begin
    ptr = MemoryPointer::new( Program )
    error = OpenCL.clGetKernelInfo(self, PROGRAM, Program.size, ptr, nil)
    error_check(error)
    Program::new(ptr.read_pointer)
  end
end

#reference_countObject

Returns the OpenCL::Kernel::reference_count info

Returns:

  • cl_uint



201
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 201

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.



250
251
252
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 250

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.



255
256
257
258
259
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 255

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



228
229
230
231
232
233
# File 'lib/opencl_ruby_ffi/Kernel.rb', line 228

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

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
IL_SYMBOLS_INTEL =
0x407C
BINARY_PROGRAM_INTEL =
0x407D
BINARIES_INTEL =
0x4102
BINARY_SIZES_INTEL =
0x4103
EXEC_INFO_INDIRECT_HOST_ACCESS_INTEL =
0x4200
EXEC_INFO_INDIRECT_DEVICE_ACCESS_INTEL =
0x4201
EXEC_INFO_INDIRECT_SHARED_ACCESS_INTEL =
0x4202
EXEC_INFO_USM_PTRS_INTEL =
0x4203