OpenCL compiler preprocessing definitions?

旧街凉风 提交于 2019-12-11 03:52:09

问题


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.


回答1:


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__



回答2:


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.



来源:https://stackoverflow.com/questions/1545510/opencl-compiler-preprocessing-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!