Eulerian Smoke Simulation on the GPU
ComputeEngine Class Reference

A class for managing an OpenCL context and all its relevant functions. More...

#include <ComputeEngine.h>

List of all members.

Public Types

enum  DeviceType { DEVICE_TYPE_CPU = CL_DEVICE_TYPE_CPU, DEVICE_TYPE_GPU = CL_DEVICE_TYPE_GPU, DEVICE_TYPE_DEFAULT = CL_DEVICE_TYPE_DEFAULT, DEVICE_TYPE_ALL = CL_DEVICE_TYPE_ALL }

Public Member Functions

 ComputeEngine ()
 Constructor.
 ~ComputeEngine ()
 Destructor.
bool connect (DeviceType _deviceType=DEVICE_TYPE_ALL, unsigned int _count=1, bool _useOpenGLContext=false)
 Connects to the platform devices and initializes the engine.
bool disconnect ()
 Disconnects the platform devices from the engine.
bool createProgram (const char *_programName, const char *_fileName)
 Creates a program object.
bool createKernel (const char *_programName, const char *_kernelName)
 Creates a compute kernel.
bool setKernelArg (const char *_kernelName, cl_uint _index, void *_argsValue, size_t _argsSize)
 Sets a kernel argument for any arbitary variable.
bool setKernelArg (const char *_kernelName, cl_uint _index, const char *_memObjName)
 Sets a kernel memory object argument.
bool setKernelArgs (const char *_kernelName,...)
 Sets multiple kernel arguments.
bool executeKernel (const char *_kernelName, cl_uint _deviceId, size_t *_globalDim, size_t *_localDim, cl_uint _dimCount)
 Executes a kernel.
cl_kernel getKernelObject (const char *_kernelName)
 Accessor for a kernel's handle.
cl_mem getMemObject (const char *_memObjName)
 Accesor for a memory object's handle.
bool createBuffer (const char *_memObjName, cl_mem_flags _memFlags, size_t _bytes, void *_data)
 Creates a buffer object.
bool readBuffer (const char *_memObjName, cl_uint _deviceIndex, cl_uint _start, size_t _bytes, void *_data)
 Reads a buffer's data.
bool writeBuffer (const char *_memObjName, cl_uint _deviceIndex, cl_uint _start, size_t _bytes, void *_data)
 Writes data to a buffer.
bool createImage2D (const char *_memObjName, cl_mem_flags _memFlags, cl_channel_order _channelOrder, cl_channel_type _channelType, cl_uint _width, cl_uint _height, cl_uint _rowPitch=0, void *_data=NULL)
 Creates a 2D image object.
bool createImage3D (const char *_memObjName, cl_mem_flags _memFlags, cl_channel_order _channelOrder, cl_channel_type _channelType, cl_uint _width, cl_uint _height, cl_uint _depth, cl_uint _rowPitch=0, cl_uint _slicePitch=0, void *_data=NULL)
 Creates a 3D image object.
bool readImage (const char *_memObjName, cl_uint _deviceIndex, cl_uint _x, cl_uint _y, cl_uint _z, cl_uint _width, cl_uint _height, cl_uint _depth, cl_uint _rowPitch, cl_uint _slicePitch, void *_data)
 Reads from an image object.
bool writeImage (const char *_memObjName, cl_uint _deviceIndex, cl_uint _x, cl_uint _y, cl_uint _z, cl_uint _width, cl_uint _height, cl_uint _depth, cl_uint _rowPitch, cl_uint _slicePitch, void *_data)
 Writes to an image object.
bool copyBufferToBuffer (const char *_sourceBufferName, const char *_destinationBufferName, cl_uint _deviceIndex, size_t _sourceOffset, size_t _destinationOffset, size_t _bytes)
 Copies a buffer to another buffer (using buffer names).
bool copyBufferToBuffer (cl_mem _sourceBuffer, cl_mem _destinationBuffer, cl_uint _deviceIndex, size_t _sourceOffset, size_t _destinationOffset, size_t _bytes)
 Copies a buffer to another buffer (using buffer handles).
