OpenCL 编译器预处理定义?

发布于 2024-08-06 19:05:14 字数 168 浏览 1 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坦然微笑 2024-08-13 19:05:14

clBuildProgram API 采用编译器参数(const char * options 参数)。

-D MYMACRO 可以理解,-D MYMACRO=value 也可以理解。

至于预定义的宏,请参阅 OpenCL 规范的完整列表(第 6.9 节)。非详尽列表:

  • __FILE__
  • __LINE__
  • __OPENCL_VERSION__

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__
记忆消瘦 2024-08-13 19:05:14

您还可以使用 OpenCL“预处理器”来定义定义(就像在 C 中一样):(

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

注意括号,它们很重要,因为您可以在变量中插入任何表达式,并且表达式会被正确计算)

这有助于提高您的速度应用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文