views:

370

answers:

2

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

I would like the code to be aware of whether it is compiled for CPU or GPU so I for instance can use printf statements for debugging.

+5  A: 

the clBuildProgram API takes compiler arguments (the const char * options parameter).

-D MYMACRO is understood, so is -D MYMACRO=value.

As to what predefined macros, see the OpenCL specification for a full list (Section 6.9). A non exhaustive list:

  • __FILE__
  • __LINE__
  • __OPENCL_VERSION__
Bahbar
A: 

You can also use the OpenCL "preprocessor" to define definitions (like in C):

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

(notice the brackets, they are important because you can insert any Expression in the Variables and the expression gets correctly evaluated)

This helps to improve the speed of your Application.

Quonux