compute maximal distance from graph inputs to graph nodes along with min/max values of distance and return status of computation (Assumes graph has no cycles)
compute maximal distance from graph inputs to graph nodes along with min/max values of distance and return status of compuation (success/failure)
30{
31 if (module == nullptr)
32 return ParameterizerResult::FAILURE;
33
34 if (module->size() != 1)
35 return ParameterizerResult::FAILURE;
36
37 auto graph = module->graph(0);
38 if (!graph)
39 return ParameterizerResult::FAILURE;
40
41
42 std::vector<luci::CircleNode *> to_process;
43 std::map<std::string, float> named_depth;
44 {
46 for (auto &node : inputs)
47 {
48 auto cnode = loco::must_cast<luci::CircleNode *>(node);
49 to_process.emplace_back(cnode);
50 nodes_depth[cnode] = 0.f;
51 named_depth[cnode->name()] = 0.f;
52 }
53 }
54
55
56 while (!to_process.empty())
57 {
58 auto cur_node = to_process.back();
59 to_process.pop_back();
60 auto iter = nodes_depth.find(cur_node);
61 if (iter == nodes_depth.end())
62 {
63 return ParameterizerResult::FAILURE;
64 }
65 float cur_depth = iter->second + 1;
66
68 for (auto &child : children)
69 {
70 auto cichild = loco::must_cast<luci::CircleNode *>(child);
71 auto node_depth = nodes_depth.find(cichild);
72 if (node_depth == nodes_depth.end() || node_depth->second < cur_depth)
73 {
74
75 nodes_depth[cichild] = cur_depth;
76 to_process.push_back(cichild);
77 named_depth[cichild->name()] = cur_depth;
78 }
79 }
80 }
81
82
83 auto minmax = std::minmax_element(
84 nodes_depth.begin(), nodes_depth.end(),
85 [=](const std::pair<luci::CircleNode *, float> &el1,
86 const std::pair<luci::CircleNode *, float> &el2) { return el1.second < el2.second; });
87
88 min_depth = minmax.first->second;
89 max_depth = minmax.second->second;
90
91 return ParameterizerResult::SUCCESS;
92}
std::set< Node * > succs(const Node *node)
Enumerate all the successors of a given node.
std::vector< Node * > input_nodes(const Graph *)