CUDA context management class More...
#include <Inventor/devices/SoCudaContext.h>
Public Member Functions | |
SoCudaContext (SoCudaDevice *device) | |
void | bind () |
void | unbind () |
virtual bool | isCurrent () const |
virtual bool | isCompatible (SoDeviceContext *context) const |
Static Public Member Functions | |
static SoCudaContext * | getCurrent () |
This class provides functions to manage CUDA contexts. Each context defines a private working area for the threads which use it.
Before using any CUDA contexts the application must initialize the Open Inventor CUDA module by calling SoCuda::init().
A valid CUDA context is required to use CUDA buffer objects, to call CUDA functions or to execute CUDA algorithms (e.g. SoCudaConvolution).
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.
// OpenInventor Initialization ... SoCuda::init(); SoCudaDevice* pMainDevice = SoCudaDevice::findFirstAvailableDevice(); if ( pMainDevice ) { SoCudaContext* pContext = new SoCudaContext( pMainDevice ); if ( pContext ) { pContext->bind(); SoCudaHandle* pHandle = SoCuda::findFunction( "ModuleName", "FunctionName" ); if ( pHandle ) { SoCudaApi::launch( pHandle, 10, 1 ); SoCudaApi::freeHandle( pHandle ); } pContext->unbind(); } } SoCuda::finish();
SoCuda, SoCudaApi, SoCudaDevice, SoCudaBufferObject, SoCudaArithmetic, SoCudaConversion, SoCudaConvolution, SoCudaSeismic
SoCudaContext::SoCudaContext | ( | SoCudaDevice * | device | ) |
Regular constructor.
device | Device on which to create the context. |
void SoCudaContext::bind | ( | ) | [virtual] |
Bind this context to the current thread.
Implements SoDeviceContext.
static SoCudaContext* SoCudaContext::getCurrent | ( | ) | [static] |
Returns the currently bound context (if any) for the current thread.
virtual bool SoCudaContext::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 SoCudaContext::isCurrent | ( | ) | const [virtual] |
Query if the context is valid and currently active.
Implements SoDeviceContext.
void SoCudaContext::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.