OpenCL 编译器预处理定义?
我正在 Snow Leopard 上开发 OpenCL 代码,并且了解 OpenCL 即时编译是由 Clang/LLVM 完成的。是否使用了 C 预处理器?有没有办法使用编译器设置预处理定义?存在哪些定义?
我希望代码知道它是为 CPU 还是 GPU 编译的,这样我就可以使用 printf 语句进行调试。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
clBuildProgram
API 采用编译器参数(const char * options
参数)。-D MYMACRO
可以理解,-D MYMACRO=value
也可以理解。至于预定义的宏,请参阅 OpenCL 规范的完整列表(第 6.9 节)。非详尽列表:
__FILE__
__LINE__
__OPENCL_VERSION__
the
clBuildProgram
API takes compiler arguments (theconst 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__
您还可以使用 OpenCL“预处理器”来定义定义(就像在 C 中一样):(
注意括号,它们很重要,因为您可以在变量中插入任何表达式,并且表达式会被正确计算)
这有助于提高您的速度应用。
You can also use the OpenCL "preprocessor" to define definitions (like in C):
(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.