Embedding OpenCL C code in C++
masterOpenCL-Wrapper allows embedding OpenCL C code directly into C++ using a stringification macro R(...). This preserves syntax highlighting in most editors.
Important Syntax Rules:
- Stringification: The macro
R(...)converts arguments to string literals. It converts' 'to' '. - Length Limits: Because string literals cannot be arbitrarily long, you must interrupt them periodically using the
)+R(pattern. - Unbalanced Brackets: To use unbalanced brackets like
(or), exit the macro and insert the literal manually:... ) + "void func(" + R( .... - Preprocessor Macros: Standard preprocessor replacement macros (e.g.,
#define VAR 42) do not work inside theR(...)macro. Instead, pass these values directly to theDeviceconstructor. - Switch Macros: To use
#defineor#ifdefinside the kernel code, you must manually exit and re-enter theR(...)macro.