[CUDA] Allow targeting NVPTX directly without a host toolchain
authorJoseph Huber <jhuber6@vols.utk.edu>
Thu, 15 Dec 2022 20:49:09 +0000 (14:49 -0600)
committerJoseph Huber <jhuber6@vols.utk.edu>
Thu, 19 Jan 2023 00:18:25 +0000 (18:18 -0600)
commit0660397e68096a64279b19f913e7de2c283e524f
tree7dcfb067148167be1f8002fe6f823a13924272e5
parentf0e7ae085fa51c3acb3abd852f534880877b5753
[CUDA] Allow targeting NVPTX directly without a host toolchain

Currently, the NVPTX compilation toolchain can only be invoked either
through CUDA or OpenMP via `--offload-device-only`. This is because we
cannot build a CUDA toolchain without an accompanying host toolchain for
the offloading. When using `--target=nvptx64-nvidia-cuda` this results
in generating calls to the GNU assembler and linker, leading to errors.

This patch abstracts the portions of the CUDA toolchain that are
independent of the host toolchain or offloading kind into a new base
class called `NVPTXToolChain`. We still need to read the host's triple
to build the CUDA installation, so if not present we just assume it will
match the host's system for now, or the user can provide the path
explicitly.

This should allow the compiler driver to create NVPTX device images
directly from C/C++ code.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D140158
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h
clang/test/Driver/cuda-cross-compiling.c [new file with mode: 0644]