MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GatherCosts

Method GatherCosts

tensorflow/python/grappler/cost_analyzer.cc:61–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61void CostAnalyzer::GatherCosts() {
62 CostGraphDef cost_graph_measured;
63 PredictCosts(&measure_estimator_, &cost_graph_measured,
64 &total_time_measured_);
65 VLOG(1) << "Graph size: " << item_->graph.node_size();
66 VLOG(1) << "cost_graph_measured size: " << cost_graph_measured.node_size();
67
68 CostGraphDef cost_graph_analytical;
69 PredictCosts(&analytical_estimator_, &cost_graph_analytical,
70 &total_time_analytical_);
71 VLOG(1) << "cost_graph_analytical size: "
72 << cost_graph_analytical.node_size();
73
74 CostGraphDef cost_graph_analytical_filtered;
75 CostGraphDef cost_graph_measured_filtered;
76 std::map<string, const CostGraphDef_Node*> measured_nodes;
77 for (const auto& node : cost_graph_measured.node()) {
78 measured_nodes[node.name()] = &node;
79 }
80 for (const auto& node : cost_graph_analytical.node()) {
81 auto it = measured_nodes.find(node.name());
82 // Filter the nodes that are not the cost nodes returned by
83 // MeasuringCostEstimator.
84 if (it == measured_nodes.end()) {
85 continue;
86 }
87 auto added_node_analytical = cost_graph_analytical_filtered.add_node();
88 auto added_node_measured = cost_graph_measured_filtered.add_node();
89 *added_node_analytical = node;
90 *added_node_measured = *(it->second);
91 }
92 VLOG(1) << "cost_graph_analytical_filtered size: "
93 << cost_graph_analytical_filtered.node_size();
94
95 // TODO(yaozhang): add a test to make sure that op_perf_analytical_ and
96 // op_perf_ cover the same set of nodes.
97 op_perf_analytical_ = CostGraphToOpPerformanceData(
98 cost_graph_analytical_filtered, item_->graph);
99 op_perf_ =
100 CostGraphToOpPerformanceData(cost_graph_measured_filtered, item_->graph);
101}
102
103void CostAnalyzer::PreprocessCosts() {
104 for (int i = 0; i < op_perf_.op_performance_size(); i++) {

Callers

nothing calls this directly

Calls 5

nameMethod · 0.65
nodeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected