[cfe-dev] [RfC] A proposal of adding SPIR-V Toolchain in Clang
Anastasia Stulova via cfe-dev
cfe-dev at lists.llvm.org
Mon Sep 10 08:10:19 PDT 2018
Hello,
Since 2015 Khronos has switched to the new portable intermediate format SPIR-V, which has replaced the original SPIR. The advantage is that it offers higher portability across different toolchains. There was a talk about it at a Dev Meeting:
http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#17
LLVM currently only supports SPIR format for OpenCL in Clang. Several Khronos vendors (ARM, AMD, Intel, Xilinx, Codeplay and others) are interested in adding support for SPIR-V, which should gradually replace the old SPIR once products are no longer shipped with the old format. Here is the detailed description:
https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang
To summarize, the idea is to add a SPIR-V target triple to Clang that can be used to generate a SPIR-V binary for OpenCL code. There was a separate thread regarding generation of SPIR-V binary and the community suggested that a translator from LLVM IR to SPIR-V can be used as an external tool, called llvm-spirv. This can be invoked similar to such tools as ptxas and fatbinary for the CUDA toolchain:
http://lists.llvm.org/pipermail/llvm-dev/2018-February/121440.html
An example of how Clang can be used to target SPIR-V:
clang -c test.cl -target spirv[32|64]-unknown-unknown -o test.spv
This will result in the following Clang actions:
(1) clang -cc1 -triple spirv[32|64]-unknown-unknown test.cl -emit-llvm-bc -o test.bc
(2) llvm-spirv test.bc -o test.spv
SPIR-V generation is essential for completion of OpenCL C++ support in Clang, as newer OpenCL standards require frontend invocation to be performed offline, producing the SPIR-V binary that can be then loaded at application execution time. Besides that, it will also allow Clang to be used as a complete standalone tool to generate portable binaries that can then be consumed by different proprietary toolchains. In addition, this will open a path to the LLVM backends for various languages and frontends that already generate SPIR-V.
A more detailed explanation of the complete design proposal is given in this Wiki page:
https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang
Looking forward to any feedback about the proposal or possible collaborations,
Thanks!
Anastasia
More information about the cfe-dev
mailing list