Closed oscarbg closed 5 years ago
Hi @oscarbg,
./llvm-spirv clpp.bc clppspir.spv
You need to use:
./llvm-spirv clcpp.bc -o clppspir.spv
# or
./llvm-spirv clcpp.bc # to get clcpp.spv file
Offline compilation into SPIR-V or device binary
- Generates SPIR-V 1.0 for most features
- Uses SPIR-V 1.2 where necessary
From personal experience, I would say it generates not only SPIR-V 1.0 in some cases. For example, if you have functions which accept arguments by reference in your OpenCL C++ code, SPIRV-LLVM-Translator will generate some additional decorations and will generate SPIR-V 1.1 binary.
can share when SPIR-V 1.2 instead of SPIR-V 1.0 is needed?
I'm not sure that there is some well-documented list of OpenCL C++ features that requires SPIR-V 1.2 instead of SPIR-V 1.0, but at least you can take a look at spec changelog to find some information.
also some additional argument to llmv-spirv or clang compilation steps is needed in such cases?
If I understand correctly, SPIRV-LLVM-Translator automatically selects resulting version based on features used in input file.
Unfortunately, there are no options to force min/max or required version of the resulting SPIR-V file. And that leads to a "hacks" like this one - this options allows you to generate SPIR-V 1.0 even if source code contains functions which accept arguments by reference.
Hi @AlexeySachkov , many thanks for very informative answer! now that I can generate SPIR-V binaries I will play a little with it..
Hi, seeing IWOCL keynote slides, interesting is the slide 20: C++ for OpenCL in Clang project it has a sample: https://godbolt.org/z/nGvxAC and a I see it uses SPIR target instead of SPIR-V I wanted to test if can have success generating SPIR-V output with SPIRV-LLVM-translator from that sample: so I name this kernel clcpp.cl:
and get latest clang-9 nightly form apt.llvm.org and latest SPIRV-LLVM-Translator-dev build available here (version.txt mentions commit: ece29378764c7b16c273276e62a61efad801c633).. then using:
as seems clang++-9 from apt.llvm.org doesn't accept -target spir-v anyway seems llvm-spirv can convert BC's using SPIR target also.. but then using:
I get:
So questions are:
any additional flags needed to pass to llvm-spirv or clang++-9 to fix this issue? SPIRV-LLVM translator is ready to translate C++ OCL kernels like this? finally also in slide I see:
so question is: can share when SPIR-V 1.2 instead of SPIR-V 1.0 is needed? also some additional argument to llmv-spirv or clang compilation steps is needed in such cases? I say because Intel Neo driver already has SPIR-V 1.2 support and wanted to test working support!
I attach bitcode in text form ( llvm-dis-9 <clppspir.bc) in case you want to explore also: