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 16 // Common DSO loading functionality: exposes callables that dlopen DSOs 17 // in either the runfiles directories 18 19 #ifndef TENSORFLOW_STREAM_EXECUTOR_DSO_LOADER_H_ 20 #define TENSORFLOW_STREAM_EXECUTOR_DSO_LOADER_H_ 21 22 #include <vector> 23 24 #include "absl/strings/string_view.h" 25 #include "absl/synchronization/mutex.h" 26 #include "tensorflow/stream_executor/lib/status.h" 27 #include "tensorflow/stream_executor/lib/statusor.h" 28 #include "tensorflow/stream_executor/platform.h" 29 #include "tensorflow/stream_executor/platform/port.h" 30 31 namespace stream_executor { 32 namespace internal { 33 34 namespace DsoLoader { 35 // The following methods either load the DSO of interest and return a dlopen 36 // handle or error status. 37 port::StatusOr<void*> GetCudaDriverDsoHandle(); 38 port::StatusOr<void*> GetCudaRuntimeDsoHandle(); 39 port::StatusOr<void*> GetCublasDsoHandle(); 40 port::StatusOr<void*> GetCublasLtDsoHandle(); 41 port::StatusOr<void*> GetCufftDsoHandle(); 42 port::StatusOr<void*> GetCurandDsoHandle(); 43 port::StatusOr<void*> GetCusolverDsoHandle(); 44 port::StatusOr<void*> GetCusparseDsoHandle(); 45 port::StatusOr<void*> GetCuptiDsoHandle(); 46 port::StatusOr<void*> GetCudnnDsoHandle(); 47 port::StatusOr<void*> GetNvInferDsoHandle(); 48 port::StatusOr<void*> GetNvInferPluginDsoHandle(); 49 50 port::StatusOr<void*> GetRocblasDsoHandle(); 51 port::StatusOr<void*> GetMiopenDsoHandle(); 52 port::StatusOr<void*> GetRocfftDsoHandle(); 53 port::StatusOr<void*> GetRocrandDsoHandle(); 54 port::StatusOr<void*> GetHipsparseDsoHandle(); 55 port::StatusOr<void*> GetHipDsoHandle(); 56 57 // The following method tries to dlopen all necessary GPU libraries for the GPU 58 // platform TF is built with (CUDA or ROCm) only when these libraries should be 59 // dynamically loaded. Error status is returned when any of the libraries cannot 60 // be dlopened. 61 port::Status MaybeTryDlopenGPULibraries(); 62 63 // The following method tries to dlopen all necessary TensorRT libraries when 64 // these libraries should be dynamically loaded. Error status is returned when 65 // any of the libraries cannot be dlopened. 66 port::Status TryDlopenTensorRTLibraries(); 67 } // namespace DsoLoader 68 69 // Wrapper around the DsoLoader that prevents us from dlopen'ing any of the DSOs 70 // more than once. 71 namespace CachedDsoLoader { 72 // Cached versions of the corresponding DsoLoader methods above. 73 port::StatusOr<void*> GetCudaDriverDsoHandle(); 74 port::StatusOr<void*> GetCudaRuntimeDsoHandle(); 75 port::StatusOr<void*> GetCublasDsoHandle(); 76 port::StatusOr<void*> GetCublasLtDsoHandle(); 77 port::StatusOr<void*> GetCufftDsoHandle(); 78 port::StatusOr<void*> GetCurandDsoHandle(); 79 port::StatusOr<void*> GetCusolverDsoHandle(); 80 port::StatusOr<void*> GetCusparseDsoHandle(); 81 port::StatusOr<void*> GetCuptiDsoHandle(); 82 port::StatusOr<void*> GetCudnnDsoHandle(); 83 84 port::StatusOr<void*> GetRocblasDsoHandle(); 85 port::StatusOr<void*> GetMiopenDsoHandle(); 86 port::StatusOr<void*> GetRocfftDsoHandle(); 87 port::StatusOr<void*> GetRocrandDsoHandle(); 88 port::StatusOr<void*> GetHipsparseDsoHandle(); 89 port::StatusOr<void*> GetHipDsoHandle(); 90 } // namespace CachedDsoLoader 91 92 } // namespace internal 93 } // namespace stream_executor 94 95 #endif // TENSORFLOW_STREAM_EXECUTOR_DSO_LOADER_H_ 96