• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #if CUBLAS_VER_MAJOR >= 11
16 #include "third_party/gpus/cuda/include/cublas_v2.h"
17 #else
18 #include "third_party/gpus/cuda/include/cublas.h"
19 #endif
20 #include "third_party/gpus/cuda/include/cuda.h"
21 #include "tensorflow/stream_executor/lib/env.h"
22 #include "tensorflow/stream_executor/platform/dso_loader.h"
23 
24 // Implements the cuBLAS API by forwarding to cuBLAS loaded from the DSO.
25 // Note that it does not implement the v1 interface.
26 
27 namespace {
28 // Returns DSO handle or null if loading the DSO fails.
GetDsoHandle()29 void* GetDsoHandle() {
30 #ifdef PLATFORM_GOOGLE
31   return nullptr;
32 #else
33   static auto handle = []() -> void* {
34     auto handle_or = stream_executor::internal::DsoLoader::GetCublasDsoHandle();
35     if (!handle_or.ok()) return nullptr;
36     return handle_or.ValueOrDie();
37   }();
38   return handle;
39 #endif
40 }
41 
42 template <typename T>
LoadSymbol(const char * symbol_name)43 T LoadSymbol(const char* symbol_name) {
44   void* symbol = nullptr;
45   if (auto handle = GetDsoHandle()) {
46     stream_executor::port::Env::Default()
47         ->GetSymbolFromLibrary(handle, symbol_name, &symbol)
48         .IgnoreError();
49   }
50   return reinterpret_cast<T>(symbol);
51 }
52 
LogFatalSymbolNotFound(const char * symbol_name)53 void LogFatalSymbolNotFound(const char* symbol_name) {
54   LOG(FATAL) << symbol_name << " symbol not found.";
55 }
56 
GetSymbolNotFoundError()57 cublasStatus_t GetSymbolNotFoundError() { return CUBLAS_STATUS_INTERNAL_ERROR; }
58 }  // namespace
59 
60 #if CUDA_VERSION < 9000
61 typedef enum {} cublasMath_t;
62 #endif
63 
64 #if CUDA_VERSION < 10000
65 #include "tensorflow/stream_executor/cuda/cublas_9_0.inc"
66 #elif CUDA_VERSION < 10010
67 #include "tensorflow/stream_executor/cuda/cublas_10_0.inc"
68 #elif CUDA_VERSION < 10020
69 #include "tensorflow/stream_executor/cuda/cublas_10_1.inc"
70 #elif CUDA_VERSION < 11000
71 #include "tensorflow/stream_executor/cuda/cublas_10_2.inc"
72 #else
73 #include "tensorflow/stream_executor/cuda/cublas_11_0.inc"
74 #endif
75