| 187 | } |
| 188 | |
| 189 | bool CheckGraphIntegraityByEdge(StaticGraph* graph) |
| 190 | { |
| 191 | /*go through all tensors and check if the tensor's producer and consumer's info are correct */ |
| 192 | StaticTensor* tensor; |
| 193 | |
| 194 | for(unsigned int i = 0; i < graph->tensor_list.size(); i++) |
| 195 | { |
| 196 | tensor = graph->tensor_list[i].get(); |
| 197 | |
| 198 | /* check index */ |
| 199 | if(tensor->index != ( int )i) |
| 200 | { |
| 201 | LOG_ERROR() << "tensor: " << tensor->name << " index mismatch: real " << i << " record " << tensor->index |
| 202 | << "\n"; |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | /* check producer */ |
| 207 | |
| 208 | NodeSynapse node_entry = tensor->producer; |
| 209 | |
| 210 | StaticNode* node = graph->node_list[node_entry.node_index].get(); |
| 211 | |
| 212 | if(node->index != node_entry.node_index) |
| 213 | { |
| 214 | LOG_ERROR() << "node: " << node->name << " index mismatch: real " << node_entry.node_index; |
| 215 | LOG_ERROR() << " record " << node->index << "\n"; |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | /* check producer */ |
| 220 | |
| 221 | if(node_entry.entry_index >= ( int )node->output_tensor_list.size() || |
| 222 | node->output_tensor_list[node_entry.entry_index] != tensor->index) |
| 223 | { |
| 224 | LOG_ERROR() << "Producer mismatch: tensor " << tensor->name << " node " << node->name << "\n"; |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | /* if the node has no input tensor, the op must be const or input */ |
| 229 | if(node->input_tensor_list.size() == 0) |
| 230 | { |
| 231 | StaticOp* op = node->op.get(); |
| 232 | |
| 233 | if(op->name != "Const" && op->name != "InputOp") |
| 234 | { |
| 235 | LOG_ERROR() << "node " << node->name << " has no input while op is: " << op->name << "\n"; |
| 236 | return false; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /* if the tensor has no consumer, the node must be an output node of graph */ |
| 241 | |
| 242 | if(tensor->consumer.size() == 0) |
| 243 | { |
| 244 | int found = 0; |
| 245 | |
| 246 | for(unsigned int n = 0; n < graph->output_node_list.size(); n++) |
no test coverage detected