[PATCH] D105295: [CUDA] Only allow NVIDIA offload-arch during CUDA compilation.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 1 10:00:25 PDT 2021


tra created this revision.
tra added a reviewer: yaxunl.
Herald added a subscriber: bixia.
tra requested review of this revision.
Herald added a project: clang.

Otherwise, if someone specifies a valid AMD arch, we may end up triggering an
assertion on unexpected arch later on.

Current tests didn't catch it because the failure does not get triggered with `-###`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105295

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cuda-bad-arch.cu


Index: clang/test/Driver/cuda-bad-arch.cu
===================================================================
--- clang/test/Driver/cuda-bad-arch.cu
+++ clang/test/Driver/cuda-bad-arch.cu
@@ -10,6 +10,8 @@
 // RUN: | FileCheck -check-prefix BAD %s
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_19 -c %s 2>&1 \
 // RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
 
 // BAD: error: Unsupported CUDA gpu architecture
 
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2785,7 +2785,7 @@
 
     StringRef getCanonicalOffloadArch(StringRef ArchStr) override {
       CudaArch Arch = StringToCudaArch(ArchStr);
-      if (Arch == CudaArch::UNKNOWN) {
+      if (Arch == CudaArch::UNKNOWN || !IsNVIDIAGpuArch(Arch)) {
         C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << ArchStr;
         return StringRef();
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105295.355927.patch
Type: text/x-patch
Size: 1083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210701/b61c6827/attachment.bin>


More information about the cfe-commits mailing list