[llvm-dev] Execute OpenCL

Enrique González via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 8 01:31:14 PDT 2019


Hi Alexey,

I have finally build successfully the SPIRV-LLVM-Translator project inside
the llvm-project, but i still cannot compile a OpenCL code file into a
spirv format because of the lack of the spirv64 target.

I attach the error when trying to use spirv64 target:

enrique at enrique-VirtualBox:~/Escritorio/OpenCL_Projects/opencl-example/helloworld$
clang++ -Xclang -finclude-default-header --target=spir64-unknown-unknown
HelloWorld_Kernel.cl
error: unable to create target: 'No available targets are compatible with
triple "spir64-unknown-unknown"'
1 error generated.

Thanks in advance.

El jue., 3 oct. 2019 a las 12:59, Sachkov, Alexey (<alexey.sachkov at intel.com>)
escribió:

> Hi Enrique,
>
>
>
> > I have been trying to use clang with the spir64 target
> (soir64-unknown-unknown) and the tool does not detect this target, i do not
> know why.
>
> It is hard to say anything without additional information. Please provide
> command you are trying to launch
>
>
>
> > I also tried to build also SPIRV-LLVM-Translator project[2] and it fails
> when making the project. It does not encounter the Polly library and fails.
>
> Again, it is hard to help without any additional information or logs
>
>
>
> *From:* Enrique González <enrike.gonzalez.98 at gmail.com>
> *Sent:* Wednesday, October 2, 2019 6:19 PM
> *To:* Sachkov, Alexey <alexey.sachkov at intel.com>; llvm-dev at lists.llvm.org
> *Subject:* Re: [llvm-dev] Execute OpenCL
>
>
>
> Hello everyone,
>
>
>
> I have been trying to use clang with the spir64 target
> (soir64-unknown-unknown) and the tool does not detect this target, i do not
> know why.
>
>
>
> I have tried to install SPIR-V Tool project[1] and it still does no detect
> the target I
>
>
>
> I also tried to build also SPIRV-LLVM-Translator project[2] and it fails
> when making the project. It does not encounter the Polly library and fails.
>
>
>
> Could someone help me with this problem?
>
>
>
> Thanks in advance.
>
>
>
> References:
>
> [1] https://github.com/KhronosGroup/SPIRV-Tools
>
> [2] https://github.com/KhronosGroup/SPIRV-LLVM-Translator
>
>
>
> El lun., 30 sept. 2019 a las 12:34, Sachkov, Alexey (<
> alexey.sachkov at intel.com>) escribió:
>
> Hi Enrique,
>
>
>
> I’m afraid I’m not very familiar with POCL and its details.
>
>
>
> + Pekka here, who is the main POCL maintainer (if I understand correctly)
> and I guess he can help you there better than me.
>
>
>
> *From:* Enrique González <enrike.gonzalez.98 at gmail.com>
> *Sent:* Sunday, September 29, 2019 7:51 PM
> *To:* Sachkov, Alexey <alexey.sachkov at intel.com>
> *Subject:* Re: [llvm-dev] Execute OpenCL
>
>
>
> Hi Alexey,
>
>
>
> Many thanks for your grateful replies, you are helping me a lot with all
> this information about my problem!
>
>
>
> I am looking the documentation about OpenCL for understanding it better,
> the YouTube video was also very helpful.
>
>
>
> During this days, I have tried to install SPIR-V target for making the
> hybrid compilation and prove how it could be optimized. Also I installed
> POCL (and an old LLVM version, so it requires one between 4.0 and 8.0). I
> have read the documentation at their page and it does not seems to say
> anything about how you can use this tool for optimize code, my boss neither
> has find anything, and we are looking for some site where we can learn how
> to use it and which flags we can prove for diferente results, because POCL
> looks like the tool we need for OpenCL pipeline optimizations.
>
>
>
> Could you help us with this problem too? We are a little bit lost about
> this and if we solve this problem, I can begin the project we have in mind
> to help the community.
>
>
>
> Thanks in advance.
>
>
>
> El jue., 26 sept. 2019 a las 14:05, Sachkov, Alexey (<
> alexey.sachkov at intel.com>) escribió:
>
> Hi Enrique,
>
>
>
> > 1) What do yourefer by OpenCL RT?
>
> I mean OpenCL Runtime – some library which implements OpenCL API for you.
>
>
> Basically, OpenCL consist of two parts: host code and device code.
>
> Host code can be written at any language and actually it is a regular
> C/C++/Python/whatever application which uses OpenCL API.
>
>
>
> OpenCL API allows you to select platform, device, create context and
> buffers for data, create and build program for your device, create command
> queue and kernel, set kernel arguments and then enqueue your kernel for
> execution on the selected device.
>
> You can always read the spec [1] to understand all these concepts. I would
> recommend section 3 “The OpenCL Architecture”: in particular, section 3.1
> “Platform Model” and 3.2 “Execution Model”.
>
> Also you can find some videos [2], slides [3] or articles [4] about this
> topic.
>
>
>
> So, the next part is device code: it can be written on OpenCL C, C++ for
> OpenCL in clang, or any other language which can be represented in SPIR-V.
>
> As I said in previous emails, device code can be compiled online or
> offline and then it will be launched on selected device using API.
>
>
>
> I encourage you to read the spec or search for videos/slides/articles on
> this topic to get familiar with main OpenCL concepts/architecture/ideas.
>
>
>
> > 2) Could you give me some examples of an open-source OpenCL
> implementation and update optimization pipeline?
>
> Sure, here you go (there might be more implementations, I’m just not aware
> of them):
>
>
>
>    - POCL [5]
>    - Intel graphics compute runtime and compiler [6] and [7]
>    - ROCm [8]. I guess compiler sources are located in corresponding
>    forks of llvm [9] and clang [10]
>    - VC4CL [11]
>
>
>
> Please note that each implementation targets specific device or set of
> devices from one or more particular vendors.
>
> The most generic/portable one is POCL, I guess.
>
>
>
>
>
> [1]: https://www.khronos.org/registry/OpenCL/specs/2.2/pdf/OpenCL_API.pdf
>
> [2]: https://www.youtube.com/watch?v=hUiX8rBcNzw
>
> [3]:
> https://www.fz-juelich.de/SharedDocs/Downloads/IAS/JSC/EN/slides/opencl/opencl-03-basics.pdf?__blob=publicationFile
>
> [4]: https://www.sciencedirect.com/topics/computer-science/opencl
>
>
>
> [5]: https://github.com/pocl/pocl
>
> [6]: https://github.com/intel/compute-runtime
>
> [7]: https://github.com/intel/intel-graphics-compiler
>
> [8]: https://github.com/RadeonOpenCompute/ROCm-OpenCL-Runtime
>
> [9]: https://github.com/RadeonOpenCompute/llvm
>
> [10]: https://github.com/RadeonOpenCompute/clang
>
> [11]: https://github.com/doe300/VC4CL
>
>
>
>
>
> *From:* Enrique González <enrike.gonzalez.98 at gmail.com>
> *Sent:* Thursday, September 26, 2019 2:41 PM
> *To:* Sachkov, Alexey <alexey.sachkov at intel.com>; llvm-dev at lists.llvm.org
> *Subject:* Re: [llvm-dev] Execute OpenCL
>
>
>
> 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
>
>
> --------------------------------------------------------------------
> 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
>
>
> --------------------------------------------------------------------
> 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
>
>
> --------------------------------------------------------------------
> 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/20191008/e3409e91/attachment.html>


More information about the llvm-dev mailing list