bool copyBufferToImage (const char *_bufferName, const char *_imageName, cl_uint _deviceIndex, size_t _bufferOffset, cl_uint _x, cl_uint _y, cl_uint _z, cl_uint _width, cl_uint _height, cl_uint _depth)
 Copies a buffer object to an image (using memory object names)
bool copyBufferToImage (cl_mem _buffer, cl_mem _image, cl_uint _deviceIndex, size_t _bufferOffset, cl_uint _x, cl_uint _y, cl_uint _z, cl_uint _width, cl_uint _height, cl_uint _depth)
 Copies a buffer object to an image (using memory object handles)
bool copyImageToBuffer (const char *_bufferName, const char *_imageName, cl_uint _deviceIndex, cl_uint _x, cl_uint _y, cl_uint _z, cl_uint _width, cl_uint _height, cl_uint _depth, size_t _bufferOffset)
 Copies an image to a buffer object (using memory object names).
bool copyImageToBuffer (cl_mem _buffer, cl_mem _image, cl_uint _deviceIndex, cl_uint _x, cl_uint _y, cl_uint _z, cl_uint _width, cl_uint _height, cl_uint _depth, size_t _bufferOffset)
 Copies an image to a buffer object (using memory object handles).
bool createGLBufferReference (const char *_memObjName, cl_mem_flags _memFlags, cl_uint _bufferId)
 Creates an OpenGL buffer reference object.
bool createGLTexture2DReference (const char *_memObjName, cl_mem_flags _memFlags, GLenum _target, GLint _mipLevel, GLuint _textureId)
 Creates an OpenGL 2D texture reference object.
bool createGLTexture3DReference (const char *_memObjName, cl_mem_flags _memFlags, GLenum _target, GLint _mipLevel, GLuint _textureId)
 Creates an OpenGL 3D texture reference object.
bool createGLRenderBufferReference (const char *_memObjName, cl_mem_flags _memFlags, GLuint _rboId)
 Creates an OpenGL render buffer reference object.
bool acquireGLObject (const char *_memObjName, cl_uint _deviceIndex=0)
 Acquire an OpenGL reference object, to use in OpenCL operations.
bool releaseGLObject (const char *_memObjName, cl_uint _deviceIndex=0)
 Releases an OpenGL reference object from any OpenCL operations.
bool swapMemObjects (const char *_memObjNameA, const char *_memObjNameB)
 Swaps two memory objects.
bool createImageSampler (const char *_samplerName, cl_bool _normalizedCoords, cl_addressing_mode _addressingMode, cl_filter_mode _filterMode)
 Creates an image sampler.
cl_sampler getSampler (const char *_samplerName)
 Accessor for an image sampler's handle.
bool flush (cl_uint _deviceIndex=0)
 Issues all previously queued OpenCL commands in a command-queue to the device associated with the command-queue.
bool finish (cl_uint _deviceIndex=0)
 Blocks all operations unitll all previously queued OpenCL commands in the specified command-queue have completed.
bool barrier (cl_uint _deviceIndex=0)
 Creates a synchronization point for pending operations.
cl_uint getContextDeviceCount ()
 Accessor for the number of context devices.
cl_uint getEstimatedWorkGroupSize (const char *_kernelName, cl_uint _deviceIndex=0)
 Estimates an optimal work-group size for a given kernel.
void getCLExtensions ()
 Prints the available OpenCL extensions.

Detailed Description

A class for managing an OpenCL context and all its relevant functions.

Author:
Nikolaos Verigakis
Version:
1.0
Date:
04/06/11 Revision History : Initial Version 04/06/11

Member Function Documentation

bool ComputeEngine::acquireGLObject ( const char *  _memObjName,
cl_uint  _deviceIndex = 0 
)

Acquire an OpenGL reference object, to use in OpenCL operations.

Parameters:
[in]_memObjNamethe reference object's name
[in]_deviceIndexthe device in which the acquire command will be queued
bool ComputeEngine::barrier ( cl_uint  _deviceIndex = 0)

Creates a synchronization point for pending operations.

Parameters:
[in]_deviceIndexthe device in which the command will be queued
bool ComputeEngine::connect ( DeviceType  _deviceType = DEVICE_TYPE_ALL,
unsigned int  _count = 1,
bool  _useOpenGLContext = false 
)

Connects to the platform devices and initializes the engine.

Parameters:
[in]_deviceTypethe device type to create the OpenCL context
[in]_countthe number of devices to use
[in]_useOpenGLContexta flag to set whether to use an OpenGL context or not
bool ComputeEngine::copyBufferToBuffer ( const char *  _sourceBufferName,
const char *  _destinationBufferName,
cl_uint  _deviceIndex,
size_t  _sourceOffset,
size_t  _destinationOffset,
size_t  _bytes 
)

Copies a buffer to another buffer (using buffer names).

Parameters:
[in]_sourceBufferNamethe source buffer's name
[in]_destinationBufferNamethe destination's buffer's name
[in]_deviceIndexthe device in which the copy command will be queued
[in]_sourceOffsetbyte offset to the source buffer
[in]_destinationOffsetbyte offset to the destination buffer
[in]_bytesthe data size in bytes to copy
bool ComputeEngine::copyBufferToBuffer ( cl_mem  _sourceBuffer,
cl_mem  _destinationBuffer,
cl_uint  _deviceIndex,
size_t  _sourceOffset,
size_t  _destinationOffset,
size_t  _bytes 
)

Copies a buffer to another buffer (using buffer handles).

Parameters:
[in]_sourceBufferthe source buffer
[in]_destinationBufferthe destination buffer
[in]_deviceIndexthe device in which the copy command will be queued
[in]_sourceOffsetbyte offset to the source buffer
[in]_destinationOffsetbyte offset to the destination buffer
[in]_bytesthe data size in bytes to copy
bool ComputeEngine::copyBufferToImage ( const char *  _bufferName,
const char *  _imageName,
cl_uint  _deviceIndex,
size_t  _bufferOffset,
cl_uint  _x,
cl_uint  _y,
cl_uint  _z,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth 
)

Copies a buffer object to an image (using memory object names)

Parameters:
[in]_bufferNamethe buffer's name
[in]_imageNamethe image's name
[in]_deviceIndexthe device in which the copy command will be queued
[in]_bufferOffsetbyte offset to the source buffer
[in]_xthe X offset in pixels where to begin copying data to the image
[in]_ythe Y offset in pixels where to begin copying data to the image
[in]_zthe Z offset in pixels where to begin copying data to the image
[in]_widththe width in pixels of the 2D or 3D rectangle to copy
[in]_heightthe height in pixels of the 2D or 3D rectangle to copy
[in]_depththe depth in pixels of the 2D or 3D rectangle to copy
bool ComputeEngine::copyBufferToImage ( cl_mem  _buffer,
cl_mem  _image,
cl_uint  _deviceIndex,
size_t  _bufferOffset,
cl_uint  _x,
cl_uint  _y,
cl_uint  _z,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth 
)

Copies a buffer object to an image (using memory object handles)

Parameters:
[in]_bufferthe buffer to copy from
[in]_imagethe image to copy to
[in]_deviceIndexthe device in which the copy command will be queued
[in]_bufferOffsetbyte offset to the source buffer
[in]_xthe X offset in pixels where to begin copying data to the image
[in]_ythe Y offset in pixels where to begin copying data to the image
[in]_zthe Z offset in pixels where to begin copying data to the image
[in]_widththe width in pixels of the 2D or 3D rectangle to copy
[in]_heightthe height in pixels of the 2D or 3D rectangle to copy
[in]_depththe depth in pixels of the 2D or 3D rectangle to copy
bool ComputeEngine::copyImageToBuffer ( const char *  _bufferName,
const char *  _imageName,
cl_uint  _deviceIndex,
cl_uint  _x,
cl_uint  _y,
cl_uint  _z,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth,
size_t  _bufferOffset 
)

Copies an image to a buffer object (using memory object names).

