https://github.com/oraluben created https://github.com/llvm/llvm-project/pull/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. This default is regularly updated, and the most recent configuration as of commit ab202aa sets it to `sm_52`. This value is also assumed when no `-march` option is provided. This PR does not address any compatibility issues between different CUDA versions. >From 9d6fe5f8522ddedde66525e93f4b66e547ddadc6 Mon Sep 17 00:00:00 2001 From: Yichen Yan <[email protected]> Date: Thu, 14 Mar 2024 19:43:49 +0800 Subject: [PATCH] [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" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
