r257413 - [CUDA] Reject values for --cuda-gpu-arch that are not of the form /sm_\d+/.
Justin Lebar via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 11 15:27:14 PST 2016
Author: jlebar
Date: Mon Jan 11 17:27:13 2016
New Revision: 257413
URL: http://llvm.org/viewvc/llvm-project?rev=257413&view=rev
Log:
[CUDA] Reject values for --cuda-gpu-arch that are not of the form /sm_\d+/.
Reviewers: tra
Subscribers: cfe-commits, jhen, echristo
Differential Revision: http://reviews.llvm.org/D16079
Added:
cfe/trunk/test/Driver/cuda-bad-arch.cu
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/Action.h
cfe/trunk/lib/Driver/Action.cpp
cfe/trunk/lib/Driver/Driver.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=257413&r1=257412&r2=257413&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Mon Jan 11 17:27:13 2016
@@ -22,6 +22,7 @@ def err_drv_unknown_stdin_type_clang_cl
def err_drv_unknown_language : Error<"language not recognized: '%0'">;
def err_drv_invalid_arch_name : Error<
"invalid arch name '%0'">;
+def err_drv_cuda_bad_gpu_arch : Error<"Unsupported CUDA gpu architecture: %0">;
def err_drv_invalid_thread_model_for_target : Error<
"invalid thread model '%0' in '%1' for this target">;
def err_drv_invalid_linker_name : Error<
Modified: cfe/trunk/include/clang/Driver/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Action.h?rev=257413&r1=257412&r2=257413&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Action.h (original)
+++ cfe/trunk/include/clang/Driver/Action.h Mon Jan 11 17:27:13 2016
@@ -15,6 +15,9 @@
#include "llvm/ADT/SmallVector.h"
namespace llvm {
+
+class StringRef;
+
namespace opt {
class Arg;
}
@@ -133,7 +136,7 @@ public:
class CudaDeviceAction : public Action {
virtual void anchor();
- /// GPU architecture to bind -- e.g 'sm_35'.
+ /// GPU architecture to bind. Always of the form /sm_\d+/.
const char *GpuArchName;
/// True when action results are not consumed by the host action (e.g when
/// -fsyntax-only or --cuda-device-only options are used).
@@ -145,6 +148,8 @@ public:
const char *getGpuArchName() const { return GpuArchName; }
bool isAtTopLevel() const { return AtTopLevel; }
+ static bool IsValidGpuArchName(llvm::StringRef ArchName);
+
static bool classof(const Action *A) {
return A->getKind() == CudaDeviceClass;
}
Modified: cfe/trunk/lib/Driver/Action.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Action.cpp?rev=257413&r1=257412&r2=257413&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Action.cpp (original)
+++ cfe/trunk/lib/Driver/Action.cpp Mon Jan 11 17:27:13 2016
@@ -9,6 +9,7 @@
#include "clang/Driver/Action.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Regex.h"
#include <cassert>
using namespace clang::driver;
using namespace llvm::opt;
@@ -54,7 +55,14 @@ void CudaDeviceAction::anchor() {}
CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName,
bool AtTopLevel)
: Action(CudaDeviceClass, Input), GpuArchName(ArchName),
- AtTopLevel(AtTopLevel) {}
+ AtTopLevel(AtTopLevel) {
+ assert(IsValidGpuArchName(GpuArchName));
+}
+
+bool CudaDeviceAction::IsValidGpuArchName(llvm::StringRef ArchName) {
+ static llvm::Regex RE("^sm_[0-9]+$");
+ return RE.match(ArchName);
+}
void CudaHostAction::anchor() {}
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=257413&r1=257412&r2=257413&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Jan 11 17:27:13 2016
@@ -1297,8 +1297,12 @@ static Action *buildCudaActions(Compilat
if (!A->getOption().matches(options::OPT_cuda_gpu_arch_EQ))
continue;
A->claim();
- if (GpuArchNames.insert(A->getValue()).second)
- GpuArchList.push_back(A->getValue());
+
+ const auto& Arch = A->getValue();
+ if (!CudaDeviceAction::IsValidGpuArchName(Arch))
+ C.getDriver().Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << Arch;
+ else if (GpuArchNames.insert(Arch).second)
+ GpuArchList.push_back(Arch);
}
// Default to sm_20 which is the lowest common denominator for supported GPUs.
Added: cfe/trunk/test/Driver/cuda-bad-arch.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-bad-arch.cu?rev=257413&view=auto
==============================================================================
--- cfe/trunk/test/Driver/cuda-bad-arch.cu (added)
+++ cfe/trunk/test/Driver/cuda-bad-arch.cu Mon Jan 11 17:27:13 2016
@@ -0,0 +1,34 @@
+// Checks errors generated by passing a bad value for --cuda-gpu-arch.
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=compute_20 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=foo_20 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm20 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_abc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_20a -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_a20 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=ssm_20 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_ -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD %s
+
+// BAD: error: Unsupported CUDA gpu architecture
+
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_2 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix OK %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix OK %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_999 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix OK %s
+// RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix OK %s
+
+// OK-NOT: error: Unsupported CUDA gpu architecture
More information about the cfe-commits
mailing list