Parameters:
[in]_bufferNamethe buffer's name
[in]_imageNamethe image's name
[in]_deviceIndexthe device in which the copy command will be queued
[in]_xthe X offset in pixels in the image from where to copy
[in]_ythe Y offset in pixels in the image from where to copy
[in]_zthe Z offset in pixels in the image from where to copy
[in]_widththe width in pixels of the 2D or 3D rectangle to copy
[in]_heightthe height in pixels of the 2D or 3D rectangle to copy
[in]_depththe depth in pixels of the 2D or 3D rectangle to copy
[in]_bufferOffsetbyte offset to the destination buffer
bool ComputeEngine::copyImageToBuffer ( cl_mem  _buffer,
cl_mem  _image,
cl_uint  _deviceIndex,
cl_uint  _x,
cl_uint  _y,
cl_uint  _z,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth,
size_t  _bufferOffset 
)

Copies an image to a buffer object (using memory object handles).

Parameters:
[in]_bufferthe buffer to copy to
[in]_imagethe image to copy from
[in]_deviceIndexthe device in which the copy command will be queued
[in]_xthe X offset in pixels in the image from where to copy
[in]_ythe Y offset in pixels in the image from where to copy
[in]_zthe Z offset in pixels in the image from where to copy
[in]_widththe width in pixels of the 2D or 3D rectangle to copy
[in]_heightthe height in pixels of the 2D or 3D rectangle to copy
[in]_depththe depth in pixels of the 2D or 3D rectangle to copy
[in]_bufferOffsetbyte offset to the destination buffer
bool ComputeEngine::createBuffer ( const char *  _memObjName,
cl_mem_flags  _memFlags,
size_t  _bytes,
void *  _data 
)

Creates a buffer object.

Parameters:
[in]_memObjNamethe buffer's name
[in]_memFlagsthe memory flags to set
[in]_bytesthe buffer's size in bytes
[in]_datathe buffer's data
bool ComputeEngine::createGLBufferReference ( const char *  _memObjName,
cl_mem_flags  _memFlags,
cl_uint  _bufferId 
)

Creates an OpenGL buffer reference object.

Parameters:
[in]_memObjNamethe buffer's name
[in]_memFlagsthe memory flags to set
[in]_bufferIdthe OpenGL buffer's ID handle
bool ComputeEngine::createGLRenderBufferReference ( const char *  _memObjName,
cl_mem_flags  _memFlags,
GLuint  _rboId 
)

Creates an OpenGL render buffer reference object.

Parameters:
[in]_memObjNamethe buffer's name
[in]_memFlagsthe memory flags to set
[in]_rboIdthe OpenGL render buffer's ID handle
bool ComputeEngine::createGLTexture2DReference ( const char *  _memObjName,
cl_mem_flags  _memFlags,
GLenum  _target,
GLint  _mipLevel,
GLuint  _textureId 
)

Creates an OpenGL 2D texture reference object.

Parameters:
[in]_memObjNamethe 2D texture's name
[in]_memFlagsthe memory flags to set
[in]_targetthe OpenGL texture target
[in]_mipLevelthe texture's mipmap level
[in]_textureIdthe OpenGL 2D texture's ID handle
bool ComputeEngine::createGLTexture3DReference ( const char *  _memObjName,
cl_mem_flags  _memFlags,
GLenum  _target,
GLint  _mipLevel,
GLuint  _textureId 
)

Creates an OpenGL 3D texture reference object.

Parameters:
[in]_memObjNamethe 3D texture's name
[in]_memFlagsthe memory flags to set
[in]_targetthe OpenGL texture target
[in]_mipLevelthe texture's mipmap level
[in]_textureIdthe OpenGL 3D texture's ID handle
bool ComputeEngine::createImage2D ( const char *  _memObjName,
cl_mem_flags  _memFlags,
cl_channel_order  _channelOrder,
cl_channel_type  _channelType,
cl_uint  _width,
cl_uint  _height,
cl_uint  _rowPitch = 0,
void *  _data = NULL 
)

Creates a 2D image object.

