llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Yichen Yan (oraluben) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/85222.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+2-2) - (modified) clang/test/Driver/cuda-cross-compiling.c (+7-2) ``````````diff 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" `````````` </details> https://github.com/llvm/llvm-project/pull/85222 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits