Skip to content

Commit 3b52341

Browse files
committed
[CUDA] Fix output name being replaced in device-only mode
When performing device only compilation, there was an issue where `cubin` outputs were being renamed to `cubin` despite the user's name. This is required in a normal compilation flow as the Nvidia tools only understand specific filenames instead of checking magic bytes for some unknown reason. We do not want to perform this transformation when the user is performing device only compilation. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D131278
1 parent 6635f48 commit 3b52341

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,8 @@ CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
693693

694694
std::string CudaToolChain::getInputFilename(const InputInfo &Input) const {
695695
// Only object files are changed, for example assembly files keep their .s
696-
// extensions.
697-
if (Input.getType() != types::TY_Object)
696+
// extensions. If the user requested device-only compilation don't change it.
697+
if (Input.getType() != types::TY_Object || getDriver().offloadDeviceOnly())
698698
return ToolChain::getInputFilename(Input);
699699

700700
// Replace extension for object files with cubin because nvlink relies on

clang/test/Driver/cuda-bindings.cu

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,14 @@
135135
// RUN: | FileCheck -check-prefix=DASM2 %s
136136
// DASM2: # "nvptx64-nvidia-cuda" - "clang",{{.*}} output: "cuda-bindings-cuda-nvptx64-nvidia-cuda-sm_30.s"
137137
// DASM2: # "nvptx64-nvidia-cuda" - "clang",{{.*}} output: "cuda-bindings-cuda-nvptx64-nvidia-cuda-sm_35.s"
138+
139+
//
140+
// Ensure we output the user's specified name in device-only mode.
141+
//
142+
// RUN: %clang -target powerpc64le-ibm-linux-gnu -### \
143+
// RUN: --cuda-gpu-arch=sm_52 --cuda-device-only -c -o foo.o %s 2>&1 \
144+
// RUN: | FileCheck -check-prefix=D_ONLY %s
145+
// RUN: %clang -target powerpc64le-ibm-linux-gnu -### --offload-new-driver \
146+
// RUN: --cuda-gpu-arch=sm_52 --cuda-device-only -c -o foo.o %s 2>&1 \
147+
// RUN: | FileCheck -check-prefix=D_ONLY %s
148+
// D_ONLY: "foo.o"

0 commit comments

Comments
 (0)