| 2391 | } |
| 2392 | |
| 2393 | Status GraphProperties::InferFromCostGraph(const CostGraphDef& cost_graph) { |
| 2394 | if (cost_graph.node_size() == 0) { |
| 2395 | LOG(WARNING) << "cost_graph is empty: nothing can be inferred!"; |
| 2396 | } |
| 2397 | std::unordered_map<string, const CostGraphDef::Node*> name_to_cost; |
| 2398 | std::unordered_map<string, const NodeDef*> name_to_node; // Empty |
| 2399 | for (auto& node : cost_graph.node()) { |
| 2400 | name_to_cost[node.name()] = &node; |
| 2401 | |
| 2402 | std::vector<OpInfo::TensorProperties> output_properties; |
| 2403 | for (const auto& out : node.output_info()) { |
| 2404 | OpInfo::TensorProperties properties; |
| 2405 | properties.set_dtype(out.dtype()); |
| 2406 | *properties.mutable_shape() = out.shape(); |
| 2407 | output_properties.push_back(properties); |
| 2408 | } |
| 2409 | output_properties_[node.name()] = output_properties; |
| 2410 | } |
| 2411 | |
| 2412 | for (const auto& node : item_.graph.node()) { |
| 2413 | // Skip the nodes that are not in the cost graph: these are nodes that |
| 2414 | // aren't run, because they aren't in the intersection of transitive fan-in |
| 2415 | // of a fetch node and the transitive fan-out of an input, or nodes that |
| 2416 | // were optimized away by the optimizer. |
| 2417 | auto it = name_to_cost.find(node.name()); |
| 2418 | if (it == name_to_cost.end()) { |
| 2419 | continue; |
| 2420 | } |
| 2421 | std::vector<OpInfo::TensorProperties> inputs = |
| 2422 | FindInputFeatures(node, name_to_cost, name_to_node); |
| 2423 | |
| 2424 | input_properties_[node.name()] = inputs; |
| 2425 | } |
| 2426 | return Status::OK(); |
| 2427 | } |
| 2428 | |
| 2429 | bool GraphProperties::HasInputProperties(const string& node_name) const { |
| 2430 | return input_properties_.find(node_name) != input_properties_.end(); |
nothing calls this directly
no test coverage detected