[HIPSPV][3/4] Enable SPIR-V emission for HIP
authorYaxun (Sam) Liu <yaxun.liu@amd.com>
Fri, 17 Dec 2021 16:01:51 +0000 (11:01 -0500)
committerYaxun (Sam) Liu <yaxun.liu@amd.com>
Mon, 20 Dec 2021 15:45:09 +0000 (10:45 -0500)
commita6786cdd575701ec1a1bc42adc086cfb70201ad3
tree136ca6d252b2a72e4d4fa7ad804da57c265e6768
parent9cd55c7c3463fea334fd3169023bb63cca7276e5
[HIPSPV][3/4] Enable SPIR-V emission for HIP

This patch enables SPIR-V binary emission for HIP device code via the
HIPSPV tool chain.

‘--offload’ option, which is envisioned in [1], is added for specifying
offload targets. This option is used to override default device target
(amdgcn-amd-amdhsa) for HIP compilation for emitting device code as
SPIR-V binary. The option is handled in getHIPOffloadTargetTriple().

getOffloadingDeviceToolChain() function (based on the design in the
SYCL repository) is added to select HIPSPVToolChain when HIP offload
target is ‘spirv64’.

The HIPActionBuilder is modified to produce LLVM IR at the backend
phase. HIPSPV tool chain expects to receive HIP device code as LLVM
IR so it can run external LLVM passes over them. HIPSPV TC is also
responsible for emitting the SPIR-V binary.

A Cuda GPU architecture ‘generic’ is added. The name is picked from
the LLVM SPIR-V Backend. In the HIPSPV code path the architecture
name is inserted to the bundle entry ID as target ID. Target ID is
expected to be always present so a component in the target triple
is not mistaken as target ID.

Tests are added for checking the HIPSPV tool chain.

[1]: https://lists.llvm.org/pipermail/cfe-dev/2020-December/067362.html

Patch by: Henry Linjamäki

Reviewed by: Yaxun Liu, Artem Belevich, Alexey Bader

Differential Revision: https://reviews.llvm.org/D110622
21 files changed:
clang/include/clang/Basic/Cuda.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.td
clang/lib/Basic/Cuda.cpp
clang/lib/Basic/Targets/NVPTX.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/Driver/Driver.cpp
clang/test/Driver/Inputs/hipspv-dev-lib/a/a.bc [new file with mode: 0644]
clang/test/Driver/Inputs/hipspv-dev-lib/b/b.bc [new file with mode: 0644]
clang/test/Driver/Inputs/hipspv-dev-lib/hipspv-spirv64.bc [new file with mode: 0644]
clang/test/Driver/Inputs/hipspv/bin/.hipVersion [new file with mode: 0644]
clang/test/Driver/Inputs/hipspv/lib/hip-device-lib/hipspv-spirv64.bc [new file with mode: 0644]
clang/test/Driver/Inputs/hipspv/lib/libLLVMHipSpvPasses.so [new file with mode: 0644]
clang/test/Driver/Inputs/pass-plugin.so [new file with mode: 0644]
clang/test/Driver/hipspv-device-libs.hip [new file with mode: 0644]
clang/test/Driver/hipspv-pass-plugin.hip [new file with mode: 0644]
clang/test/Driver/hipspv-toolchain-rdc.hip [new file with mode: 0644]
clang/test/Driver/hipspv-toolchain.hip [new file with mode: 0644]
clang/test/Driver/invalid-offload-options.cpp [new file with mode: 0644]