包括头文件到OpenCL .cl文件 [英] include headers to OpenCL .cl file

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

问题描述

我在 .cl 文件中编写了OpenCL内核。它试图 #include 几个标题。



编译失败,因为包含的头文件找不到 。
我知道 clBuildProgram 可以使用 -I dir 选项,该选项添加目录<$ c

在khronus网站论坛中,这篇文章 http://www.khronos.org/message_boards/viewtopic.php?f=37& ; t = 2535 谈论这个问题。他们建议使用 clCreateProgramWithSource ,它指定所有来源(包括.h文件)。



我对这个问题有疑问:


  1. 哪个选项更好? ( clBuildProgram clCreateProgramWithSource ,如上所述)

  2. 如果我使用 clCreateProgramWithSource 编译器如何知道要包含什么?我的意思是,哪个源代表包含文件名?

  3. 如果我使用 clBuildProgram ,并且有几个包含include文件的目录,是否指定它们?
  4. code> clCreateProgramWithSource()后跟 clBuildProgram()



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

    cl_program 对象被输入到 clBuildProgram()



    clBuildProgram()允许您指定包含include文件
    目录的编译器选项。在你的情况下,对于头文件包含,它将像字符串一样:

      -I myincludedir1 -I myincludedir2 ... 

    使用的编译器是 OpenCL中的内部OpenCL编译器您正在使用的SDK 。因此,如果您的
    使用 AMD的SDK ,那么将使用 OpenCL SDK 的一部分 AMD OpenCL编译器。对于 Nvidia 英特尔也是如此。

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


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

    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.

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

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

    I have a questions regarding this issue:

    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 requires you use clCreateProgramWithSource() followed by clBuildProgram().

    ClCreateProgramWithSource() creates and returns a cl_program object.

    That cl_program object is input into 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  ...
    

    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.

    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天全站免登陆