• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 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 #ifndef TENSORFLOW_COMPILER_TF2TENSORRT_CONVERT_LOGGER_REGISTRY_H_
16 #define TENSORFLOW_COMPILER_TF2TENSORRT_CONVERT_LOGGER_REGISTRY_H_
17 
18 #include "tensorflow/core/lib/core/status.h"
19 #include "tensorflow/core/platform/macros.h"
20 #include "tensorflow/core/platform/types.h"
21 
22 #if GOOGLE_CUDA && GOOGLE_TENSORRT
23 
24 #include "third_party/tensorrt/NvInfer.h"
25 
26 namespace tensorflow {
27 namespace tensorrt {
28 
29 class LoggerRegistry {
30  public:
31   virtual Status Register(const string& name, nvinfer1::ILogger* logger) = 0;
32   virtual nvinfer1::ILogger* LookUp(const string& name) = 0;
~LoggerRegistry()33   virtual ~LoggerRegistry() {}
34 };
35 
36 LoggerRegistry* GetLoggerRegistry();
37 
38 class RegisterLogger {
39  public:
RegisterLogger(const string & name,nvinfer1::ILogger * logger)40   RegisterLogger(const string& name, nvinfer1::ILogger* logger) {
41     TF_CHECK_OK(GetLoggerRegistry()->Register(name, logger));
42   }
43 };
44 
45 #define REGISTER_TENSORRT_LOGGER(name, logger) \
46   REGISTER_TENSORRT_LOGGER_UNIQ_HELPER(__COUNTER__, name, logger)
47 #define REGISTER_TENSORRT_LOGGER_UNIQ_HELPER(ctr, name, logger) \
48   REGISTER_TENSORRT_LOGGER_UNIQ(ctr, name, logger)
49 #define REGISTER_TENSORRT_LOGGER_UNIQ(ctr, name, logger)                 \
50   static ::tensorflow::tensorrt::RegisterLogger register_trt_logger##ctr \
51       TF_ATTRIBUTE_UNUSED =                                              \
52           ::tensorflow::tensorrt::RegisterLogger(name, logger)
53 
54 }  // namespace tensorrt
55 }  // namespace tensorflow
56 
57 #endif  // GOOGLE_CUDA && GOOGLE_TENSORRT
58 #endif  // TENSORFLOW_COMPILER_TF2TENSORRT_CONVERT_LOGGER_REGISTRY_H_
59