Parameters:
[in]_memObjNamethe image's name
[in]_memFlagsthe memory flags to set
[in]_channelOrderthe number of channels and the channel layout
[in]_channelTypethe size of the channel data type
[in]_widththe image width
[in]_heightthe image height
[in]_rowPitchthe scan-line pitch in bytes
[in]_dataa pointer to the image data
bool ComputeEngine::createImage3D ( const char *  _memObjName,
cl_mem_flags  _memFlags,
cl_channel_order  _channelOrder,
cl_channel_type  _channelType,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth,
cl_uint  _rowPitch = 0,
cl_uint  _slicePitch = 0,
void *  _data = NULL 
)

Creates a 3D image object.

Parameters:
[in]_memObjNamethe image's name
[in]_memFlagsthe memory flags to set
[in]_channelOrderthe number of channels and the channel layout
[in]_channelTypethe size of the channel data type
[in]_widththe image width
[in]_heightthe image height
[in]_depththe image depth
[in]_rowPitchthe scan-line pitch in bytes
[in]_slicePitchthe size in bytes of each 2D slice in the 3D image
[in]_dataa pointer to the image data
bool ComputeEngine::createImageSampler ( const char *  _samplerName,
cl_bool  _normalizedCoords,
cl_addressing_mode  _addressingMode,
cl_filter_mode  _filterMode 
)

Creates an image sampler.

Parameters:
[in]_samplerNamethe sampler's name
[in]_normalizedCoordsdetermines if the image coordinates specified are normalized or not
[in]_addressingModespecifies how out-of-range image coordinates are handled when reading from an image
[in]_filterModethe type of filter that must be applied when reading an image
bool ComputeEngine::createKernel ( const char *  _programName,
const char *  _kernelName 
)

Creates a compute kernel.

Parameters:
[in]_programNamethe name of the program that uses the kernel
[in]_kernelNamethe name of the kernel
bool ComputeEngine::createProgram ( const char *  _programName,
const char *  _fileName 
)

Creates a program object.

Parameters:
[in]_programNamethe name of the program
[in]_fileNamethe file name of the program's code
bool ComputeEngine::executeKernel ( const char *  _kernelName,
cl_uint  _deviceId,
size_t *  _globalDim,
size_t *  _localDim,
cl_uint  _dimCount 
)

Executes a kernel.

Parameters:
[in]_kernelNamethe name of the kernel
[in]_deviceIdthe device to execute the kernel to
[in]_globalDimthe kernel's global dimension
[in]_localDimthe kernel's local dimension
[in]_dimCountthe number of dimensions
bool ComputeEngine::finish ( cl_uint  _deviceIndex = 0)

Blocks all operations unitll all previously queued OpenCL commands in the specified command-queue have completed.

Parameters:
[in]_deviceIndexthe device in which the command will be queued
bool ComputeEngine::flush ( cl_uint  _deviceIndex = 0)

Issues all previously queued OpenCL commands in a command-queue to the device associated with the command-queue.

Parameters:
[in]_deviceIndexthe device in which the command will be queued
cl_uint ComputeEngine::getEstimatedWorkGroupSize ( const char *  _kernelName,
cl_uint  _deviceIndex = 0 
)

Estimates an optimal work-group size for a given kernel.

Parameters:
[in]_kernelNamethe name of the kernel to estimate
[in]_deviceIndexthe device in which the command will be queued
cl_kernel ComputeEngine::getKernelObject ( const char *  _kernelName)

Accessor for a kernel's handle.

Parameters:
[in]_kernelNamethe name of the kernel
cl_mem ComputeEngine::getMemObject ( const char *  _memObjName)

Accesor for a memory object's handle.

Parameters:
[in]_memObjNamethe name of the memory object
cl_sampler ComputeEngine::getSampler ( const char *  _samplerName)

Accessor for an image sampler's handle.

Parameters:
[in]_samplerNamethe name of the sampler
bool ComputeEngine::readBuffer ( const char *  _memObjName,
cl_uint  _deviceIndex,
cl_uint  _start,
size_t  _bytes,
void *  _data 
)

Reads a buffer's data.

Parameters:
[in]_memObjNamethe buffer's name
[in]_deviceIndexthe device in which the read command will be queued
[in]_startthe offset in bytes in the buffer object to read from
[in]_bytesthe size in bytes of data being read
[in]_dataa pointer in host memory where data is to be read into
bool ComputeEngine::readImage ( const char *  _memObjName,
cl_uint  _deviceIndex,
cl_uint  _x,
cl_uint  _y,
cl_uint  _z,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth,
cl_uint  _rowPitch,
cl_uint  _slicePitch,
void *  _data 
)

Reads from an image object.

Parameters:
[in]_memObjNamethe image's name
[in]_deviceIndexthe device in which the read command will be queued
[in]_xthe X offset in pixels in the image from where to read
[in]_ythe Y offset in pixels in the image from where to read
[in]_zthe Z offset in pixels in the image from where to read
[in]_widththe width in pixels of the 2D or 3D rectangle being read
[in]_heightthe height in pixels of the 2D or 3D rectangle being read
[in]_depththe depth in pixels of the 2D or 3D rectangle being read
[in]_rowPitchthe length of each row in bytes
[in]_slicePitchthe size in bytes of the 2D slice of the 3D region
[in]_datathe pointer to a buffer in host memory where image data is to be read from
bool ComputeEngine::releaseGLObject ( const char *  _memObjName,
cl_uint  _deviceIndex = 0 
)

Releases an OpenGL reference object from any OpenCL operations.

Parameters:
[in]_memObjNamethe reference object's name
[in]_deviceIndexthe device in which the release command will be queued
bool ComputeEngine::setKernelArg ( const char *  _kernelName,
cl_uint  _index,
const char *  _memObjName 
)

Sets a kernel memory object argument.

Parameters:
[in]_kernelNamethe name of the kernel
[in]_indexthe argument's index
[in]_memObjNamethe memory object to set as the argument's value
bool ComputeEngine::setKernelArg ( const char *  _kernelName,
cl_uint  _index,
void *  _argsValue,
size_t  _argsSize 
)

Sets a kernel argument for any arbitary variable.

Parameters:
[in]_kernelNamethe name of the kernel
[in]_indexthe argument's index
[in]_argsValuethe argument's value
[in]_argsSizethe argument's size in bytes
bool ComputeEngine::setKernelArgs ( const char *  _kernelName,
  ... 
)

Sets multiple kernel arguments.

Parameters:
[in]_kernelNamethe name of the kernel
[in]...multiple argument values and sizes
bool ComputeEngine::swapMemObjects ( const char *  _memObjNameA,
const char *  _memObjNameB 
)

Swaps two memory objects.

Parameters:
[in]_memObjNameAthe first memory object's name
[in]_memObjNameBthe second memory object's name
bool ComputeEngine::writeBuffer ( const char *  _memObjName,
cl_uint  _deviceIndex,
cl_uint  _start,
size_t  _bytes,
void *  _data 
)

Writes data to a buffer.

Parameters:
[in]_memObjNamethe buffer's name
[in]_deviceIndexthe device in which the write command will be queued
[in]_startthe offset in bytes in the buffer object to write to
[in]_bytesthe size in bytes of data being written
[in]_dataa pointer in host memory where data is to be written from
bool ComputeEngine::writeImage ( const char *  _memObjName,
cl_uint  _deviceIndex,
cl_uint  _x,
cl_uint  _y,
cl_uint  _z,
cl_uint  _width,
cl_uint  _height,
cl_uint  _depth,
cl_uint  _rowPitch,
cl_uint  _slicePitch,
void *  _data 
)

Writes to an image object.

Parameters:
[in]_memObjNamethe image's name
[in]_deviceIndexthe device in which the write command will be queued
[in]_xthe X offset in pixels in the image from where to write
[in]_ythe Y offset in pixels in the image from where to write
[in]_zthe Z offset in pixels in the image from where to write
[in]_widththe width in pixels of the 2D or 3D rectangle being writen
[in]_heightthe height in pixels of the 2D or 3D rectangle being writen
[in]_depththe depth in pixels of the 2D or 3D rectangle being writen
[in]_rowPitchthe length of each row in bytes
[in]_slicePitchthe size in bytes of the 2D slice of the 3D region
[in]_datathe pointer to a buffer in host memory where image data is to be written to

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables