CTL
0.6.1
Computed Tomography Library
|
The OpenCLFunctions class provides additional OpenCL C functions. More...
#include <openclfunctions.h>
Classes | |
class | OpenCLFunction |
Representation of a single OpenCL C function. More... | |
Public Types | |
using | OpenCLFunctionGen = OpenCLFunction(*)() |
Public Member Functions | |
OpenCLFunctions (std::initializer_list< OpenCLFunctionGen > functionList) | |
OpenCLFunctions (OpenCLFunctionGen function) | |
const std::vector< OpenCLFunction > & | functions () const |
std::string | declarations () const |
std::string | declarationsAndDefinitions () const |
Static Public Member Functions | |
static OpenCLFunction | atomic_addf_g () |
static OpenCLFunction | atomic_addf_l () |
static OpenCLFunction | write_bufferf () |
Private Attributes | |
std::vector< OpenCLFunction > | _functions |
The list of OpenCL C functions. | |
The OpenCLFunctions class provides additional OpenCL C functions.
Instances of the ClFileLoader class represent collections of OpenCL C functions, which may be used in an OpenCL program and in particular in the implementation of OpenCL kernel code. Such an instance can be passed to the OCL::OpenCLConfig::addKernel
function in order to equip a kernel with the according additional OpenCL functions. By this approach, additional functions are made available to the OpenCL programmer that are not standardized in OpenCL C.
The functions that are available are represented by a list of static
member functions of the OpenCLFunctions class. This list may be extended during the development of the CTL toolkit. An instance of a OpenCLFunctions object is created using the constructor, eg.
Here, myFunctions
represents a set consisting of the two functions write_bufferf
and atomic_addf_l
. This object can be passed when creating a kernel:
Note that by using this approach, it is is also possible that the internal implementation of a function provided by OpenCLFunctions uses other functions from OpenCLFunctions, as long as all required functions are passed to the addKernel
function (all function declarations will be prefixed to the kernel source code, followed by all definitions).
CTL::OpenCLFunctions::OpenCLFunctions | ( | std::initializer_list< OpenCLFunctionGen > | functionList | ) |
Constructs a OpenCLFunctions instance from an std::initializer_list
functionList. An example use case is given by
As this constructor is implicit, the right-hand side of the aboves code can be also directly passed to the OpenCLConfig::addKernel
function.
The input type std::initializer_list
has OpenCLFunctionGen
as template argument. This helper class defines a function type (generator function) with the signature of the static
functions provided by the OpenCLFunctions class, which in turn, when invoked, return the actual OpenCLFunction
object. The invocation of the generator functions in functionList is performed in this constructor and the returned OpenCLFunction
objects are stored internally.
CTL::OpenCLFunctions::OpenCLFunctions | ( | OpenCLFunctionGen | function | ) |
Constructs a OpenCLFunctions instance that contains a single function. An example use case is given by
As this constructor is implicit, the right-hand side of the aboves code can be also directly passed to the OpenCLConfig::addKernel
function.
The input type OpenCLFunctionGen
defines a function type (generator function) with the signature of the static
functions provided by the OpenCLFunctions class, which in turn, when invoked, return the actual OpenCLFunction
object. The invocation of the generator function is performed in this constructor and the returned OpenCLFunction
object is stored internally.
An instance of OpenCLFunctions may be also constructed from a custom function using a lambda expression:
|
static |
inline void atomic_addf_g(volatile global float* addr, float val)
This function is supposed to extend the capabilities of the built-in function atomic_add
. The built-in function works only with integer types, whereas this function works with float
. In an atomic manner it does the following: It reads the 32-bit value floating point value stored at location pointed by addr
. It computes the sum with val
and stores back the result to the location pointed by addr
.
Internally, the implementation uses atomic_cmpxchg
in a loop. Depending on the simultaneous write accesses to the location addr
(by other workers), the function may take several iterations to terminate.
The _g
in the function name indicates that it can only be used with an addr
pointing to global
qualified memory. For local
memory, see atomic_addf_l
.
Note that this function does not return anything in contrast to the OpenCL built-in function.
|
static |
inline void atomic_addf_l(volatile local float* addr, float val)
This function is supposed to extend the capabilities of the built-in function atomic_add
. The built-in function works only with integer types, whereas this function works with float
. In an atomic manner it does the following: It reads the 32-bit value floating point value stored at location pointed by addr
. It computes the sum with val
and stores back the result to the location pointed by addr
.
Internally, the implementation uses atomic_cmpxchg
in a loop. Depending on the simultaneous write accesses to the location addr
(by other workers), the function may take several iterations to terminate.
The _l
in the function name indicates that it can only be used with an addr
pointing to local
qualified memory. For global
memory, see atomic_addf_g
.
Note that this function does not return anything in contrast to the OpenCL built-in function.
std::string CTL::OpenCLFunctions::declarations | ( | ) | const |
Returns all declarations of the internally handled OpenCLFunction
s as a single string.
std::string CTL::OpenCLFunctions::declarationsAndDefinitions | ( | ) | const |
Returns all declarations of the internally handled OpenCLFunction
s followed by all definitions of these functions as a single string.
const std::vector< OpenCLFunctions::OpenCLFunction > & CTL::OpenCLFunctions::functions | ( | ) | const |
Returns the list of the internally stored OpenCLFunction
s.
|
static |
void write_bufferf(global float* buffer, int4 coord, float color, image3d_t image)
This function imitates the behavior of the function write_imagef
for buffers of vectorized 3d float images instead of image3d_t
. Unlike write_imagef
, the extension cl_khr_3d_image_writes
does not need to be implemented for write_bufferf
.
Note that no bounds checking is performed on coord
.
In contrast to write_imagef
, the color
argument is a single float
value.
The extents of the 3d image are inherited from the last argument image
.