xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/tf2tensorrt/utils/trt_execution_context.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2021 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 #ifndef TENSORFLOW_COMPILER_TF2TENSORRT_UTILS_TRT_EXECUTION_CONTEXT_H_
17 #define TENSORFLOW_COMPILER_TF2TENSORRT_UTILS_TRT_EXECUTION_CONTEXT_H_
18 
19 #if GOOGLE_CUDA && GOOGLE_TENSORRT
20 #include "third_party/tensorrt/NvInfer.h"
21 
22 namespace tensorflow {
23 namespace tensorrt {
24 
25 // A wrapper for the TensorRT execution context which will destroy the TensorRT
26 // execution context when the object goes out of scope.
27 class ExecutionContext : public TrtUniquePtrType<nvinfer1::IExecutionContext> {
28  public:
ExecutionContext(nvinfer1::IExecutionContext * context,bool has_memory)29   ExecutionContext(nvinfer1::IExecutionContext* context, bool has_memory)
30       : TrtUniquePtrType<nvinfer1::IExecutionContext>(context),
31         has_device_memory_(has_memory) {}
32   static ExecutionContext Create(nvinfer1::ICudaEngine* cuda_engine);
33 
HasDeviceMemory()34   bool HasDeviceMemory() { return has_device_memory_; }
35 
36  private:
37   bool has_device_memory_;
38 };
39 
40 };  // namespace tensorrt
41 };  // namespace tensorflow
42 #endif
43 #endif
44