diff options
Diffstat (limited to 'tensorflow/core/graph/costutil.cc')
-rw-r--r-- | tensorflow/core/graph/costutil.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tensorflow/core/graph/costutil.cc b/tensorflow/core/graph/costutil.cc new file mode 100644 index 0000000000..f8e2d9fe68 --- /dev/null +++ b/tensorflow/core/graph/costutil.cc @@ -0,0 +1,22 @@ +#include "tensorflow/core/graph/costutil.h" + +#include "tensorflow/core/graph/algorithm.h" +#include "tensorflow/core/graph/graph.h" +#include "tensorflow/core/graph/costmodel.h" + +namespace tensorflow { + +std::vector<int64> LongestOutgoingPathCost(const Graph& graph, + const CostModel& cm) { + std::vector<int64> result(graph.num_node_ids()); + DFS(graph, nullptr, [&result, &cm](Node* n) { + int64 max_child = 0; + for (const Node* out : n->out_nodes()) { + max_child = std::max(max_child, result[out->id()]); + } + result[n->id()] = max_child + (n->IsOp() ? cm.TimeEstimate(n).value() : 0); + }); + return result; +} + +} // namespace tensorflow |