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 #include "cuda/include/cublas.h" 16 #include "cuda/include/cuda.h" 17 #include "tensorflow/stream_executor/lib/env.h" 18 #include "tensorflow/stream_executor/platform/dso_loader.h" 19 20 // Implements the cuBLAS API by forwarding to cuBLAS loaded from the DSO. 21 // Note that it does not implement the v1 interface. 22 23 namespace { 24 // Returns DSO handle or null if loading the DSO fails. GetDsoHandle()25void* GetDsoHandle() { 26 #ifdef PLATFORM_GOOGLE 27 return nullptr; 28 #else 29 static auto handle = []() -> void* { 30 auto handle_or = stream_executor::internal::DsoLoader::GetCublasDsoHandle(); 31 if (!handle_or.ok()) return nullptr; 32 return handle_or.ValueOrDie(); 33 }(); 34 return handle; 35 #endif 36 } 37 38 template <typename T> LoadSymbol(const char * symbol_name)39T LoadSymbol(const char* symbol_name) { 40 void* symbol = nullptr; 41 if (auto handle = GetDsoHandle()) { 42 stream_executor::port::Env::Default() 43 ->GetSymbolFromLibrary(handle, symbol_name, &symbol) 44 .IgnoreError(); 45 } 46 return reinterpret_cast<T>(symbol); 47 } 48 LogFatalSymbolNotFound(const char * symbol_name)49void LogFatalSymbolNotFound(const char* symbol_name) { 50 LOG(FATAL) << symbol_name << " symbol not found."; 51 } 52 GetSymbolNotFoundError()53cublasStatus_t GetSymbolNotFoundError() { return CUBLAS_STATUS_INTERNAL_ERROR; } 54 } // namespace 55 56 #if CUDA_VERSION < 9000 57 typedef enum {} cublasMath_t; 58 #endif 59 60 // Parameter constness changed in cuBLAS 9.2 61 #if CUDA_VERSION < 9020 62 #include "tensorflow/stream_executor/cuda/cublas_9_0.inc" 63 #else 64 #include "tensorflow/stream_executor/cuda/cublas_10_0.inc" 65 #endif 66