[llvm-dev] Execute OpenCL

Enrique González via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 26 04:40:35 PDT 2019


Hi Alexey,

Your reply has been a great help to me,your way of explain the different
types of compilation is very detailed and easy to understand.

Even so, I have a couple of questions.

1) What do yourefer by OpenCL RT?

2) Could you give me some examples of an open-source OpenCL implementation
and update optimization pipeline?

Thank you in advance. Regards

El vie., 20 sept. 2019 a las 12:34, Sachkov, Alexey (<
alexey.sachkov at intel.com>) escribió:

> Hi Enrique,
>
>
>
> > First, I only want to compile a project and execute it to see how it
> works, specifically this one:
> https://github.com/rsnemmen/OpenCL-examples/tree/master/add_numbers
>
> As I can see, it has a Makefile which you could use. Anyway, on Linux you
> need to do something like:
>
> clang -std=c99 add_numbers.c -lOpenCL -I/path/to/folder/with/CL/cl.h
>
>
>
> Usually, libOpenCL.so and CL/cl.h are provided by OpenCL SDKs from HW/SW
> vendor, for example: [1], [2], [3], [4] and others [5]
>
> But, you can also get them from KhronosGroup repos: OpenCL-ICD-Loader [6],
> OpenCL-Headers [7]
>
>
>
> > I want to do that the .c file uses the .cl that i have compiled before
> with clang and i do not know how to do it.
>
>
>
> This is an interesting question. Basically, in OpenCL you can build your
> device program in a separate ways:
>
>
>
>    1. Use clCreateProgramFromSource + clBuildProgram: this is so-called
>    “online” compilation, when your device code is written in OpenCL C and its
>    compilation is performed in runtime (all stages like front-end, middle-end
>    optimizations and back-end, i.e. codegen to native code)
>    2. Use clCreateProgramWithBinary + clBuildProgram: this is so-called
>    “offline” compilation, where you build your device code manually prior
>    launching the app. Unfortunately, OpenCL spec doesn’t define binary format,
>    i.e. it is implementation-defined. Usually each vendor provides so-called
>    “offline compiler” tool which allows you to get device binary for your
>    OpenCL code – the binary is not portable across different devices/vendors
>    3. Use clCreateProgramWithIL + clBuildProgram: requires OpenCL 2.1 or
>    cl_khr_il_program extension. Allows you to create program from SPIR-V.
>    Basically, this is kind of combination of online and offline models: one
>    the one side, you need to launch offline compiler to parse source code and
>    get SPIR-V, on the other side, SPIR-V is an intermediate representation,
>    i.e. partially-compiled program – that will save some runtime resources.
>    Plus, SPIR-V is a standard and it is portable between devices/vendors.
>
>
>
> Summarizing:
>
>    - There are several OpenCL implementations (both open-source and
>    closed-source) which are LLVM-based
>    - Not sure that a lot of them provide possibility to create OpenCL
>    program from pure LLVM IR produced by clang
>
>
>
> If you want to optimize your OpenCL code by yourself you can do the
> following:
>
>    - Try to understand binary format that is accepted by OpenCL runtime
>    you are using: try to contact support/forums to check if you can pass
>    already optimized LLVM BC there (BTW, not sure that this functionality is
>    widely supported)
>    - Get LLVM IR from clang, then optimize it as you want, then convert
>    it to SPIR-V and pass to OpenCL RT
>    - Find open-source OpenCL implementation and update optimization
>    pipeline in there with you own modifications
>
>
>
> Personally, I would go with the last option.
>
>
>
>
>
> [1]: https://software.intel.com/en-us/opencl-sdk
>
> [2]: https://developer.nvidia.com/opencl
>
> [3]: https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases
>
> [4]: https://developer.arm.com/solutions/graphics/apis/opencl
>
> [5]: https://www.iwocl.org/resources/opencl-implementations/
>
>
>
> [6]: https://github.com/KhronosGroup/OpenCL-ICD-Loader
>
> [7]: https://github.com/KhronosGroup/OpenCL-Headers
>
>
>
>
>
> *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> *On Behalf Of *Enrique
> Gonzalez via llvm-dev
> *Sent:* Thursday, September 19, 2019 11:41 PM
> *To:* llvm-dev at lists.llvm.org
> *Subject:* [llvm-dev] Execute OpenCL
>
>
>
> Dear all,
>
>
>
> After a huge amount of time trying to install LLVM and Clang i could
> finally do it, so now im trying to use this tools for generating a
> bytecode, then apply it modular optimizations and then generate an
> executable to test the result.
>
>
>
> First, I only want to compile a project and execute it to see how it
> works, specifically this one:
> https://github.com/rsnemmen/OpenCL-examples/tree/master/add_numbers
>
>
>
> Which commands would you use?
>
>
>
> I want to do that the .c file uses the .cl that i have compiled before
> with clang and i do not know how to do it.
>
>
>
> Thanks in advance.
>
>
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park,
> 17 Krylatskaya Str., Bldg 4, Moscow 121614,
> Russian Federation
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>


-- 
Un saludo

Enrique González
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190926/0e583c7b/attachment-0001.html>


More information about the llvm-dev mailing list