开发者

OpenCL compiler preprocessing definitions?

开发者 https://www.devze.com 2022-12-08 17:44 出处:网络
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 pre

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.


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__


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消