Accelerated Computation Engine
Classes | Public Member Functions | Protected Member Functions | List of all members
OpenCL::Kernel Class Reference

#include <opencl_kernel.h>

Inheritance diagram for OpenCL::Kernel:

Classes

class  Locker
 

Public Member Functions

virtual ~Kernel () override
 
Event execute (CommandQueue *queue)
 

Protected Member Functions

 Kernel (Program *program, const QString &name, QObject *parent=nullptr)
 
Kernel::Locker lock ()
 
void unlock ()
 
int maxWorkGroupSize (Device *device) const
 
int workGroupMultiple (Device *device) const
 
void setDimensions (cl_uint size)
 
void setSizes (cl_uint dimension, qint64 globalSize, qint64 localSize)
 
template<class T >
void setArgument (cl_uint index, T value)
 
template<class T >
void setBuffer (cl_uint index, Buffer< T > *buffer)
 
template<class T >
void setLocalMemory (cl_uint index, qint64 size)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~Kernel()

Kernel::~Kernel ( )
overridevirtual

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
programPointer to the program which has built the kernel with the given name that is created.
nameThe name of the kernel that is created.
parentOptional parent for this new kernel object.

Member Function Documentation

◆ execute()

Event Kernel::execute ( CommandQueue queue)

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
queue
Returns
The event for the kernel command running on the given command queue.

◆ lock()

Kernel::Locker Kernel::lock ( )
protected

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
device
Returns
Maximum work group size this kernel can possess for the given device.

◆ setArgument()

template<class T >
void OpenCL::Kernel::setArgument ( cl_uint  index,
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
TThe type of the value that is set.
Parameters
indexThe kernel argument index whose value is set.
valueThe 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
TThe buffer type that is set.
Parameters
indexThe kernel argument index whose value is set.
bufferThe 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
sizeThe 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
TThe element type whose given size in elements is allocated.
Parameters
indexThe kernel argument index whose value is set.
sizeThe 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
dimensionThe dimension whose global and local sizes are set.
globalSizeThe new global size that is set. This must be a multiple of the local size.
localSizeThe new local or work group size that is set. This must be divisible of the global size.

◆ unlock()

void Kernel::unlock ( )
protected

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
device
Returns
Work group multiple for the given device.

The documentation for this class was generated from the following files: