From fd3a1ac0e29c9bffc20391cf10ba006fff501b12 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Wed, 6 Jul 2016 21:21:39 +0000 Subject: [CUDA] Add utility functions for dealing with CUDA versions / architectures. Summary: Currently our handling of CUDA architectures is scattered all around clang. This patch centralizes it. A key advantage of this centralization is that you can now write a C++ switch on e.g. CudaArch and get a compile error if you don't handle one of the enum values. Reviewers: tra Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D21867 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274681 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Action.cpp | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'lib/Driver/Action.cpp') diff --git a/lib/Driver/Action.cpp b/lib/Driver/Action.cpp index f9e1024f92..425f315ccd 100644 --- a/lib/Driver/Action.cpp +++ b/lib/Driver/Action.cpp @@ -51,43 +51,11 @@ void BindArchAction::anchor() {} BindArchAction::BindArchAction(Action *Input, const char *_ArchName) : Action(BindArchClass, Input), ArchName(_ArchName) {} -// Converts CUDA GPU architecture, e.g. "sm_21", to its corresponding virtual -// compute arch, e.g. "compute_20". Returns null if the input arch is null or -// doesn't match an existing arch. -static const char* GpuArchToComputeName(const char *ArchName) { - if (!ArchName) - return nullptr; - return llvm::StringSwitch(ArchName) - .Cases("sm_20", "sm_21", "compute_20") - .Case("sm_30", "compute_30") - .Case("sm_32", "compute_32") - .Case("sm_35", "compute_35") - .Case("sm_37", "compute_37") - .Case("sm_50", "compute_50") - .Case("sm_52", "compute_52") - .Case("sm_53", "compute_53") - .Case("sm_60", "compute_60") - .Case("sm_61", "compute_61") - .Case("sm_62", "compute_62") - .Default(nullptr); -} - void CudaDeviceAction::anchor() {} -CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName, +CudaDeviceAction::CudaDeviceAction(Action *Input, CudaArch Arch, bool AtTopLevel) - : Action(CudaDeviceClass, Input), GpuArchName(ArchName), - AtTopLevel(AtTopLevel) { - assert(!GpuArchName || IsValidGpuArchName(GpuArchName)); -} - -const char *CudaDeviceAction::getComputeArchName() const { - return GpuArchToComputeName(GpuArchName); -} - -bool CudaDeviceAction::IsValidGpuArchName(llvm::StringRef ArchName) { - return GpuArchToComputeName(ArchName.data()) != nullptr; -} + : Action(CudaDeviceClass, Input), GpuArch(Arch), AtTopLevel(AtTopLevel) {} void CudaHostAction::anchor() {} -- cgit v1.2.3