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. 35 using SegmentNodesVector = std::vector<std::set<const Node*>>; 36 37 struct SegmentOptions { 38 // Segment must contain at least this many nodes. 39 int minimum_segment_size = 2; 40 std::set<string> exclude_node_list; 41 }; 42 43 // Get the subgraphs of a graph that can be handled by TensorRT. 44 // 45 // @param graph Graph of the network 46 // @param candidate_fn A function that returns OK for a Node* if 47 // that node can be handled by TensorRT. 48 // @param segments Returns the TensorRT segments/subgraphs. Each entry 49 // in the vector describes a subgraph by giving a set of the names of 50 // all the NodeDefs in that subgraph. 51 // @return the status. 52 Status SegmentGraph(const Graph* tf_graph, 53 const std::function<Status(const Node*)>& candidate_fn, 54 const std::function<bool(const Edge*)>& input_candidate_fn, 55 const std::function<bool(const Edge*)>& output_candidate_fn, 56 const SegmentOptions& options, 57 SegmentNodesVector* segments); 58 59 } // namespace segment 60 } // namespace tensorrt 61 } // namespace tensorflow 62 63 #endif // GOOGLE_TENSORRT 64 #endif // GOOGLE_CUDA 65 66 #endif // TENSORFLOW_COMPILER_TF2TENSORRT_SEGMENT_SEGMENT_H_ 67