Sets up an OpenCL environment.
More...
#include <CLUtils.hpp>
|
| CLEnv (const std::vector< std::string > &kernel_filenames=std::vector< std::string >(), const char *build_options=nullptr) |
|
| CLEnv (const std::string &kernel_filename, const char *build_options=nullptr) |
| Delegating constructor. More...
|
|
cl::Context & | getContext (unsigned int pIdx=0) |
| Gets back one of the existing contexts. More...
|
|
cl::CommandQueue & | getQueue (unsigned int ctxIdx=0, unsigned int qIdx=0) |
| Gets back one of the existing command queues in the specified context. More...
|
|
cl::Program & | getProgram (unsigned int pgIdx=0) |
| Gets back one of the existing programs. More...
|
|
cl::Kernel & | getKernel (const char *kernelName, unsigned int pgIdx=0) |
| Gets back one of the existing kernels in some program. More...
|
|
cl::Context & | addContext (unsigned int pIdx, const bool gl_shared=false) |
| Creates a context for all devices in the requested platform. More...
|
|
cl::CommandQueue & | addQueue (unsigned int ctxIdx, unsigned int dIdx, cl_command_queue_properties props=0) |
| Creates a queue for the specified device in the specified context. More...
|
|
cl::CommandQueue & | addQueueGL (unsigned int ctxIdx, cl_command_queue_properties props=0) |
| Creates a queue for the GL-shared device in the specified context. More...
|
|
cl::Kernel & | addProgram (unsigned int ctxIdx, const std::vector< std::string > &kernel_filenames, const char *kernel_name=nullptr, const char *build_options=nullptr) |
| Creates a program for the specified context. More...
|
|
cl::Kernel & | addProgram (unsigned int ctxIdx, const std::string &kernel_filename, const char *kernel_name=nullptr, const char *build_options=nullptr) |
|
|
std::vector< cl::Platform > | platforms |
|
std::vector< std::vector< cl::Device > > | devices |
| List of devices per platform. More...
|
|
Sets up an OpenCL environment.
Prepares the essential OpenCL objects for the execution of kernels. This class aims to allow rapid prototyping by hiding away all the boilerplate code necessary for establishing an OpenCL environment.
clutils::CLEnv::CLEnv |
( |
const std::vector< std::string > & |
kernel_filenames = std::vector<std::string> () , |
|
|
const char * |
build_options = nullptr |
|
) |
| |
It initializes the OpenCL environment. If a kernel_filenames
argument is provided, it creates a context for all the devices in the first platform, and a command queue for the first device in that platform. It also builds a program object from all the requested kernel files, and extracts all kernels in that program.
- Parameters
-
[in] | kernel_filenames | a vector of strings with the names of the kernel files (.cl). |
[in] | build_options | options that are forwarded to the OpenCL compiler. |
clutils::CLEnv::CLEnv |
( |
const std::string & |
kernel_filename, |
|
|
const char * |
build_options = nullptr |
|
) |
| |
Delegating constructor.
- Parameters
-
[in] | kernel_filename | a string with the name of the kernel file (.cl). |
[in] | build_options | options that are forwarded to the OpenCL compiler. |
cl::Context & clutils::CLEnv::addContext |
( |
unsigned int |
pIdx, |
|
|
const bool |
gl_shared = false |
|
) |
| |
Creates a context for all devices in the requested platform.
It allows to create a GL-shared context. If GL-Sharing is not supported for the associated device, an exception is thrown. It also calls initGLMemObjects
to initialize the GL buffers.
- Parameters
-
[in] | pIdx | an index for the platform for which to create the context. Indices follow the order the platforms got returned in by the OpenCL runtime. |
[in] | gl_shared | a flag for whether or not to create a GL-shared CL context. |
- Returns
- A reference to the created context.
cl::Kernel & clutils::CLEnv::addProgram |
( |
unsigned int |
ctxIdx, |
|
|
const std::vector< std::string > & |
kernel_filenames, |
|
|
const char * |
kernel_name = nullptr , |
|
|
const char * |
build_options = nullptr |
|
) |
| |
Creates a program for the specified context.
- Parameters
-
[in] | ctxIdx | the index of the context the program is associated with. Indices follow the order the contexts were created in. |
[in] | kernel_filenames | a vector of strings with the names of the kernel files (.cl). |
[in] | kernel_name | the name of a requested kernel. |
[in] | build_options | options that are forwarded to the OpenCL compiler. |
- Returns
- The requested kernel. If kernel_name is NULL, the first kernel of the program gets returned.
cl::Kernel & clutils::CLEnv::addProgram |
( |
unsigned int |
ctxIdx, |
|
|
const std::string & |
kernel_filename, |
|
|
const char * |
kernel_name = nullptr , |
|
|
const char * |
build_options = nullptr |
|
) |
| |
- Parameters
-
[in] | ctxIdx | the index of the context the program is associated with. Indices follow the order the contexts were created in. |
[in] | kernel_filename | a string with the name of the kernel file (.cl). |
[in] | kernel_name | the name of a requested kernel. |
[in] | build_options | options that are forwarded to the OpenCL compiler. |
- Returns
- The requested kernel. If kernel_name is NULL, the first kernel of the program gets returned.
- See also
- addProgram
cl::CommandQueue & clutils::CLEnv::addQueue |
( |
unsigned int |
ctxIdx, |
|
|
unsigned int |
dIdx, |
|
|
cl_command_queue_properties |
props = 0 |
|
) |
| |
Creates a queue for the specified device in the specified context.
- Parameters
-
[in] | ctxIdx | the index of the context the device is handled by. Indices follow the order the contexts were created in. |
[in] | dIdx | the index of the device among those handled by the specified context. Indices follow the order the devices got returned in by the call to getDevices on the proper platform. |
[in] | props | bitfield to enable command queue properties. |
- Returns
- A reference to the created queue.
cl::CommandQueue & clutils::CLEnv::addQueueGL |
( |
unsigned int |
ctxIdx, |
|
|
cl_command_queue_properties |
props = 0 |
|
) |
| |
Creates a queue for the GL-shared device in the specified context.
- Parameters
-
[in] | ctxIdx | the index of the context the GL-shared device is handled by. Indices follow the order the contexts were created in. |
[in] | props | bitfield to enable command queue properties. |
- Returns
- A reference to the created queue.
cl::Context & clutils::CLEnv::getContext |
( |
unsigned int |
pIdx = 0 | ) |
|
Gets back one of the existing contexts.
- Parameters
-
[in] | pIdx | an index for the context. Indices follow the order the contexts were created in. |
- Returns
- The requested context.
cl::Kernel & clutils::CLEnv::getKernel |
( |
const char * |
kernel_name, |
|
|
unsigned int |
pgIdx = 0 |
|
) |
| |
Gets back one of the existing kernels in some program.
- Parameters
-
[in] | kernel_name | the name of the kernel. |
[in] | pgIdx | the index of the program the kernel belongs to. Indices follow the order the programs were created in. |
- Returns
- The requested kernel.
- See also
- kernelIdx
cl::Program & clutils::CLEnv::getProgram |
( |
unsigned int |
pgIdx = 0 | ) |
|
Gets back one of the existing programs.
- Parameters
-
[in] | pgIdx | the index of the requested program object. Indices follow the order the programs were created in. |
- Returns
- The requested program.
cl::CommandQueue & clutils::CLEnv::getQueue |
( |
unsigned int |
ctxIdx = 0 , |
|
|
unsigned int |
qIdx = 0 |
|
) |
| |
Gets back one of the existing command queues in the specified context.
- Parameters
-
[in] | ctxIdx | the index for the context the requested queue is in. Indices follow the order the contexts were created in. |
[in] | qIdx | an index for the command queue. Indices follow the order the queues were created in. |
- Returns
- The requested command queue.
virtual void clutils::CLEnv::initGLMemObjects |
( |
| ) |
|
|
inlineprotectedvirtual |
Initializes the OpenGL memory buffers.
If CL-GL interop is desirable, CLEnv has to be derived and initGLMemObjects
be implemented. initGLMemObjects
will have to create all necessary OpenGL memory buffers.
- Note
- Setting up CL-GL interop requires the following procedure: (i) Initialize OpenGL context, (ii) Initilize OpenCL context, (iii) Create OpenGL buffers, (iv) Create OpenCL buffers.
-
Do not call
initGLMemObjects
directly. initGLMemObjects
will be called by addContext
when it is asked for a GL-shared CL context to be created.
std::vector< std::vector<cl::Device> > clutils::CLEnv::devices |
List of devices per platform.
Holds a vector of devices per platform.
std::vector<cl::Platform> clutils::CLEnv::platforms |
The documentation for this class was generated from the following files: