将标头包含到 OpenCL .cl 文件中 [英] include headers to OpenCL .cl file

查看:31
本文介绍了将标头包含到 OpenCL .cl 文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .cl 文件中编写了一个 OpenCL 内核.它尝试 #include 几个标头.

I've written an OpenCL kernel in a .cl file. It attempts to #include several headers.

它的编译失败,因为包含的头文件找不到".我知道 clBuildProgram 可以采用 -I dir 选项,它将目录 dir 添加到要搜索标头的目录列表中文件.

Its compilation fails, since the included header files are "not found". I am aware that clBuildProgram can take the -I dir option, which adds the directory dir to the list of directories to be searched for the header files.

在 khronus 网站论坛中发布此帖子 http://www.khronos.org/message_boards/viewtopic.php?f=37&t=2535 谈到了这个问题.

In the khronus site forum this post http://www.khronos.org/message_boards/viewtopic.php?f=37&t=2535 talks about the issue.

他们建议使用 clCreateProgramWithSource 来指定所有来源(包括 .h 文件).

They propose to use clCreateProgramWithSource which specifies all sources (including .h files).

我对此问题有疑问:

  1. 哪个选项更好?(clBuildProgram vs. clCreateProgramWithSource,如上所述)
  2. 如果我使用 clCreateProgramWithSource,编译器如何知道要包含什么?我的意思是,哪个来源代表哪个包含的文件名?
  3. 如果我使用 clBuildProgram 并且有多个包含包含文件的目录,我该如何指定它们?
  1. Which option is better? (clBuildProgram vs. clCreateProgramWithSource, as described above)
  2. If I use clCreateProgramWithSource how does the compiler know what to include? I mean, which source stands for which included file name?
  3. If I use clBuildProgram and there are several directories with include files, how do I specify them?

推荐答案

OpenCL 要求您使用 clCreateProgramWithSource() 后跟 clBuildProgram().

OpenCL requires you use clCreateProgramWithSource() followed by clBuildProgram().

ClCreateProgramWithSource() 创建并返回一个 cl_program 对象.

ClCreateProgramWithSource() creates and returns a cl_program object.

cl_program 对象被输入到 clBuildProgram().

clBuildProgram() 允许您指定包含包含文件的编译器选项目录.在您的情况下,对于头文件包含,它将类似于字符串:

clBuildProgram() allows you to specify compiler options which include the include file directories. In your case, for header file includes, it will be something like the string:

-I myincludedir1 -I myincludedir2  ...

使用的编译器是您正在使用的 OpenCL SDK 中的内部 OpenCL 编译器.所以如果你正在使用 AMD 的 SDK,将使用作为其 OpenCL SDK 一部分的 AMD OpenCL 编译器.NvidiaIntel 也是如此.

The compiler used is the internal OpenCL compiler in the OpenCL SDK you are using. So if you are using AMD's SDK, the AMD OpenCL compiler that is part of their OpenCL SDK will be used. Likewise for Nvidia or Intel.

检查所有 OpenCL 函数调用的 OpenCL 状态代码很重要.这是 clCreateProgramWithSource()clBuildProrgam() 必须获得的任何编译器错误或消息.还有一个完整的其他位代码要编写获取消息的大小,然后自行检索消息.

Its important to check the OpenCL status code for ALL OpenCL function calls. This is mandatory for clCreateProgramWithSource() and clBuildProrgam() to get any compiler errors or messages. There is a whole other bit code to write to get the size of the messages and then retrieve the messages themselves.

这篇关于将标头包含到 OpenCL .cl 文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