| 292 | } |
| 293 | |
| 294 | OpPerformanceList CostGraphToOpPerformanceData(const CostGraphDef& cost_graph, |
| 295 | const GraphDef& graph) { |
| 296 | OpPerformanceList ret; |
| 297 | std::unordered_map<string, const CostGraphDef::Node*> name_to_cost; |
| 298 | std::unordered_map<string, const NodeDef*> name_to_node; |
| 299 | for (auto& node : cost_graph.node()) { |
| 300 | name_to_cost[node.name()] = &node; |
| 301 | } |
| 302 | for (auto& node : graph.node()) { |
| 303 | name_to_node[node.name()] = &node; |
| 304 | } |
| 305 | |
| 306 | for (const auto& node : graph.node()) { |
| 307 | // Skip the nodes that are not in the cost graph: these are nodes that |
| 308 | // aren't run, because they aren't in the intersection of transitive |
| 309 | // fan-in of a fetch node and the transitive fan-out of an input, or nodes |
| 310 | // that were optimized away by the optimizer. Since they don't contribute |
| 311 | // to the execution time we simply discard them. |
| 312 | auto it = name_to_cost.find(node.name()); |
| 313 | if (it == name_to_cost.end()) { |
| 314 | continue; |
| 315 | } |
| 316 | const CostGraphDef::Node* cost_node = it->second; |
| 317 | |
| 318 | OpPerformance* perf = ret.add_op_performance(); |
| 319 | perf->set_node(node.name()); |
| 320 | |
| 321 | std::vector<OpInfo::TensorProperties> inputs = |
| 322 | FindInputFeatures(node, name_to_cost, name_to_node); |
| 323 | *perf->mutable_op() = BuildOpInfoWithoutDevice(node, name_to_node, inputs); |
| 324 | *perf->mutable_op()->mutable_device() = GetDeviceInfo(cost_node->device()); |
| 325 | |
| 326 | perf->set_temporary_memory_size(cost_node->temporary_memory_size()); |
| 327 | // Note that CostGraphDef::Node::compute_cost is microseconds, while |
| 328 | // OpPerformance.compute_cost is nanoseconds. |
| 329 | perf->set_compute_cost(cost_node->compute_cost() * 1000); |
| 330 | perf->set_compute_time(cost_node->compute_time() * 1000); |
| 331 | perf->set_memory_time(cost_node->memory_time() * 1000); |
| 332 | |
| 333 | for (const auto& output_info : cost_node->output_info()) { |
| 334 | perf->mutable_op_memory()->add_output_memory(output_info.size()); |
| 335 | } |
| 336 | |
| 337 | perf->mutable_op_memory()->set_temp_memory( |
| 338 | cost_node->temporary_memory_size()); |
| 339 | perf->mutable_op_memory()->set_persistent_memory( |
| 340 | cost_node->persistent_memory_size()); |
| 341 | } |
| 342 | return ret; |
| 343 | } |
| 344 | |
| 345 | void TensorSizeHistogram::Add(const uint64 value) { |
| 346 | num_elem_++; |
no test coverage detected