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/compiler/tf2tensorrt/convert/trt_optimization_pass.h" 22 #include "tensorflow/compiler/tf2tensorrt/convert/utils.h" 23 #include "tensorflow/compiler/tf2tensorrt/utils/trt_shape_optimization_profiles.h" 24 #include "tensorflow/core/framework/graph.pb.h" 25 #include "tensorflow/core/framework/tensor_shape.h" 26 #include "tensorflow/core/grappler/clusters/cluster.h" 27 #include "tensorflow/core/grappler/grappler_item.h" 28 #include "tensorflow/core/lib/core/status.h" 29 #include "tensorflow/core/platform/types.h" 30 31 #if GOOGLE_CUDA && GOOGLE_TENSORRT 32 33 namespace tensorflow { 34 namespace tensorrt { 35 namespace convert { 36 37 // These functions are internal implementation functions for the 38 // TRTOptimizationPass. 39 40 // Performs segmentation and conversion on the given Grappler item. This method 41 // contains the core logic of the TRTOptimizationPass. 42 Status ConvertGraph(const TRTOptimizationPass::ConversionParams& params, 43 grappler::GrapplerItem& grappler_item, 44 const std::vector<string>& input_output_names, 45 grappler::Cluster* cluster, GraphDef* output); 46 47 // Helper method for the conversion, expose for testing. 48 std::pair<int, Allocator*> GetDeviceAndAllocator( 49 const grappler::Cluster* cluster, const EngineInfo& engine); 50 51 // Helper method that registers `segment_graph` as a function to the function 52 // library in `graph`. 53 Status RegisterGraphToFunctionLibrary(const GraphDef& segment_graph_def, 54 Graph* graph, const string& engine_name); 55 56 // Creates and serializes an ICudaEngine. Used only in is_dynamic_op=false, 57 // a.k.a. static engine mode. 58 Status CreateStaticEngine(const TRTOptimizationPass::ConversionParams& params, 59 const EngineInfo& info, int max_batch_size, 60 const std::vector<PartialTensorShape>& input_shapes, 61 TrtShapeOptimizationProfile* profile, 62 string* segment_string, grappler::Cluster* cluster); 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