Skip to content

Commit cd35858

Browse files
jhuber6tstellar
authored andcommitted
[NVPTX] Fix NVPTX output name in the driver with -save-temps
Summary: Currently, OpenMP and direct compilation uses an NVPTX toolchain to directly invoke the CUDA tools from Clang to do the assembling and linking of NVPTX codes. This breaks under `-save-temps` because of a workaround. The `nvlink` linker does not accept `.o` files, so we need to be selective when we output these. The previous logic keyed off of presense in the temp files and wasn't a great solution. Change this to just query the input args for `-c` to see if we stop at the assembler. Fixes #60767
1 parent e0ffaab commit cd35858

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,8 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
446446
std::string OutputFileName = TC.getInputFilename(Output);
447447

448448
// If we are invoking `nvlink` internally we need to output a `.cubin` file.
449-
// Checking if the output is a temporary is the cleanest way to determine
450-
// this. Putting this logic in `getInputFilename` isn't an option because it
451-
// relies on the compilation.
452449
// FIXME: This should hopefully be removed if NVIDIA updates their tooling.
453-
if (Output.isFilename() &&
454-
llvm::find(C.getTempFiles(), Output.getFilename()) !=
455-
C.getTempFiles().end()) {
450+
if (!C.getInputArgs().getLastArg(options::OPT_c)) {
456451
SmallString<256> Filename(Output.getFilename());
457452
llvm::sys::path::replace_extension(Filename, "cubin");
458453
OutputFileName = Filename.str();

clang/test/Driver/cuda-cross-compiling.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
//
4444
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -c -### %s 2>&1 \
4545
// RUN: | FileCheck -check-prefix=OBJECT %s
46+
// RUN: %clang -target nvptx64-nvidia-cuda -save-temps -march=sm_61 -c -### %s 2>&1 \
47+
// RUN: | FileCheck -check-prefix=OBJECT %s
4648

4749
// OBJECT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
4850
// OBJECT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[OBJ:.+]].o" "[[PTX]].s" "-c"

0 commit comments

Comments
 (0)