Skip to content

Commit 047b2b2

Browse files
oralubenjhuber6
andauthored
[NVPTX] Add -march=general option to mirror default configuration (#85222)
This PR adds `-march=generic` support for the NVPTX backend. This fulfills a TODO introduced in #79873. With this PR, users can explicitly request the "default" CUDA architecture, which makes sure that no specific architecture is specified. This PR does not address any compatibility issues between different CUDA versions. --------- Co-authored-by: Joseph Huber <[email protected]>
1 parent d5a277d commit 047b2b2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,12 @@ NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
750750
if (!llvm::is_contained(*DAL, A))
751751
DAL->append(A);
752752

753-
// TODO: We should accept 'generic' as a valid architecture.
754753
if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
755754
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
756755
CudaArchToString(CudaArch::CudaDefault));
756+
} else if (DAL->getLastArgValue(options::OPT_march_EQ) == "generic" &&
757+
OffloadKind == Action::OFK_None) {
758+
DAL->eraseArg(options::OPT_march_EQ);
757759
} else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
758760
auto GPUsOrErr = getSystemGPUArchs(Args);
759761
if (!GPUsOrErr) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@
8080
//
8181
// RUN: not %clang -target nvptx64-nvidia-cuda %s -### 2>&1 \
8282
// RUN: | FileCheck -check-prefix=MISSING %s
83+
// RUN: not %clang -target nvptx64-nvidia-cuda -march=generic %s -### 2>&1 \
84+
// RUN: | FileCheck -check-prefix=MISSING %s
8385

8486
// MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 'ptxas'
8587
// MISSING: error: Must pass in an explicit nvptx64 gpu architecture to 'nvlink'
8688

8789
// RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
8890
// RUN: | FileCheck -check-prefix=GENERIC %s
91+
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c %s -### 2>&1 \
92+
// RUN: | FileCheck -check-prefix=GENERIC %s
8993

9094
// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"

0 commit comments

Comments
 (0)