HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CE_Context Class Reference

#include <CE_Context.h>

Classes

struct  DeviceDescriptor
 
struct  KernelInfo
 

Public Member Functions

 CE_Context ()
 
virtual ~CE_Context ()
 
cl::Context getCLContext () const
 Returns the underlying cl::Context object. More...
 
cl::CommandQueue getQueue () const
 
cl::Device getDevice () const
 Returns the OpenCL Device object. More...
 
void getInfo (UT_WorkBuffer &buffer)
 
void getExtendedInfo (UT_WorkBuffer &buffer)
 
void get1DRanges (const cl::Kernel &k, size_t items, cl::NDRange &g, cl::NDRange &l)
 
cl::Program loadProgram (const char *progname, const char *options=NULL, bool recompile=false)
 
cl::Program compileProgram (const char *progtext, const char *options=NULL, bool recompile=false)
 
cl::Kernel loadKernel (const cl::Program &prog, const UT_StringRef &kernelname)
 
cl::Kernel loadKernel (const char *progname, const UT_StringRef &kernelname, const char *options=NULL)
 
bool isValid () const
 Returns whether the CE_Context has been successfully initialized. More...
 
bool isCPU () const
 Returns true if the OpenCL device is running on the CPU. More...
 
bool hasDoubleSupport () const
 Returns true if the OpenCL device supports double precision. More...
 
void finish (bool sweepPool=true)
 
cl::Buffer allocBuffer (int64 size, bool usePool=true, bool read=true, bool write=true, uint32 ogl_bind=SYS_UINT32_MAX)
 
void releaseBuffer (const cl::Buffer &buf)
 Release the specified buffer, possibly to the CE_MemoryPool. More...
 
uint32 registerDelayedOGLBindBuffer (CE_DelayedOGLBindBuffer *buffer)
 
void unregisterDelayedOGLBindBuffer (uint32 id)
 
CE_DelayedOGLBindBufferlookupDelayedOGLBindBuffer (uint id)
 
void clearMemoryPool ()
 Clear the CE_MemoryPool object. More...
 
fpreal32getPinnedBuffer (int64 size)
 
cl::Buffer getXNoiseData ()
 
void setOutOfMemoryFailure (bool hasfailed=true)
 
bool hasOutOfMemoryFailureHappened () const
 

Static Public Member Functions

static CE_ContextgetContext (bool gl_shared=false)
 
static void getAllPlatformsInfo (UT_WorkBuffer &buffer)
 
static bool isInitialized (bool gl_shared=false)
 
static void reportError (const cl::Error &err)
 
static void outputErrorMessage (const char *errMsg)
 
static void setErrorCB (CE_ErrorCB callback, void *data)
 
static void outputWarningMessage (const char *errMsg)
 
static void initMainSharedGLContext (int devicetype, void *context, void *display)
 
static bool useHalfNormalDelayedBindBuffer ()
 
static void getDevices (UT_Array< DeviceDescriptor > &, cl_device_type t)
 Get the vector of available devices of the given type. More...
 
static bool isEnvironmentOverride ()
 Returns true if environment variables are set that override preferences. More...
 

Protected Member Functions

cl::ProgramdoCompileProgram (const char *progtext, const char *options)
 
void init (cl::Context &context, cl::Device &device)
 Initialize the context for the given device. More...
 
void releasePinnedBuffer ()
 Releases the pinned, page-locked memory buffer. More...
 

Protected Attributes

cl::Context myContext
 
cl::CommandQueue myQueue
 
cl::Device myDevice
 
bool myIsValid
 
bool mySupportsDouble
 
cl::Buffer myXNoiseData
 
UT_StringMap< cl::Program * > myProgramTable
 
UT_Map< const _cl_program
*, UT_Array< KernelInfo > * > 
myKernelTable
 
CE_MemoryPoolmyMemPool
 
cl::Buffer myPinnedBuffer
 
fpreal32myPinnedData
 
bool myOutOfMemoryFailure
 
UT_Map< uint32,
CE_DelayedOGLBindBuffer * > 
myDelayedOGLBindBuffers
 

Static Protected Attributes

static voidtheGLContext
 
static voidtheGLDisplay
 
static int theGLDeviceType
 

Detailed Description

