xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/tf2tensorrt/utils/py_utils.cc (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2019 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 #include "tensorflow/compiler/tf2tensorrt/utils/py_utils.h"
17 
18 #include <string>
19 
20 #if GOOGLE_CUDA && GOOGLE_TENSORRT
21 #include "tensorflow/compiler/tf2tensorrt/common/utils.h"
22 #include "tensorflow/compiler/tf2tensorrt/convert/op_converter_registry.h"
23 #include "tensorflow/stream_executor/platform/dso_loader.h"
24 #include "third_party/tensorrt/NvInfer.h"
25 #endif
26 
27 namespace tensorflow {
28 namespace tensorrt {
29 
IsGoogleTensorRTEnabled()30 bool IsGoogleTensorRTEnabled() {
31 #if GOOGLE_CUDA && GOOGLE_TENSORRT
32 #if TF_USE_TENSORRT_STATIC
33   LOG(INFO) << "TensorRT libraries are statically linked, skip dlopen check";
34   return true;
35 #else   // TF_USE_TENSORRT_STATIC
36   auto handle_or = se::internal::DsoLoader::TryDlopenTensorRTLibraries();
37   if (!handle_or.ok()) {
38     LOG_WARNING_WITH_PREFIX
39         << "Cannot dlopen some TensorRT libraries. If you would like "
40            "to use Nvidia GPU with TensorRT, please make sure the "
41            "missing libraries mentioned above are installed properly.";
42   }
43   return handle_or.ok();
44 #endif  // TF_USE_TENSORRT_STATIC
45 #else   // GOOGLE_CUDA && GOOGLE_TENSORRT
46   return false;
47 #endif  // GOOGLE_CUDA && GOOGLE_TENSORRT
48 }
49 
GetRegisteredOpConverters()50 std::vector<std::string> GetRegisteredOpConverters() {
51 #if GOOGLE_CUDA && GOOGLE_TENSORRT
52   auto* registry = tensorflow::tensorrt::convert::GetOpConverterRegistry();
53   return registry->ListRegisteredOps();
54 #else
55   return {"undef"};
56 #endif
57 }
58 
59 }  // namespace tensorrt
60 }  // namespace tensorflow
61