darktable  3.0.0.rc0
About: darktable is an open source photography workflow application and RAW developer. A virtual lighttable and darkroom for photographers. Release candidate.
  Fossies Dox: darktable-3.0.0.rc0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

darktable Documentation

Introduction

For many large applications C++ is the language of choice and so it seems reasonable to define C++ bindings for OpenCL.

The interface is contained with a single C++ header file cl.hpp and all definitions are contained within the namespace cl. There is no additional requirement to include cl.h and to use either the C++ or original C bindings it is enough to simply include cl.hpp.

The bindings themselves are lightweight and correspond closely to the underlying C API. Using the C++ bindings introduces no additional execution overhead.

For detail documentation on the bindings see:

The OpenCL C++ Wrapper API 1.1 (revision 04) http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.1.pdf

Example

The following example shows a general use case for the C++ bindings, including support for the optional exception feature and also the supplied vector and string classes, see following sections for descriptions of these features.

#define __CL_ENABLE_EXCEPTIONS
#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/cl.hpp>
#else
#include <CL/cl.hpp>
#endif
#include <cstdio>
#include <cstdlib>
#include <iostream>
const char * helloStr = "__kernel void "
"hello(void) "
"{ "
" "
"} ";
int
main(void)
{
try {
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.size() == 0) {
std::cout << "Platform size 0\n";
return -1;
}
cl_context_properties properties[] =
{ CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
cl::Context context(CL_DEVICE_TYPE_CPU, properties);
std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
std::make_pair(helloStr,strlen(helloStr)));
cl::Program program_ = cl::Program(context, source);
program_.build(devices);
cl::Kernel kernel(program_, "hello", &err);
cl::Event event;
cl::CommandQueue queue(context, devices[0], 0, &err);
queue.enqueueNDRangeKernel(
NULL,
&event);
event.wait();
}
catch (cl::Error err) {
std::cerr
<< "ERROR: "
<< err.what()
<< "("
<< err.err()
<< ")"
<< std::endl;
}
return EXIT_SUCCESS;
}
cl::Kernel
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2288
cl::Platform::get
static cl_int get(std::vector< Platform > *platforms)
Definition: cl.hpp:1389
cl_int
int32_t cl_int
Definition: cl_platform.h:230
cl::Program
Program interface that implements cl_program.
Definition: cl.hpp:2385
cl::Context
Definition: cl.hpp:1416
CL_CONTEXT_DEVICES
#define CL_CONTEXT_DEVICES
Definition: cl.h:438
main
int main(int argc, char **argv)
Definition: sse_test.c:21
cl::CommandQueue
CommandQueue interface for cl_command_queue.
Definition: cl.hpp:2558
cl::Event
Event interface for cl_event.
Definition: cl.hpp:1536
cl::NDRange
NDRange interface.
Definition: cl.hpp:2210
kernel
static float kernel(const float *x, const float *y)
Definition: colorchecker.c:433
CL_SUCCESS
#define CL_SUCCESS
Definition: cl.h:186
cl::Program::Sources
std::vector< std::pair< const char *, ::size_t > > Sources
Definition: cl.hpp:2389
cl::Program::build
cl_int build(const std::vector< Device > &devices, const char *options=NULL, void(*notifyFptr)(cl_program, void *)=NULL, void *data=NULL) const
Definition: cl.hpp:2458
CL_DEVICE_TYPE_CPU
#define CL_DEVICE_TYPE_CPU
Definition: cl.h:284
cl.hpp
C++ bindings for OpenCL 1.0 (rev 48) and OpenCL 1.1 (rev 33)
cl::NullRange
static const NDRange NullRange
Definition: cl.hpp:2246
CL_CONTEXT_PLATFORM
#define CL_CONTEXT_PLATFORM
Definition: cl.h:445
cl_context_properties
intptr_t cl_context_properties
Definition: cl.h:81