CE_Context encapsulates the OpenCL context and provides various convenience functions for loading kernel programs and allocating GPU memory.

Definition at line 43 of file CE_Context.h.

Constructor & Destructor Documentation

CE_Context::CE_Context ( )
virtual CE_Context::~CE_Context ( )
virtual

Member Function Documentation

cl::Buffer CE_Context::allocBuffer ( int64  size,
bool  usePool = true,
bool  read = true,
bool  write = true,
uint32  ogl_bind = SYS_UINT32_MAX 
)

Allocate a buffer of specified size on the CE_Device. usePool= true, attempts to use the underlying CE_MemoryPool to possibly return an already allocated, unused buffer. read=true, creates a buffer that is readable inside kernels. write=true, creates a buffer that is writable inside kernels. ogl_bind, specifies an OGL buffer to bind to.

void CE_Context::clearMemoryPool ( )

Clear the CE_MemoryPool object.

cl::Program CE_Context::compileProgram ( const char *  progtext,
const char *  options = NULL,
bool  recompile = false 
)
cl::Program* CE_Context::doCompileProgram ( const char *  progtext,
const char *  options 
)
protected
void CE_Context::finish ( bool  sweepPool = true)

Block until any outstanding kernel or memory transfers on the main CommandQueue have executed. If sweepPool is true, the context's CE_MemoryPool will sweep for any buffers that were in use when their CE_Grid's went out of scope, but that were still active in kernels.

void CE_Context::get1DRanges ( const cl::Kernel k,
size_t  items,
cl::NDRange g,
cl::NDRange l 
)

Get the suggested global and local ranges for the given 1-D kernel over the specified number of items.

static void CE_Context::getAllPlatformsInfo ( UT_WorkBuffer buffer)
static
cl::Context CE_Context::getCLContext ( ) const
inline

Returns the underlying cl::Context object.

Definition at line 54 of file CE_Context.h.

static CE_Context* CE_Context::getContext ( bool  gl_shared = false)
static

Returns a pointer to the singleton CE_Context object. This function initializes attempts to initialize OpenCL if it has not yet been.

cl::Device CE_Context::getDevice ( ) const
inline

Returns the OpenCL Device object.

Definition at line 61 of file CE_Context.h.

static void CE_Context::getDevices ( UT_Array< DeviceDescriptor > &  ,
cl_device_type  t 
)
static

Get the vector of available devices of the given type.

void CE_Context::getExtendedInfo ( UT_WorkBuffer buffer)
void CE_Context::getInfo ( UT_WorkBuffer buffer)
fpreal32* CE_Context::getPinnedBuffer ( int64  size)

Return a pointer to pinned (page-locked) host memory. On some devices (Nvidia), using this type of memory for the PCI/E host/device transfers can double the throughput. Will return NULL if the memory can't be allocated, or if the device is not a GPU.

cl::CommandQueue CE_Context::getQueue ( ) const
inline

Returns the cl::Queue object that is used to enqueue OpenCL kernels and memory transfers.

Definition at line 58 of file CE_Context.h.

cl::Buffer CE_Context::getXNoiseData ( )
bool CE_Context::hasDoubleSupport ( ) const
inline

Returns true if the OpenCL device supports double precision.

Definition at line 108 of file CE_Context.h.

bool CE_Context::hasOutOfMemoryFailureHappened ( ) const
inline

Definition at line 172 of file CE_Context.h.

void CE_Context::init ( cl::Context context,
cl::Device device 
)
protected

Initialize the context for the given device.

static void CE_Context::initMainSharedGLContext ( int  devicetype,
void context,
void display 
)
static
bool CE_Context::isCPU ( ) const

Returns true if the OpenCL device is running on the CPU.

static bool CE_Context::isEnvironmentOverride ( )
static

Returns true if environment variables are set that override preferences.

static bool CE_Context::isInitialized ( bool  gl_shared = false)
static

Returns whether the singleton CE_Context has been initialized yet. This can be used to test whether OpenCL has been initialized without calling getContext and forcing an attempt at initialization.

bool CE_Context::isValid ( ) const
inline

Returns whether the CE_Context has been successfully initialized.

Definition at line 97 of file CE_Context.h.

cl::Kernel CE_Context::loadKernel ( const cl::Program prog,
const UT_StringRef kernelname 
)

Create an OpenCL kernel named kernelname from the program specified by progname. For some types of devices these kernels will be cached, as kernels can be expensive to create. This is the recommended method for creating kernels.

cl::Kernel CE_Context::loadKernel ( const char *  progname,
const UT_StringRef kernelname,
const char *  options = NULL 
)
inline

Definition at line 92 of file CE_Context.h.

cl::Program CE_Context::loadProgram ( const char *  progname,
const char *  options = NULL,
bool  recompile = false 
)

Loads the OpenCL program specified by progname. This functions searches for the file in the HOUDINI_OCL_PATH environment variable. Any compile- time options can be passed in the options parameter. If the program load succeeds, the progname will be cached, using the progrname and options strings together as a hash value lookup. In this way the same OpenCL program can be loaded several times with different compile-time flags.

CE_DelayedOGLBindBuffer* CE_Context::lookupDelayedOGLBindBuffer ( uint  id)
static void CE_Context::outputErrorMessage ( const char *  errMsg)
static
static void CE_Context::outputWarningMessage ( const char *  errMsg)
static
uint32 CE_Context::registerDelayedOGLBindBuffer ( CE_DelayedOGLBindBuffer buffer)

Keep a map buffer to bind at render time The first time a CL::Buffer is created it can be registered to rebing to a OGL vertex buffer at drawing time. The uint returned by the register call can be attached to a detail attribute and the drawing code can convert the CL Buffer to a CL BufferGL.

void CE_Context::releaseBuffer ( const cl::Buffer buf)

Release the specified buffer, possibly to the CE_MemoryPool.

void CE_Context::releasePinnedBuffer ( )
protected

Releases the pinned, page-locked memory buffer.

static void CE_Context::reportError ( const cl::Error &  err)
static

Standard error reporting for OpenCL exceptions. They should generally take the form:

try
{
OpenCL calls...
}
catch(cl::Error &err)
{
///cleanup
}

This will not capture delayed errors, however. Instead you will need to add a callback to intercept them.

static void CE_Context::setErrorCB ( CE_ErrorCB  callback,
void data 
)
static
void CE_Context::setOutOfMemoryFailure ( bool  hasfailed = true)
inline

Marks that an operation has run out of memory, allowing us to report elsewhere.

Definition at line 171 of file CE_Context.h.

void CE_Context::unregisterDelayedOGLBindBuffer ( uint32  id)
static bool CE_Context::useHalfNormalDelayedBindBuffer ( )
static

Member Data Documentation

cl::Context CE_Context::myContext
protected

Definition at line 197 of file CE_Context.h.

UT_Map<uint32,CE_DelayedOGLBindBuffer*> CE_Context::myDelayedOGLBindBuffers
protected

Definition at line 221 of file CE_Context.h.

cl::Device CE_Context::myDevice
protected

Definition at line 199 of file CE_Context.h.

bool CE_Context::myIsValid
protected

Definition at line 200 of file CE_Context.h.

UT_Map<const _cl_program *, UT_Array<KernelInfo> *> CE_Context::myKernelTable
protected

Definition at line 211 of file CE_Context.h.

CE_MemoryPool* CE_Context::myMemPool
protected

Definition at line 213 of file CE_Context.h.

bool CE_Context::myOutOfMemoryFailure
protected

Definition at line 219 of file CE_Context.h.

cl::Buffer CE_Context::myPinnedBuffer
protected

Definition at line 216 of file CE_Context.h.

fpreal32* CE_Context::myPinnedData
protected

Definition at line 217 of file CE_Context.h.

UT_StringMap<cl::Program *> CE_Context::myProgramTable
protected

Definition at line 210 of file CE_Context.h.

cl::CommandQueue CE_Context::myQueue
protected

Definition at line 198 of file CE_Context.h.

bool CE_Context::mySupportsDouble
protected

Definition at line 201 of file CE_Context.h.

cl::Buffer CE_Context::myXNoiseData
protected

Definition at line 202 of file CE_Context.h.

void* CE_Context::theGLContext
staticprotected

Definition at line 223 of file CE_Context.h.

int CE_Context::theGLDeviceType
staticprotected

Definition at line 225 of file CE_Context.h.

void* CE_Context::theGLDisplay
staticprotected

Definition at line 224 of file CE_Context.h.


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