From 29bfa893cc148b4933996914f4628fd2bf487eed Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Tue, 12 Jan 2016 22:23:04 +0000 Subject: [CUDA] Add explicit mapping from sm_XX to compute_YY. Summary: This is used by D16082 when it invokes fatbinary. Reviewers: tra Subscribers: cfe-commits, jhen, echristo Differential Revision: http://reviews.llvm.org/D16097 llvm-svn: 257530 --- clang/lib/Driver/Action.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'clang/lib/Driver/Action.cpp') diff --git a/clang/lib/Driver/Action.cpp b/clang/lib/Driver/Action.cpp index 0117f8ab0be..e9490e96db8 100644 --- a/clang/lib/Driver/Action.cpp +++ b/clang/lib/Driver/Action.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "clang/Driver/Action.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Regex.h" #include @@ -50,6 +51,24 @@ 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") + .Default(nullptr); +} + void CudaDeviceAction::anchor() {} CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName, @@ -59,9 +78,12 @@ CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName, assert(IsValidGpuArchName(GpuArchName)); } +const char *CudaDeviceAction::getComputeArchName() const { + return GpuArchToComputeName(GpuArchName); +} + bool CudaDeviceAction::IsValidGpuArchName(llvm::StringRef ArchName) { - static llvm::Regex RE("^sm_[0-9]+$"); - return RE.match(ArchName); + return GpuArchToComputeName(ArchName.data()) != nullptr; } void CudaHostAction::anchor() {} -- cgit v1.2.3