正确的方式编译OpenCL应用程序并使用可用的编译器选项 [英] Proper way of compiling OpenCL applications and using available compiler options

查看:438
本文介绍了正确的方式编译OpenCL应用程序并使用可用的编译器选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenCL的新手。



编译OpenCL项目的最佳方式是什么?
$ b


  1. 使用受支持的编译器( GCC Clang ):

    <当我们使用编译器
    (比如 gcc clang )时,我们如何控制这些选项?它们是
    吗?必须在源代码中设置,或者,我们可以通过命令行传递它们的正常
    编译流程。查看 Khornos-Manual-1.2 < a>,为优化提供了 cl_int clBuildProgram 的几个选项。 :

      gcc | clang -O3 -I< INCLUDES> OpenCL_app.c -framework OpenCL OPTION -lm 

    其实,我试过这个并收到一个错误: p>

      gcc:error:无法识别的命令行选项'< OPTION>'
    openclc :

  2. >我看到有人使用 openclc 来编译使用
    a
    Makefile

我想知道哪个是最好的方法(如果
实际上有两种不同的方式) ,以及我们如何控制不同编译时选项的
使用。

您可能知道,但它是重要的是要重申。 OpenCL标准包含两件事:
$ b $ ol
OpenCL C语言和编程模型(我认为最近的标准包括一些C ++)
  • OpenCL主机库来管理设备

  • gcc clang 是OpenCL项目主机端的编译器。因此,使用主机编译器将无法为OpenCL设备代码编译提供编译器选项,因为他们甚至不知道任何OpenCL。
    clang 外,有一个接受OpenCL设备代码的标志,包含内核的.cl文件。这样,如果我没有记错的话,你可以使用 clang 并提供标志和选项,但现在你可以使用llvm IR或 SPIR 输出不是设备可执行对象。然后,您可以使用设备的运行环境(opencl驱动程序)将 SPIR 对象加载到设备中。
    您可以检出以下链接:

    使用Clang编译内核



    Llvm IR代

    SPIR



    其他选择是使用您的目标平台提供的工具。声称支持opencl的每个厂商都应该有一个运行时环境。通常,他们有单独的CLI工具来编译OpenCL设备代码。在你的情况下(我猜)你有苹果公司的驱动程序,因此你有 openclc



    以英特尔CLI为例

    现在到你的主要问题(最好的方式来编译opencl)。这取决于你想要做什么。你没有具体说明你有什么需求,所以我不得不推测。



    如果你想在没有主机程序的情况下进行脱机编译,上面的考虑将会帮你。否则,您必须使用OpenCL库并为您的内核进行联机编译,这通常是需要可移植性的产品的首选。因为如果您在程序开始时编译所有内核,则可以直接使用提供的环境,而无需为每个目标平台提供库。

    因此,如果你有OpenCL项目,你必须决定如何编译。如果你真的想使用通用标志而不依赖第三方工具。我建议你有一个类来构建你的内核并提供你想要的标志。


    I am a newbie in OpenCL stuffs.

    Whats is the best way to compiler an OpenCL project ?

    1. Using a supported compiler (GCC or Clang):

      When we use a compiler like gcc or clang, how do we control these options? Are they have to be set inside the source code, or, likewise the normal compilation flow we can pass them on the command line. Looking at the Khornos-Manual-1.2, there are a few options provided for cl_int clBuildProgram for optimizations. :

      gcc|clang -O3 -I<INCLUDES> OpenCL_app.c -framework OpenCL OPTION -lm
      

      Actually, I Tried this and received an error :

      gcc: error: unrecognized command line option '<OPTION>'
      

    2. Alternatively, using openclc:

      I have seen people using openclc to compiler using a Makefile.

    I would like to know which is the best way (if there are actually two separate ways), and how do we control the usage of different compile time options.

    解决方案

    You might be aware but it is important to reiterate. OpenCL standard contains two things:

    1. OpenCL C language and programming model (I think recent standard include some C++)
    2. OpenCL host library to manage device

    gcc and clang are compilers for the host side of your OpenCL project. So there will be no way to provide compiler options for OpenCL device code compilations using a host compiler since they are not even aware of any OpenCL. Except with clang there is a flag that accept OpenCL device code, .cl file which contains the kernels. That way you can use clang and provide also the flags and options if I remember correctly, but now you would have either llvm IR or SPIR output not an device executable object. You can then load SPIR object to a device using device's run-time environment(opencl drivers). You can checkout these links:

    Using Clang to compile kernels

    Llvm IR generation

    SPIR

    Other alternative is to use the tools provided by your target platform. Each vendor that claims to support opencl, should have a run-time environment. Usually, they have separate CLI tools to compile OpenCL device code. In you case(I guess) you have drivers from Apple, therefore you have openclc.

    Intel CLI as an example

    Now to your main question (best way to compile opencl). It depends what you want to do. You didn't specify what kind of requirements you have so I had to speculate.

    If you want to have off-line compilation without a host program, the considerations above will help you. Otherwise, you have to use OpenCL library and have on-line compilation for you kernels, this is generally preferred for products that needs portability. Since if you compile all your kernels at the start of your program, you directly use the provided environment and you don't need to provide libraries for each target platform.

    Therefore, if you have an OpenCL project, you have to decide how to compile. If you really want to use the generic flags and do not rely on third party tools. I suggest you to have a class that builds your kernels and provides the flags you want.

    这篇关于正确的方式编译OpenCL应用程序并使用可用的编译器选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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