Skip to content

Commit

Permalink
[NVPTX] Add -march=general option to mirror default configuration (#…
Browse files Browse the repository at this point in the history
…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 <huberjn@outlook.com>
  • Loading branch information
oraluben and jhuber6 committed Mar 15, 2024
1 parent d5a277d commit 047b2b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,12 @@ NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
if (!llvm::is_contained(*DAL, A))
DAL->append(A);

// TODO: We should accept 'generic' as a valid architecture.
if (!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) {
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
CudaArchToString(CudaArch::CudaDefault));
} else if (DAL->getLastArgValue(options::OPT_march_EQ) == "generic" &&
OffloadKind == Action::OFK_None) {
DAL->eraseArg(options::OPT_march_EQ);
} else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
auto GPUsOrErr = getSystemGPUArchs(Args);
if (!GPUsOrErr) {
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/cuda-cross-compiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@
//
// RUN: not %clang -target nvptx64-nvidia-cuda %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=MISSING %s
// RUN: not %clang -target nvptx64-nvidia-cuda -march=generic %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=MISSING %s

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

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

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

0 comments on commit 047b2b2

Please sign in to comment.