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