Function will return static ops set
| 90 | |
| 91 | // Function will return static ops set |
| 92 | void StaticShapeCluteringStrategy::GetStaticGraphOps( |
| 93 | const GraphDef& gdef, |
| 94 | std::vector<std::string>& inputs, |
| 95 | std::vector<std::string>& outputs, |
| 96 | std::unordered_set<std::string>* static_ops_name) { |
| 97 | std::unordered_map<std::string, bool> dynamic_ops_map = |
| 98 | GetNodesHasDynamicShapeMap(gdef); |
| 99 | |
| 100 | std::unordered_map<std::string, bool> has_control_flow_input = |
| 101 | GetNodesHasControlFlowInputs(gdef); |
| 102 | |
| 103 | std::unordered_map<std::string, const NodeDef*> nodes; |
| 104 | for (const NodeDef& node : gdef.node()) { |
| 105 | nodes[node.name()] = &node; |
| 106 | } |
| 107 | |
| 108 | std::unordered_set<const NodeDef*> static_nodes; |
| 109 | std::unordered_set<const NodeDef*> visited; |
| 110 | std::queue<const NodeDef*> q; |
| 111 | for (auto output : outputs) { |
| 112 | q.push(nodes[output]); |
| 113 | visited.insert(nodes[output]); |
| 114 | } |
| 115 | |
| 116 | std::unordered_set<std::string> black_ops = GetBlackOpsSet(); |
| 117 | while (!q.empty()) { |
| 118 | const NodeDef* curr_node = q.front(); |
| 119 | // 1) no control edge |
| 120 | // 2) no dynamic shape |
| 121 | // 3) no blacklist ops |
| 122 | if (!has_control_flow_input[curr_node->name()] && |
| 123 | !dynamic_ops_map[curr_node->name()] && |
| 124 | black_ops.find(curr_node->op()) == black_ops.end()) { |
| 125 | // Add op into static ops set |
| 126 | //(*static_ops)[curr_node->name()] = curr_node; |
| 127 | static_ops_name->insert(curr_node->name()); |
| 128 | |
| 129 | for (auto in_name : curr_node->input()) { |
| 130 | size_t offset = in_name.find(":"); |
| 131 | in_name = in_name.substr(0, offset); |
| 132 | if (visited.find(nodes[in_name]) == visited.end()) { |
| 133 | q.push(nodes[in_name]); |
| 134 | visited.insert(nodes[in_name]); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | q.pop(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void StaticShapeCluteringStrategy::Run( |
| 144 | const GraphDef& gdef, |
nothing calls this directly
no test coverage detected