OpenCL compiler preprocessing definitions?

2019-07-11 03:59发布

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.

2条回答
Fickle 薄情
2楼-- · 2019-07-11 04:29

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.

查看更多
We Are One
3楼-- · 2019-07-11 04:36

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__
查看更多
登录 后发表回答