C++ API Reference
MOpenCLKernelInfo Class Reference

Introduced in 2023.0 More...

#include <MOpenCLUtils.h>

Public Member Functions

 MOpenCLKernelInfo ()
 Construct a MOpenCLKernelInfo with a NULL MAutoCLKernel.
 
virtual ~MOpenCLKernelInfo ()
 Destructor.
 
void reset ()
 Releases the kernel and stops the managing its lifetime.
 
const size_t * localWorkSize () const
 Returns the array of unsigned values that describe the number of work-items that make up a work-group that will execute the kernel function.
 
const size_t * globalWorkSize () const
 Returns the array of unsigned values that describe the number of global work-items that will execute the kernel function.
 
size_t elementCount () const
 Returns elementCount to be used by the kernel.
 
MAutoCLKernelkernel ()
 Returns the kernel.
 
cl_kernel get () const
 This method returns the current cl_kernel whose lifetime is being managed by the auto pointer of the kerner. More...
 
bool isNull () const
 This method checks if the object manages a null kernel object. More...
 
bool loadOrUpdate (const MString &fileName, const MString &kernelName, int elementCount=0)
 Initializes or updates the OpenCL kernel. More...
 
bool loadKernel (const MString &fileName, const MString &kernelName, int elementCount=0)
 Initializes the OpenCL kernel. More...
 
bool updateWorkSize (int elementCount)
 Updates the work size of the OpenCL kernel. More...
 
void invalidateWorkSize ()
 Invalidates the work size of the OpenCL kernel. More...
 
cl_int setKernelArgBuffer (cl_uint argIndex, const MAutoCLMem &buffer, cl_int &errorCode, bool useBuffer=true)
 Used to set the buffer as the argument value for a specific argument of this kernel. More...
 
cl_int setKernelArgBuffer (cl_uint argIndex, const MOpenCLBuffer &buffer, cl_int &errorCode, bool useBuffer=true)
 Used to set the buffer as the argument value for a specific argument of this kernel. More...
 
template<typename T >
cl_int setKernelArg (cl_uint argIndex, T value, cl_int &errorCode)
 Used to set the argument value for a specific argument of this kernel. More...
 
cl_int enqueueKernel (MAutoCLEventList &eventWaitList, MAutoCLEvent &event)
 Enqueue the execution of a kernel. More...
 

Static Public Member Functions

static const char * className ()
 Returns the name of this class. More...
 

Detailed Description

Introduced in 2023.0

2023.0:
Introduced in this version.

OpenCL functionality.

Wrapper for a MAutoCLKernel that will keep track of the work size and the element count. It also contains utility functions to more easily manage the loading, updating and argument setting of the kernel.

Examples:
offsetNode/offsetNode.cpp, and testFailureNode/testFailureNode.cpp.

Member Function Documentation

cl_kernel get ( ) const

This method returns the current cl_kernel whose lifetime is being managed by the auto pointer of the kerner.

The reference count of the cl_kernel is not modified by get(). This is the same as using kernel().get()

Returns
The cl_kernel being managed by the "this" object.
bool isNull ( ) const

This method checks if the object manages a null kernel object.

Returns
True if the object manages a null cl_kernel object.
bool loadOrUpdate ( const MString fileName,
const MString kernelName,
int  elementCount = 0 
)

Initializes or updates the OpenCL kernel.

If the kernel has not been loaded it will load the kernel given the parameters. Otherwise it will check if the work sizes of the kernel need to be updated according to the elementCount. If the kernel was already loaded and the elementCount has not changed this function will do nothing.

Parameters
[in]fileNameName of the file holding the kernel.
[in]kernelNameName of the kernel to load.
[in]elementCountNumber of element to be processed by this kernel, or 0 if the global work size value does not need to be computed.
Returns
true if the kernel was loaded or updated successfully, false otherwise.
bool loadKernel ( const MString fileName,
const MString kernelName,
int  elementCount = 0 
)

Initializes the OpenCL kernel.

