ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::ir::verifier::DAGChecker Class Reference

#include <Verifier.h>

Collaboration diagram for onert::ir::verifier::DAGChecker:

Public Member Functions

bool verify (const Graph &graph) const noexcept override
 
bool verify (const train::UseDefChains &training_defuses) const noexcept
 
- Public Member Functions inherited from onert::ir::verifier::IVerifier
virtual ~IVerifier ()=default
 

Detailed Description

Definition at line 54 of file Verifier.h.

Member Function Documentation

◆ verify() [1/2]

bool onert::ir::verifier::DAGChecker::verify ( const Graph graph) const
overridevirtualnoexcept

Implements onert::ir::verifier::IVerifier.

Definition at line 92 of file Verifier.cc.

93{
94 auto &operations = graph.operations();
95 bool cyclic = false;
96
98 operations.iterate(
99 [&](const OperationIndex &index, const IOperation &) { visited[index] = false; });
100 OperationIndexMap<bool> on_stack = visited; // Copy from visited
101
102 std::function<void(const OperationIndex &index, const IOperation &)> dfs_recursive =
103 [&](const OperationIndex &index, const IOperation &node) -> void {
104 if (on_stack[index])
105 cyclic = true;
106 if (visited[index])
107 return;
108 visited[index] = true;
109 on_stack[index] = true;
110
111 for (auto &&output : node.getOutputs() | Remove::DUPLICATED | Remove::UNDEFINED)
112 {
113 const auto &operand = graph.operands().at(output);
114 for (const auto &use : operand.getUses())
115 {
116 dfs_recursive(use, graph.operations().at(use));
117 }
118 }
119
120 on_stack[index] = false;
121 };
122
123 operations.iterate(dfs_recursive);
124
125 return !cyclic;
126}
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54
std::unordered_map< OperationIndex, T > OperationIndexMap

References onert::ir::DUPLICATED, and onert::ir::UNDEFINED.

◆ verify() [2/2]

bool onert::ir::verifier::DAGChecker::verify ( const train::UseDefChains training_defuses) const
noexcept

Definition at line 129 of file Verifier.cc.

130{
131 bool cyclic = false;
132 const auto operations = extractOperations(training_usedefs);
133 auto outputs_map = extractNodeOutputs(training_usedefs);
134
135 std::unordered_map<train::TrainingOperationIndex, bool> visited;
136 for (const auto &node_index : operations)
137 visited[node_index] = false;
138 auto on_stack = visited; // Copy from visited
139
140 std::function<void(const train::TrainingOperationIndex &index)> dfs_recursive =
141 [&](const train::TrainingOperationIndex &index) -> void {
142 if (on_stack[index])
143 cyclic = true;
144 if (visited[index])
145 return;
146 visited[index] = true;
147 on_stack[index] = true;
148
149 auto &node_outputs = outputs_map[index];
150 for (const auto &output : node_outputs)
151 {
152 const auto &uses = training_usedefs.at(output).getTrainingUses();
153 for (const auto &use : uses)
154 {
155 dfs_recursive(use);
156 }
157 }
158
159 on_stack[index] = false;
160 };
161
162 for (const auto &node_index : operations)
163 dfs_recursive(node_index);
164
165 return !cyclic;
166}
Class that provides index of tensor for training.
Definition Index.h:38

The documentation for this class was generated from the following files: