OpenCL device context API More...
#include <Inventor/devices/SoOpenCLContext.h>
Public Member Functions | |
SoOpenCLContext (SoOpenCLDevice *device) | |
void | bind () |
void | unbind () |
virtual bool | isCurrent () const |
virtual bool | isCompatible (SoDeviceContext *context) const |
cl_context | getOpenCLContext () const |
cl_command_queue | getOpenCLCommandQueue () const |
SoOpenCLDevice * | getDevice () const |
Static Public Member Functions | |
static SoOpenCLContext * | getCurrent () |
This class provides functions to manage OpenCL contexts. Each context defines a private working area for the threads which use it.
Before using any OpenCL contexts the application must initialize the Open Inventor OpenCL module by calling SoCuda::init().
A valid OpenCL context is required to use OpenCL buffer objects, to call OpenCL functions or to execute OpenCL algorithms (e.g. SoOpenCLConvolution).
The context can only be current for one thread at a time. If thread1 binds a context, then any other thread that tries to bind the context will block until thread1 unbinds the context.
Notes:
// OpenInventor Initialization ... SoOpenCL::init(); SoOpenCLDevice* pMainDevice = SoOpenCLDevice::findFirstAvailableDevice(); if ( pMainDevice ) { SoOpenCLContext* pContext = new SoOpenCLContext( pMainDevice ); if ( pContext ) { pContext->bind(); SoOpenCLHandle* pHandle = SoOpenCL::findFunction( "ModuleName", "FunctionName" ); if ( pHandle ) { SoOpenCLApi::launch( pHandle, 10, 1 ); SoOpenCLApi::freeHandle( pHandle ); } pContext->unbind(); } } SoOpenCL::finish();
SoOpenCL, SoOpenCLApi, SoOpenCLDevice, SoOpenCLBufferObject, SoOpenCLArithmetic, SoOpenCLConversion, SoOpenCLConvolution, SoOpenCLSeismic
SoOpenCLContext::SoOpenCLContext | ( | SoOpenCLDevice * | device | ) |
Regular constructor.
device | Device on which to create the context. |
void SoOpenCLContext::bind | ( | ) | [virtual] |
Bind this context to the current thread.
Implements SoDeviceContext.
static SoOpenCLContext* SoOpenCLContext::getCurrent | ( | ) | [static] |
Returns the currently bound context (if any) for the current thread.
SoOpenCLDevice* SoOpenCLContext::getDevice | ( | ) | const [inline] |
Return attached device.
cl_command_queue SoOpenCLContext::getOpenCLCommandQueue | ( | ) | const [inline] |
OpenCL context accessor.
cl_context SoOpenCLContext::getOpenCLContext | ( | ) | const [inline] |
OpenCL context accessor.
virtual bool SoOpenCLContext::isCompatible | ( | SoDeviceContext * | context | ) | const [virtual] |
Indicates if the specified context and this one are compatible.
Compatible means that using a buffer from one of these contexts inside the other will not require copying the data.
context | The context to compare with this one. |
virtual bool SoOpenCLContext::isCurrent | ( | ) | const [virtual] |
Query if the context is valid and currently active.
Implements SoDeviceContext.
void SoOpenCLContext::unbind | ( | ) | [virtual] |
Unbind this context from the current thread and unlock it.
After this call the context can be bound in any thread.
Implements SoDeviceContext.