diff options
author | Justin Lebar <jlebar@google.com> | 2016-01-12 22:23:04 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-01-12 22:23:04 +0000 |
commit | 29bfa893cc148b4933996914f4628fd2bf487eed (patch) | |
tree | dac6a1a0b23ba2067480618b2b3af58d5f1ea7d8 /clang/lib/Driver/Action.cpp | |
parent | ba3a4f917f2d99edabd2dd8045587379c48b5787 (diff) | |
download | bcm5719-llvm-29bfa893cc148b4933996914f4628fd2bf487eed.tar.gz bcm5719-llvm-29bfa893cc148b4933996914f4628fd2bf487eed.zip |
[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
Diffstat (limited to 'clang/lib/Driver/Action.cpp')
-rw-r--r-- | clang/lib/Driver/Action.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
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 <cassert> @@ -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<const char *>(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() {} |