• 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_CONVERT_GRAPH_H_
16 #define TENSORFLOW_COMPILER_TF2TENSORRT_CONVERT_CONVERT_GRAPH_H_
17 
18 #include <vector>
19 
20 #include "tensorflow/compiler/tf2tensorrt/convert/convert_nodes.h"
21 #include "tensorflow/core/framework/graph.pb.h"
22 #include "tensorflow/core/grappler/clusters/cluster.h"
23 #include "tensorflow/core/grappler/grappler_item.h"
24 #include "tensorflow/core/lib/core/status.h"
25 #include "tensorflow/core/platform/types.h"
26 
27 #if GOOGLE_CUDA && GOOGLE_TENSORRT
28 
29 namespace tensorflow {
30 namespace tensorrt {
31 namespace convert {
32 
33 struct ConversionParams {
34   const grappler::GrapplerItem* grappler_item = nullptr;
35   const std::vector<string>* output_names = nullptr;
36   string trt_logger_name;
37   size_t max_batch_size = 1;
38   size_t max_workspace_size_bytes = 1 << 30;
39   GraphDef* output_graph_def = nullptr;
40   TrtPrecisionMode precision_mode = TrtPrecisionMode::FP32;
41   int minimum_segment_size = 3;
42   const grappler::Cluster* cluster = nullptr;
43   // Whether to create engine on conversion or execution time
44   bool is_dyn_op = false;
45   // maximum number of cached engines
46   int max_cached_engines = 1;
47   bool use_calibration = true;
48   bool use_implicit_batch = true;
49   bool allow_build_at_runtime = true;
50 };
51 
52 // Method to call from optimization pass
53 Status ConvertAfterShapes(const ConversionParams& params);
54 
55 // Helper method for the conversion, expose for testing.
56 std::pair<int, Allocator*> GetDeviceAndAllocator(const ConversionParams& params,
57                                                  const EngineInfo& engine);
58 
59 // Helper method that registers `segment_graph` as a function to the function
60 // library in `graph`.
61 Status RegisterGraphToFunctionLibrary(const GraphDef& segment_graph_def,
62                                       Graph* graph, const string& engine_name);
63 
64 }  // namespace convert
65 }  // namespace tensorrt
66 }  // namespace tensorflow
67 
68 #endif  // GOOGLE_CUDA && GOOGLE_TENSORRT
69 
70 #endif  // TENSORFLOW_COMPILER_TF2TENSORRT_CONVERT_CONVERT_GRAPH_H_
71