[clang] [NVPTX] Add `-march=general` option to mirror default configuration (PR #85222)
Yichen Yan via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 14 06:13:14 PDT 2024
https://github.com/oraluben updated https://github.com/llvm/llvm-project/pull/85222
>From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001
From: Yichen Yan <wenji.yyc at alibaba-inc.com>
Date: Thu, 14 Mar 2024 19:43:49 +0800
Subject: [PATCH 1/2] [NVPTX] Add `-march=general` option to mirror default
configuration
---
clang/lib/Driver/ToolChains/Cuda.cpp | 4 ++--
clang/test/Driver/cuda-cross-compiling.c | 9 +++++++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index c6007d3cfab864..4cb98f9f28963c 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,8 +750,8 @@ 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) {
+ if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) ||
+ (DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
CudaArchToString(CudaArch::CudaDefault));
} else if (DAL->getLastArgValue(options::OPT_march_EQ) == "native") {
diff --git a/clang/test/Driver/cuda-cross-compiling.c b/clang/test/Driver/cuda-cross-compiling.c
index 086840accebe7f..e5aeca8300f85c 100644
--- a/clang/test/Driver/cuda-cross-compiling.c
+++ b/clang/test/Driver/cuda-cross-compiling.c
@@ -32,10 +32,15 @@
//
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=ARGS %s
+// RUN: %clang -target nvptx64-nvidia-cuda -march=generic -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=GENERIC %s
// ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
// ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
// ARGS-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_61" {{.*}} "[[CUBIN]].cubin"
+// GENERIC: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_52" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
+// GENERIC-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_52" "--output-file" "[[CUBIN:.+]].cubin" "[[PTX]].s" "-c"
+// GENERIC-NEXT: nvlink{{.*}}"-o" "a.out" "-arch" "sm_52" {{.*}} "[[CUBIN]].cubin"
//
// Test the generated arguments to the CUDA binary utils when targeting NVPTX.
@@ -85,6 +90,6 @@
// 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: | FileCheck -check-prefix=COMPILE %s
-// GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
+// COMPILE-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"
>From ecea39a30bf3b3fb6a11744bf4888b49ccc66179 Mon Sep 17 00:00:00 2001
From: Yichen Yan <wenji.yyc at alibaba-inc.com>
Date: Thu, 14 Mar 2024 21:13:02 +0800
Subject: [PATCH 2/2] fmt
---
clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 4cb98f9f28963c..6114e4f015ab35 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -750,7 +750,8 @@ NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
if (!llvm::is_contained(*DAL, A))
DAL->append(A);
- if ((!DAL->hasArg(options::OPT_march_EQ) && OffloadKind != Action::OFK_None) ||
+ if ((!DAL->hasArg(options::OPT_march_EQ) &&
+ OffloadKind != Action::OFK_None) ||
(DAL->getLastArgValue(options::OPT_march_EQ) == "generic")) {
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
CudaArchToString(CudaArch::CudaDefault));
More information about the cfe-commits
mailing list