OpenCL compiler preprocessing definitions?

I am developing OpenCL code on Snow Leopard and I understand that OpenCL compilation is instantly done by Clang / LLVM. Is the C preprocessor used at all? Is there a way to set preprocessing definitions in the compiler? What are the definitions?

I would like the code to know if it is compiled for CPU or GPU, so I can, for example, use printf commands to debug.

+2


source to share


2 answers


The API clBuildProgram

takes compiler arguments (parameter const char * options

).

-D MYMACRO

, so -D MYMACRO=value

.



As for the predefined macros, see the OpenCL specification for a complete list (section 6.9). Non-exhaustive list:

  • __FILE__

  • __LINE__

  • __OPENCL_VERSION__

+5


source


You can also use the OpenCL preprocessor to define definitions (for example in C):

#define dot3(x1, y1, z1, x2, y2, z2) ((x1)*(x2) + (y1)*(y2) + (z1)*(z2))

      



(note the parentheses, they are important because you can put any expression in variables and the expression is evaluated correctly)

This helps to improve the speed of your application.

+1


source







All Articles