Parameters
[in]fileNameName of the file holding the kernel.
[in]kernelNameName of the kernel to load.
[in]elementCountNumber of element to be processed by this kernel, or 0 if the global work size value does not need to be computed.
Returns
true if the kernel was loaded successfully, false otherwise.
bool updateWorkSize ( int  elementCount)

Updates the work size of the OpenCL kernel.

Parameters
[in]elementCountNumber of element to be processed by this kernel.
Returns
true if the kernel remained unaltered or was updated successfully, false otherwise.
void invalidateWorkSize ( )

Invalidates the work size of the OpenCL kernel.

This ensures that a consecutive call to loadOrUpdate or updateWorkSize will recompute the work size for the kernel

cl_int setKernelArgBuffer ( cl_uint  argIndex,
const MAutoCLMem buffer,
cl_int &  errorCode,
bool  useBuffer = true 
)

Used to set the buffer as the argument value for a specific argument of this kernel.

If the specified errorCode is not CL_SUCCES this function will do nothing. It will simply return the error code. Otherwise it will set the argument on the kernel and return the new errorCode.

Parameters
[in]argIndexThe argument index. Arguments to the kernel are referred by indices that go from 0 for the leftmost argument to n - 1, where n is the total number of arguments declared by a kernel.
[in]bufferThe data that should be used as the argument value for the argument specified by argIndex
[in,out]errorCodethe previous error code which will be set to the new result if the previous code was CL_SUCCES
[in]useBufferwhen true the specified buffer is set as the argument, otherwise a nullptr is set.
Returns
returns CL_SUCCESS if the argument was successfully set. Otherwise, it returns an OpenCL error code.
cl_int setKernelArgBuffer ( cl_uint  argIndex,
const MOpenCLBuffer buffer,
cl_int &  errorCode,
bool  useBuffer = true 
)

Used to set the buffer as the argument value for a specific argument of this kernel.

If the specified errorCode is not CL_SUCCES this function will do nothing. It will simply return the error code. Otherwise it will set the argument on the kernel and return the new errorCode.

Parameters
[in]argIndexThe argument index. Arguments to the kernel are referred by indices that go from 0 for the leftmost argument to n - 1, where n is the total number of arguments declared by a kernel.
[in]bufferThe data that should be used as the argument value for the argument specified by argIndex
[in,out]errorCodethe previous error code which will be set to the new result if the previous code was CL_SUCCES
[in]useBufferwhen true the specified buffer is set as the argument, otherwise a nullptr is set.
Returns
returns CL_SUCCESS if the argument was successfully set. Otherwise, it returns an OpenCL error code.
cl_int setKernelArg ( cl_uint  argIndex,
value,
cl_int &  errorCode 
)
inline

Used to set the argument value for a specific argument of this kernel.

If the specified errorCode is not CL_SUCCES this function will do nothing. It will simply return the error code. Otherwise it will set the argument on the kernel and return the new errorCode.

Parameters
[in]argIndexThe argument index. Arguments to the kernel are referred by indices that go from 0 for the leftmost argument to n - 1, where n is the total number of arguments declared by a kernel.
[in]valueThe data that should be used as the argument value for the argument specified by argIndex
[in,out]errorCodethe previous error code which will be set to the new result if the previous code was CL_SUCCES
Returns
  • CL_SUCCESS returns CL_SUCCESS if the function is executed successfully. Otherwise, it returns an OpenCL error code.
cl_int enqueueKernel ( MAutoCLEventList eventWaitList,
MAutoCLEvent event 
)

Enqueue the execution of a kernel.

This method enqueues the execution of the specified kernel. It will use the work sizes from the kernel info and execute on the default Maya OpenCL command queue.

Parameters
[in]eventWaitListThe events that must be completed before this can be executed
[out]eventThe new event that can be used later to wait for the result of this execution
Returns
returns CL_​SUCCESS if the kernel-instance was successfully queued. Otherwise, it returns an OpenCL error code. consistent with the core OpenCL function clEnqueueNDRangeKernel
const char * className ( )
static

Returns the name of this class.

Returns
The name of this class.

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