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 16 #ifndef TENSORFLOW_COMPILER_TF2TENSORRT_SEGMENT_SEGMENT_H_ 17 #define TENSORFLOW_COMPILER_TF2TENSORRT_SEGMENT_SEGMENT_H_ 18 19 #include <set> 20 #include <vector> 21 22 #include "tensorflow/core/framework/graph.pb.h" 23 #include "tensorflow/core/graph/graph.h" 24 #include "tensorflow/core/lib/core/status.h" 25 #include "tensorflow/core/platform/types.h" 26 27 #if GOOGLE_CUDA 28 #if GOOGLE_TENSORRT 29 30 namespace tensorflow { 31 namespace tensorrt { 32 namespace segment { 33 34 // Vector of segments, each entry contains a set of node pointers and a device 35 // name in the segment. 36 using SegmentNodesVector = 37 std::vector<std::pair<std::set<const Node*>, string>>; 38 39 struct SegmentOptions { 40 // Segment must contain at least this many nodes. 41 int minimum_segment_size = 2; 42 std::set<string> exclude_node_list; 43 }; 44 45 // Get the subgraphs of a graph that can be handled by TensorRT. 46 // 47 // @param graph Graph of the network 48 // @param candidate_fn A function that returns OK for a Node* if 49 // that node can be handled by TensorRT. 50 // @param segments Returns the TensorRT segments/subgraphs. Each entry 51 // in the vector describes a subgraph by giving a set of the names of 52 // all the NodeDefs in that subgraph. 53 // @return the status. 54 Status SegmentGraph(const Graph* tf_graph, 55 const std::function<Status(const Node*)>& candidate_fn, 56 const std::function<bool(const Edge*)>& input_candidate_fn, 57 const std::function<bool(const Edge*)>& output_candidate_fn, 58 const SegmentOptions& options, 59 SegmentNodesVector* segments); 60 61 } // namespace segment 62 } // namespace tensorrt 63 } // namespace tensorflow 64 65 #endif // GOOGLE_TENSORRT 66 #endif // GOOGLE_CUDA 67 68 #endif // TENSORFLOW_COMPILER_TF2TENSORRT_SEGMENT_SEGMENT_H_ 69