#include <opencl_kernel.h>
This contains an OpenCL kernel. This class is designed to be inherited and implemented by specific kernel implementations. This design works to facilitate separating the more arduous task of setting of a kernel to execute. This way arguments for a kernel can be abstracted to C++ with easy to understand arguments for methods. Because of this design most methods to set the kernel arguments and work sizes is protected and should only be used by a child inheriting this class. Setting kernel parameters is also the only part of OpenCL which is not thread safe. Because of this setting parameters is protected behind a mutex and parameters can only be set by a thread when it has locked that mutex.
◆ ~Kernel()
Clears all resources this kernel contains.
◆ Kernel()
Kernel::Kernel |
( |
Program * |
program, |
|
|
const QString & |
name, |
|
|
QObject * |
parent = nullptr |
|
) |
| |
|
explicitprotected |
Constructs a new kernel object from the given program with the given kernel name and optional parent.
- Parameters
-
program | Pointer to the program which has built the kernel with the given name that is created. |
name | The name of the kernel that is created. |
parent | Optional parent for this new kernel object. |
◆ execute()
Executes this object's OpenCL kernel on the given command queue with the dimensions, global, and local sizes this object possesses, returning the event for the kernel command.
- Parameters
-
- Returns
- The event for the kernel command running on the given command queue.
◆ lock()
Locks this kernel object allowing the setting of this object's kernel parameters and returning a locker object that unlocks this kernel on its destruction.
- Returns
- Locker object that unlocks this kernel upon its destruction.
◆ maxWorkGroupSize()
int Kernel::maxWorkGroupSize |
( |
Device * |
device | ) |
const |
|
protected |
Returns the maximum work group (local) size this kernel can possess for the given device. If this kernel is not locked then an exception is thrown.
- Parameters
-
- Returns
- Maximum work group size this kernel can possess for the given device.
◆ setArgument()
template<class T >
void OpenCL::Kernel::setArgument |
( |
cl_uint |
index, |
|
|
T |
value |
|
) |
| |
|
protected |
Sets this kernel's argument at the given index to the given value. The first argument of a kernel function is at index 0 and increments positively. If this kernel is not locked then an exception is thrown.
- Template Parameters
-
T | The type of the value that is set. |
- Parameters
-
index | The kernel argument index whose value is set. |
value | The value that the given kernel argument is set to. |
◆ setBuffer()
template<class T >
void OpenCL::Kernel::setBuffer |
( |
cl_uint |
index, |
|
|
Buffer< T > * |
buffer |
|
) |
| |
|
protected |
Sets this kernel's argument at the given index to the given OpenCL buffer. The first argument of a kernel function is at index 0 and increments positively. If this kernel is not locked then an exception is thrown.
- Template Parameters
-
T | The buffer type that is set. |
- Parameters
-
index | The kernel argument index whose value is set. |
buffer | The buffer object that the given kernel argument is set to. |
◆ setDimensions()
void Kernel::setDimensions |
( |
cl_uint |
size | ) |
|
|
protected |
Sets the number of dimensions for parallel execution of this kernel object. If this kernel is not locked or the given size is less than one then an exception is thrown.
- Parameters
-
size | The number of dimensions for this kernel. |
◆ setLocalMemory()
template<class T >
void OpenCL::Kernel::setLocalMemory |
( |
cl_uint |
index, |
|
|
qint64 |
size |
|
) |
| |
|
protected |
Sets this kernel's argument at the given index to local memory allocated to the given size in elements of template type. The first argument of a kernel function is at index 0 and increments positively. If this kernel is not locked or the given size is less than one then an exception is thrown.
- Template Parameters
-
T | The element type whose given size in elements is allocated. |
- Parameters
-
index | The kernel argument index whose value is set. |
size | The number of elements of template type which is allocated in local memory. |
◆ setSizes()
void Kernel::setSizes |
( |
cl_uint |
dimension, |
|
|
qint64 |
globalSize, |
|
|
qint64 |
localSize |
|
) |
| |
|
protected |
Sets the global and local sizes of the given dimension used for parallel execution of this kernel object. If this kernel is not locked, the dimension is invalid, the local or group size is less than one, or the global size is not a multiple of the local size then an exception is thrown.
- Parameters
-
dimension | The dimension whose global and local sizes are set. |
globalSize | The new global size that is set. This must be a multiple of the local size. |
localSize | The new local or work group size that is set. This must be divisible of the global size. |
◆ unlock()
Unlocks this kernel object after which parameters cannot be set and allows other threads to lock it.
◆ workGroupMultiple()
int Kernel::workGroupMultiple |
( |
Device * |
device | ) |
const |
|
protected |
Returns the recommended, for efficiency, work group multiple for the given device. If this kernel is not locked then an exception is thrown.
- Parameters
-
- Returns
- Work group multiple for the given device.
The documentation for this class was generated from the following files: