Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages |
#include <itkOpenCLContext.h>
The OpenCLContext class represents an OpenCL context.
The host defines a context for the execution of the kernels. The context includes the following resources:
\table \row \o Devices \o The collection of OpenCL devices to be used by the host. \row \o Kernels \o The OpenCL functions that run on OpenCL devices. \row \o Program Objects \o The program source and executable that implement the kernels. \row \o Memory Objects \o A set of memory objects visible to the host and the OpenCL devices. Memory objects contain values that can be operated on by instances of a kernel. \endtable
The context is created and manipulated by the host using functions from the OpenCL API. The host creates a data structure called a command-queue to coordinate execution of the kernels on the devices. The host places commands into the command-queue which are then scheduled onto the devices within the context.
Context are constructed using OpenCLContext::Create().
Definition at line 76 of file itkOpenCLContext.h.
Public Types | |
typedef SmartPointer< const Self > | ConstPointer |
enum | CreateMethod { Default = 0x0000 , DevelopmentSingleMaximumFlopsDevice = 0x0001 , DevelopmentMultipleMaximumFlopsDevices = 0x0002 , SingleMaximumFlopsDevice = 0x0004 , MultipleMaximumFlopsDevices = 0x0008 } |
typedef SmartPointer< Self > | Pointer |
typedef OpenCLContext | Self |
typedef LightObject | Superclass |
Public Member Functions | |
cl_int | Barrier (const OpenCLEventList &event_list) |
OpenCLEvent | BarrierAsync (const OpenCLEventList &event_list) |
OpenCLProgram | BuildProgramFromSourceCode (const std::list< OpenCLDevice > &devices, const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string(), const std::string &extraBuildOptions=std::string()) |
OpenCLProgram | BuildProgramFromSourceCode (const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string()) |
OpenCLProgram | BuildProgramFromSourceFile (const std::list< OpenCLDevice > &devices, const std::string &fileName, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string(), const std::string &extraBuildOptions=std::string()) |
OpenCLProgram | BuildProgramFromSourceFile (const std::string &fileName, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string()) |
bool | Create () |
bool | Create (const OpenCLContext::CreateMethod method) |
bool | Create (const OpenCLDevice::DeviceType type) |
bool | Create (const OpenCLPlatform &platfrom, const OpenCLDevice::DeviceType type=OpenCLDevice::Default) |
bool | Create (const std::list< OpenCLDevice > &devices) |
OpenCLBuffer | CreateBufferCopy (const void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size) |
OpenCLBuffer | CreateBufferDevice (const OpenCLMemoryObject::Access access, const std::vcl_size_t size) |
OpenCLBuffer | CreateBufferHost (void *data, const OpenCLMemoryObject::Access access, const std::vcl_size_t size) |
OpenCLCommandQueue | CreateCommandQueue (const cl_command_queue_properties properties, const OpenCLDevice &device=OpenCLDevice()) |
OpenCLImage | CreateImageCopy (const OpenCLImageFormat &format, const void *data, const OpenCLSize &size, const OpenCLMemoryObject::Access access) |
OpenCLImage | CreateImageDevice (const OpenCLImageFormat &format, const OpenCLMemoryObject::Access access, const OpenCLSize &size) |
OpenCLImage | CreateImageHost (const OpenCLImageFormat &format, void *data, const OpenCLSize &size, const OpenCLMemoryObject::Access access) |
OpenCLProgram | CreateProgramFromBinaryCode (const unsigned char *binary, const std::vcl_size_t size) |
OpenCLProgram | CreateProgramFromSourceCode (const std::string &sourceCode, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string()) |
OpenCLProgram | CreateProgramFromSourceFile (const std::string &filename, const std::string &prefixSourceCode=std::string(), const std::string &postfixSourceCode=std::string()) |
OpenCLSampler | CreateSampler (const bool normalizedCoordinates, const OpenCLSampler::AddressingMode addressingMode, const OpenCLSampler::FilterMode filterMode) |
OpenCLUserEvent | CreateUserEvent () |
template<typename T > | |
OpenCLVector< T > | CreateVector (const OpenCLMemoryObject::Access access, const std::vcl_size_t size) |
void | Finish () |
void | Flush () |
virtual const char * | GetClassName () const |
OpenCLCommandQueue | GetCommandQueue () |
cl_context | GetContextId () const |
OpenCLCommandQueue | GetDefaultCommandQueue () |
OpenCLDevice | GetDefaultDevice () const |
std::list< OpenCLDevice > | GetDevices () const |
cl_int | GetLastError () const |
std::list< OpenCLImageFormat > | GetSupportedImageFormats (const OpenCLImageFormat::ImageType image_type, const cl_mem_flags flags) const |
bool | IsCreated () const |
cl_int | Marker (const OpenCLEventList &event_list) |
OpenCLEvent | MarkerAsync (const OpenCLEventList &event_list) |
virtual void | Release () |
void | ReportError (const cl_int code, const char *fileName="", const int lineNumber=0, const char *location="") |
void | SetCommandQueue (const OpenCLCommandQueue &queue) |
void | SetContextId (cl_context id) |
void | SetLastError (const cl_int error) |
Static Public Member Functions | |
static std::string | GetErrorName (const cl_int code) |
static Pointer | GetInstance () |
static Pointer | New () |
static void | SetInstance (OpenCLContext *instance) |
static cl_int | WaitForFinished (const OpenCLEventList &event_list) |
Protected Member Functions | |
OpenCLProgram | CreateOpenCLProgram (const std::string &filename, const std::string &source, const std::vcl_size_t sourceSize) |
OpenCLContext () | |
void | OpenCLProfile (cl_event clEvent, const std::string &message, const bool releaseEvent=false) |
void | SetDefaultDevice (const OpenCLDevice &device) |
~OpenCLContext () override | |
Private Member Functions | |
void | CreateContext (const OpenCLPlatform &platfrom, const OpenCLDevice::DeviceType type, OpenCLContextPimpl *d) |
void | CreateContext (const std::list< OpenCLDevice > &devices, OpenCLContextPimpl *d) |
cl_command_queue | GetActiveQueue () |
OpenCLContext (const Self &other) | |
void | OpenCLDebug (const std::string &callname) |
const Self & | operator= (const Self &) |
void | SetUpProfiling () |
Private Attributes | |
std::unique_ptr< OpenCLContextPimpl > | d_ptr |
Static Private Attributes | |
static Pointer | m_Instance |
Friends | |
class | OpenCLBuffer |
class | OpenCLCommandQueue |
class | OpenCLImage |
class | OpenCLKernel |
class | OpenCLMemoryObject |
class | OpenCLProgram |
class | OpenCLSampler |
class | OpenCLVectorBase |
typedef SmartPointer< const Self > itk::OpenCLContext::ConstPointer |
Definition at line 84 of file itkOpenCLContext.h.
typedef SmartPointer< Self > itk::OpenCLContext::Pointer |
Definition at line 83 of file itkOpenCLContext.h.
Standard class typedefs.
Definition at line 81 of file itkOpenCLContext.h.
typedef LightObject itk::OpenCLContext::Superclass |
Definition at line 82 of file itkOpenCLContext.h.
Enumerator | |
---|---|
Default | |
DevelopmentSingleMaximumFlopsDevice | |
DevelopmentMultipleMaximumFlopsDevices | |
SingleMaximumFlopsDevice | |
MultipleMaximumFlopsDevices |
Definition at line 115 of file itkOpenCLContext.h.
|
protected |
Constructs a new OpenCL context object. This constructor is typically followed by calls to SetPlatform() and Create().
|
overrideprotected |
Destroys this OpenCL context object. If the underlying GetContextId() has been created, then it will be released.
|
private |
cl_int itk::OpenCLContext::Barrier | ( | const OpenCLEventList & | event_list | ) |
Enqueues a barrier command which waits for either a list of events to complete, or if the list is empty it waits for all commands previously enqueued in command_queue to complete before it completes.
OpenCLEvent itk::OpenCLContext::BarrierAsync | ( | const OpenCLEventList & | event_list | ) |
Asynchronous version of the Barrier() method. This function will queue the request and return immediately. Returns an OpenCLEvent object that can be used to wait for the request to finish. The request will not start until all of the events in event_list have been signaled as completed.
OpenCLProgram itk::OpenCLContext::BuildProgramFromSourceCode | ( | const std::list< OpenCLDevice > & | devices, |
const std::string & | sourceCode, | ||
const std::string & | prefixSourceCode = std::string() , |
||
const std::string & | postfixSourceCode = std::string() , |
||
const std::string & | extraBuildOptions = std::string() |
||
) |
OpenCLProgram itk::OpenCLContext::BuildProgramFromSourceCode | ( | const std::string & | sourceCode, |
const std::string & | prefixSourceCode = std::string() , |
||
const std::string & | postfixSourceCode = std::string() |
||
) |
Creates an OpenCL program object from the supplied STL strings sourceCode, prefixSourceCode and then builds it. Returns a null OpenCLProgram if the program could not be built.
OpenCLProgram itk::OpenCLContext::BuildProgramFromSourceFile | ( | const std::list< OpenCLDevice > & | devices, |
const std::string & | fileName, | ||
const std::string & | prefixSourceCode = std::string() , |
||
const std::string & | postfixSourceCode = std::string() , |
||
const std::string & | extraBuildOptions = std::string() |
||
) |
OpenCLProgram itk::OpenCLContext::BuildProgramFromSourceFile | ( | const std::string & | fileName, |
const std::string & | prefixSourceCode = std::string() , |
||
const std::string & | postfixSourceCode = std::string() |
||
) |
Creates an OpenCL program object from the contents of the supplied by the STL strings filename, prefixSourceCode and then builds it. Returns a null OpenCLProgram if the program could not be built.
bool itk::OpenCLContext::Create | ( | ) |
Creates a new OpenCL context that is defined by CMake. See CMake OPENCL_USE_* variables. Does nothing if the context has already been created. Returns true if the context was created, false otherwise. On error, the status can be retrieved by calling GetLastError().
{clCreateContextFromType} and target existing OpenCL platform, which may not be found on the user computer. For production better use context::Create( OpenCLContext::SingleMaximumFlopsDevice ) or similar. bool itk::OpenCLContext::Create | ( | const OpenCLContext::CreateMethod | method | ) |
Creates a new OpenCL context that matches method of creating. Does nothing if the context has already been created. Returns true if the context was created, false otherwise. On error, the status can be retrieved by calling GetLastError().
bool itk::OpenCLContext::Create | ( | const OpenCLDevice::DeviceType | type | ) |
Creates a new OpenCL context that matches type. Does nothing if the context has already been created. This function will search for the first platform that has a device that matches type. The following code can be used to select devices that match type on a specific platform:
Returns true if the context was created, false otherwise. On error, the status can be retrieved by calling GetLastError().
bool itk::OpenCLContext::Create | ( | const OpenCLPlatform & | platfrom, |
const OpenCLDevice::DeviceType | type = OpenCLDevice::Default |
||
) |
Creates a new OpenCL context that matches platform and type. Does nothing if the context has already been created. Returns true if the context was created, false otherwise. On error, the status can be retrieved by calling GetLastError().
bool itk::OpenCLContext::Create | ( | const std::list< OpenCLDevice > & | devices | ) |
Creates a new OpenCL context that matches devices. Does nothing if the context has already been created. All of the devices must be associated with the same platform. Returns true if the context was created, false otherwise. On error, the status can be retrieved by calling GetLastError().
OpenCLBuffer itk::OpenCLContext::CreateBufferCopy | ( | const void * | data, |
const OpenCLMemoryObject::Access | access, | ||
const std::vcl_size_t | size | ||
) |
Creates an OpenCL memory buffer of size bytes in length, with the specified access mode. The buffer is initialized with a copy of the contents of data. The application's data can be discarded after the buffer is created. Returns the new OpenCL memory buffer object, or a null object if the buffer could not be created.
OpenCLBuffer itk::OpenCLContext::CreateBufferDevice | ( | const OpenCLMemoryObject::Access | access, |
const std::vcl_size_t | size | ||
) |
Creates an OpenCL memory buffer of size bytes in length, with the specified access mode. The memory is created on the device and will not be accessible to the host via a direct pointer. Use CreateBufferHost() to create a host-accessible buffer. Returns the new OpenCL memory buffer object, or a null object if the buffer could not be created.
OpenCLBuffer itk::OpenCLContext::CreateBufferHost | ( | void * | data, |
const OpenCLMemoryObject::Access | access, | ||
const std::vcl_size_t | size | ||
) |
Creates an OpenCL memory buffer of size bytes in length, with the specified access mode. If data is not null, then it will be used as the storage for the buffer. If data is null, then a new block of host-accessible memory will be allocated. Returns the new OpenCL memory buffer object, or a null object if the buffer could not be created.
OpenCLCommandQueue itk::OpenCLContext::CreateCommandQueue | ( | const cl_command_queue_properties | properties, |
const OpenCLDevice & | device = OpenCLDevice() |
||
) |
Creates a new command queue on this context for device with the specified properties. If device is null, then GetDefaultDevice() will be used instead. Unlike GetDefaultCommandQueue(), this function will create a new queue every time it is called. The queue will be deleted when the last reference to the returned object is removed.
|
private |
|
private |
OpenCLImage itk::OpenCLContext::CreateImageCopy | ( | const OpenCLImageFormat & | format, |
const void * | data, | ||
const OpenCLSize & | size, | ||
const OpenCLMemoryObject::Access | access | ||
) |
Creates a OpenCL image object with the specified format, size, and access mode. The image is initialized with a copy of the contents of data. The application's data can be discarded after the image is created. Returns the new OpenCL image object, or a null object if the image could not be created.
OpenCLImage itk::OpenCLContext::CreateImageDevice | ( | const OpenCLImageFormat & | format, |
const OpenCLMemoryObject::Access | access, | ||
const OpenCLSize & | size | ||
) |
Creates a OpenCL image object with the specified format, size, and access mode. The image memory is created on the device and will not be accessible to the host via a direct pointer. Use CreateImageHost() to create a host-accessible image. Returns the new OpenCL image object, or a null object if the image could not be created.
OpenCLImage itk::OpenCLContext::CreateImageHost | ( | const OpenCLImageFormat & | format, |
void * | data, | ||
const OpenCLSize & | size, | ||
const OpenCLMemoryObject::Access | access | ||
) |
Creates a OpenCL image object with the specified format, size, and access mode. If data is not null, then it will be used as the storage for the image. If data is null, then a new block of host-accessible memory will be allocated. Returns the new OpenCL image object, or a null object if the image could not be created.
|
protected |
OpenCLProgram itk::OpenCLContext::CreateProgramFromBinaryCode | ( | const unsigned char * | binary, |
const std::vcl_size_t | size | ||
) |
Creates an OpenCL program object from binary for GetDefaultDevice(). This function can only load the binary for a single device. For multiple devices, use CreateProgramFromBinaries() instead.
OpenCLProgram itk::OpenCLContext::CreateProgramFromSourceCode | ( | const std::string & | sourceCode, |
const std::string & | prefixSourceCode = std::string() , |
||
const std::string & | postfixSourceCode = std::string() |
||
) |
Creates an OpenCL program object from the supplied STL strings sourceCode, prefixSourceCode and postfixSourceCode.
OpenCLProgram itk::OpenCLContext::CreateProgramFromSourceFile | ( | const std::string & | filename, |
const std::string & | prefixSourceCode = std::string() , |
||
const std::string & | postfixSourceCode = std::string() |
||
) |
Creates an OpenCL program object from the contents of the specified by the STL string filename, prefixSourceCode and postfixSourceCode.
OpenCLSampler itk::OpenCLContext::CreateSampler | ( | const bool | normalizedCoordinates, |
const OpenCLSampler::AddressingMode | addressingMode, | ||
const OpenCLSampler::FilterMode | filterMode | ||
) |
Creates a sampler for this context from the arguments normalizedCoordinates, addressingMode, and filterMode.
OpenCLUserEvent itk::OpenCLContext::CreateUserEvent | ( | ) |
Creates a user event. User events allow applications to enqueue commands that wait on a user event to finish before the command is executed by the device. Commands that depend upon the user event will not be executed until the application triggers the user event with SetComplete().
|
inline |
Creates a host-accessible vector of size elements of type T on this context and returns it. The elements will be initially in an undefined state. Note that the access mode indicates how the OpenCL device (e.g. GPU) will access the vector. When the host maps the vector, it will always be mapped as ReadWrite.
Definition at line 291 of file itkOpenCLContext.h.
void itk::OpenCLContext::Finish | ( | ) |
Blocks until all previously queued commands on the active command queue have finished execution.
void itk::OpenCLContext::Flush | ( | ) |
Flushes all previously queued commands to the device associated with the active command queue. The commands are delivered to the device, but no guarantees are given that they will be executed.
|
private |
Quick get active queue method for friend classes.
|
virtual |
Run-time type information (and related methods).
OpenCLCommandQueue itk::OpenCLContext::GetCommandQueue | ( | ) |
Returns the context's active command queue, which will be GetDefaultCommandQueue() if the queue has not yet been set.
cl_context itk::OpenCLContext::GetContextId | ( | ) | const |
Returns the native OpenCL context identifier associated with this object.
OpenCLCommandQueue itk::OpenCLContext::GetDefaultCommandQueue | ( | ) |
Returns the default command queue for GetDefaultDevice(). If the queue has not been created, it will be created with the default properties of in-order execution of commands, and profiling disabled. Use CreateCommandQueue() to create a queue that supports out-of-order execution or profiling. For example:
OpenCLDevice itk::OpenCLContext::GetDefaultDevice | ( | ) | const |
Returns the default device in use by this context, which is typically the first element of the GetDevices() list or a null OpenCLDevice if the context has not been created yet.
std::list< OpenCLDevice > itk::OpenCLContext::GetDevices | ( | ) | const |
Returns the list of devices that are in use by this context. If the context has not been created, returns an empty list.
|
static |
Returns the name of the supplied OpenCL error code. For example, {CL_SUCCESS},
{CL_INVALID_CONTEXT}, etc.
|
static |
Return the singleton instance with no reference counting.
cl_int itk::OpenCLContext::GetLastError | ( | ) | const |
Returns the last OpenCL error that occurred while executing an operation on this context or any of the objects created by the context. Returns {CL_SUCCESS} if the last operation succeeded.
std::list< OpenCLImageFormat > itk::OpenCLContext::GetSupportedImageFormats | ( | const OpenCLImageFormat::ImageType | image_type, |
const cl_mem_flags | flags | ||
) | const |
Returns the list of supported image formats for processing images with the specified image type image_type and memory flags.
bool itk::OpenCLContext::IsCreated | ( | ) | const |
Returns true if the underlying OpenCL GetContextId() has been created, false otherwise.
cl_int itk::OpenCLContext::Marker | ( | const OpenCLEventList & | event_list | ) |
Enqueues a marker command which waits for either a list of events to complete, or if the list is empty it waits for all commands previously enqueued in command_queue to complete before it completes.
OpenCLEvent itk::OpenCLContext::MarkerAsync | ( | const OpenCLEventList & | event_list | ) |
Asynchronous version of the Marker() method. This function will queue the request and return immediately. Returns an OpenCLEvent object that can be used to wait for the request to finish. The request will not start until all of the events in event_list have been signaled as completed.
|
static |
This is a singleton pattern New. There will only be ONE reference to a OpenCLContext object per process. Clients that call this must call Delete on the object so that the reference counting will work. The single instance will be unreferenced when the program exits.
|
private |
|
protected |
|
virtual |
Releases this context, destroying it if the reference count is zero. Does nothing if the context has not been created or is already released.
void itk::OpenCLContext::ReportError | ( | const cl_int | code, |
const char * | fileName = "" , |
||
const int | lineNumber = 0 , |
||
const char * | location = "" |
||
) |
Report the error based on OpenCL error code with exception object.
void itk::OpenCLContext::SetCommandQueue | ( | const OpenCLCommandQueue & | queue | ) |
Sets the context's active command queue. If queue is null, then GetDefaultCommandQueue() will be used.
void itk::OpenCLContext::SetContextId | ( | cl_context | id | ) |
Sets the native OpenCL context identifier associated with this object to id. This function will call {clRetainContext()} to increase the reference count on id. If the identifier was previously set to something else, then
{clReleaseContext()} will be called on the previous value.
|
protected |
|
static |
Supply a user defined OpenCL context. Call ->Delete() on the supplied instance after setting it.
void itk::OpenCLContext::SetLastError | ( | const cl_int | error | ) |
Sets the last error code to error.
|
private |
|
static |
Waits on the host thread for commands identified by event objects in event_list to complete. A command is considered complete if its execution status is {CL_COMPLETE} or a negative value. The events specified in event_list act as synchronization points.
|
friend |
Definition at line 499 of file itkOpenCLContext.h.
|
friend |
Definition at line 502 of file itkOpenCLContext.h.
|
friend |
Definition at line 500 of file itkOpenCLContext.h.
|
friend |
Definition at line 501 of file itkOpenCLContext.h.
|
friend |
friends from OpenCL core
Definition at line 498 of file itkOpenCLContext.h.
|
friend |
Definition at line 503 of file itkOpenCLContext.h.
|
friend |
Definition at line 505 of file itkOpenCLContext.h.
|
friend |
Definition at line 504 of file itkOpenCLContext.h.
|
private |
Definition at line 472 of file itkOpenCLContext.h.
|
staticprivate |
Definition at line 473 of file itkOpenCLContext.h.
Generated on 1667476801 for elastix by 1.9.4 |