HDK
|
#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... | |
ceTraceCtx | getTraceContext () const |
void | get1DRanges (const cl::Kernel &k, size_t items, cl::NDRange &g, cl::NDRange &l) |
size_t | getMaxWorkgroupSize (const cl::Kernel &k) |
Get the maximum workgroup size for the given kernel. More... | |
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... | |
bool | has3DImageWriteSupport () const |
Returns true if the OpenCL device supports writing to 3D image objects. 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 (cl::Buffer &&buf) |
Release the specified buffer, possibly to the CE_MemoryPool. More... | |
void | readBuffer (const cl::Buffer &buf, size_t size, void *p, bool blocking=true, size_t offset=0) |
Read the specified number of bytes from the buffer. More... | |
void | writeBuffer (const cl::Buffer &buf, size_t size, const void *p, bool blocking=true, size_t offset=0) |
Write the specified number of bytes to the buffer. More... | |
void | enqueueKernel (const cl::Kernel &kernel, const cl::NDRange &global, const cl::NDRange &local) |
Enqueue the kernel over the provided ranges. More... | |
uint32 | registerDelayedOGLBindBuffer (CE_DelayedOGLBindBuffer *buffer) |
void | unregisterDelayedOGLBindBuffer (uint32 id) |
CE_DelayedOGLBindBuffer * | lookupDelayedOGLBindBuffer (uint id) |
void | clearMemoryPool () |
Clear the CE_MemoryPool object. More... | |
fpreal32 * | getPinnedBuffer (int64 size) |
cl::Buffer | getXNoiseData () |
void | setOutOfMemoryFailure (bool hasfailed=true) |
bool | hasOutOfMemoryFailureHappened () const |
bool | getDeviceInfo (const char *flag, fpreal &result) |
Static Public Member Functions | |
static CE_Context * | getContext (bool gl_shared=true, bool shared_fallback=true) |
static bool | isGLSharingPossible () |
Returns true if interoperability between CL and GL is possible. More... | |
static void | getInfo (const cl::Device &device, UT_WorkBuffer &buffer) |
static void | getExtendedInfo (const cl::Device &device, UT_WorkBuffer &buffer) |
static void | getAllPlatformsInfo (UT_WorkBuffer &buffer) |
static size_t | roundUpGroupSize (size_t gsize) |
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 int | getDefaultDevice (cl_device_type t, const UT_Array< DeviceDescriptor > &devices) |
static bool | isEnvironmentOverride () |
Returns true if environment variables are set that override preferences. More... | |
template<class T > | |
static bool | getDeviceInfoRestricted (cl_device_id device, cl_uint flag, T &result) |
Protected Member Functions | |
cl::Program * | doCompileProgram (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::CommandQueue | myDeviceQueue |
ceTraceCtx | myTraceCtx |
cl::Device | myDevice |
bool | myIsValid |
bool | mySupportsDouble |
bool | mySupports3DImageWrites |
cl::Buffer | myXNoiseData |
UT_StringMap< cl::Program * > | myProgramTable |
UT_Map< const _cl_program *, UT_Array< KernelInfo > * > | myKernelTable |
CE_MemoryPool * | myMemPool |
cl::Buffer | myPinnedBuffer |
fpreal32 * | myPinnedData |
bool | myOutOfMemoryFailure |
UT_Map< uint32, CE_DelayedOGLBindBuffer * > | myDelayedOGLBindBuffers |
Static Protected Attributes | |
static void * | theGLContext |
static void * | theGLDisplay |
static int | theGLDeviceType |
CE_Context encapsulates the OpenCL context and provides various convenience functions for loading kernel programs and allocating GPU memory.
Definition at line 47 of file CE_Context.h.
CE_Context::CE_Context | ( | ) |
|
virtual |
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 |
||
) |
|
protected |
void CE_Context::enqueueKernel | ( | const cl::Kernel & | kernel, |
const cl::NDRange & | global, | ||
const cl::NDRange & | local | ||
) |
Enqueue the kernel over the provided ranges.
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 |
|
inline |
Returns the underlying cl::Context object.
Definition at line 67 of file CE_Context.h.
|
static |
Returns a pointer to the singleton CE_Context object. This function attempts to initialize OpenCL if it has not yet been. gl_shared should be true if the context will be expected to interoperate with the OpenGL context. If both gl_shared and shared_fallback are true, then the function will try to make an unshared context in case the shared context fails to create.
|
static |
Get an index to the preferred/default device for the specified device type and the list of available devices.
|
inline |
Returns the OpenCL Device object.
Definition at line 74 of file CE_Context.h.
Queries the current device give the specified flag using clGetDeviceInfo, used by ocldeviceinfo EXPR function. Returns false for unrecognized flag.
|
static |
|
static |
Get the vector of available devices of the given type.
|
static |
|
static |
size_t CE_Context::getMaxWorkgroupSize | ( | const cl::Kernel & | k | ) |
Get the maximum workgroup size for the given kernel.
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.
|
inline |
Returns the cl::Queue object that is used to enqueue OpenCL kernels and memory transfers.
Definition at line 71 of file CE_Context.h.
|
inline |
Definition at line 76 of file CE_Context.h.
cl::Buffer CE_Context::getXNoiseData | ( | ) |
|
inline |
Returns true if the OpenCL device supports writing to 3D image objects.
Definition at line 134 of file CE_Context.h.
|
inline |
Returns true if the OpenCL device supports double precision.
Definition at line 132 of file CE_Context.h.
|
inline |
Definition at line 207 of file CE_Context.h.
|
protected |
Initialize the context for the given device.
|
static |
bool CE_Context::isCPU | ( | ) | const |
Returns true if the OpenCL device is running on the CPU.
|
static |
Returns true if environment variables are set that override preferences.
|
static |
Returns true if interoperability between CL and GL is possible.
|
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.
|
inline |
Returns whether the CE_Context has been successfully initialized.
Definition at line 121 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.
|
inline |
Definition at line 116 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 | ) |
void CE_Context::readBuffer | ( | const cl::Buffer & | buf, |
size_t | size, | ||
void * | p, | ||
bool | blocking = true , |
||
size_t | offset = 0 |
||
) |
Read the specified number of bytes from the buffer.
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 | ( | cl::Buffer && | buf | ) |
Release the specified buffer, possibly to the CE_MemoryPool.
|
protected |
Releases the pinned, page-locked memory buffer.
Standard error reporting for OpenCL exceptions. They should generally take the form:
This will not capture delayed errors, however. Instead you will need to add a callback to intercept them.
|
static |
Round up a provided group size to a larger clean one as some driers die with prime-based groups sizes. Less than 1024 is raised to next power of 2, greater is to a multiple of 1024.
|
static |
|
inline |
Marks that an operation has run out of memory, allowing us to report elsewhere.
Definition at line 206 of file CE_Context.h.
|
static |
void CE_Context::writeBuffer | ( | const cl::Buffer & | buf, |
size_t | size, | ||
const void * | p, | ||
bool | blocking = true , |
||
size_t | offset = 0 |
||
) |
Write the specified number of bytes to the buffer.
|
protected |
Definition at line 249 of file CE_Context.h.
|
protected |
Definition at line 276 of file CE_Context.h.
|
protected |
Definition at line 253 of file CE_Context.h.
|
protected |
Definition at line 251 of file CE_Context.h.
|
protected |
Definition at line 254 of file CE_Context.h.
|
protected |
Definition at line 266 of file CE_Context.h.
|
protected |
Definition at line 268 of file CE_Context.h.
|
protected |
Definition at line 274 of file CE_Context.h.
|
protected |
Definition at line 271 of file CE_Context.h.
|
protected |
Definition at line 272 of file CE_Context.h.
|
protected |
Definition at line 265 of file CE_Context.h.
|
protected |
Definition at line 250 of file CE_Context.h.
|
protected |
Definition at line 256 of file CE_Context.h.
|
protected |
Definition at line 255 of file CE_Context.h.
|
protected |
Definition at line 252 of file CE_Context.h.
|
protected |
Definition at line 257 of file CE_Context.h.
|
staticprotected |
Definition at line 278 of file CE_Context.h.
|
staticprotected |
Definition at line 280 of file CE_Context.h.
|
staticprotected |
Definition at line 279 of file CE_Context.h.