| 272 | } |
| 273 | |
| 274 | static void TestGraphAfterAddingCopyLayers(const armnn::Graph& graph, const armnn::Graph& origGraph) |
| 275 | { |
| 276 | std::vector<Edge> origEdges = GetEdgeList(origGraph); |
| 277 | std::vector<Edge> newEdges = GetEdgeList(graph); |
| 278 | |
| 279 | // Adding copy layers should not produce any duplicate edges. |
| 280 | { |
| 281 | std::vector<Edge> sortedNewEdges = newEdges; |
| 282 | std::sort(sortedNewEdges.begin(), sortedNewEdges.end()); |
| 283 | |
| 284 | auto last = std::unique(sortedNewEdges.begin(), sortedNewEdges.end()); |
| 285 | CHECK_MESSAGE(last == sortedNewEdges.end(), "New graph contains duplicate edges!"); |
| 286 | } |
| 287 | |
| 288 | // Each new edge must be tested. |
| 289 | while (!newEdges.empty()) |
| 290 | { |
| 291 | const Edge edge = std::move(newEdges.back()); |
| 292 | newEdges.pop_back(); |
| 293 | |
| 294 | // Edge present in the original graph? |
| 295 | int originalEdge = -1; |
| 296 | for (unsigned int i = 0; i < origEdges.size(); i++) |
| 297 | { |
| 298 | const Edge& origEdge = origEdges[i]; |
| 299 | if (origEdge.first->GetNameStr() == edge.first->GetNameStr() && |
| 300 | origEdge.second->GetNameStr() == edge.second->GetNameStr()) |
| 301 | { |
| 302 | originalEdge = armnn::numeric_cast<int>(i); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if (originalEdge != -1) |
| 307 | { |
| 308 | // Each vertex should correspond to a layer. |
| 309 | const armnn::Layer* srcLayer = edge.first; |
| 310 | const armnn::Layer* dstLayer = edge.second; |
| 311 | CHECK(srcLayer); |
| 312 | CHECK(dstLayer); |
| 313 | |
| 314 | // Both layers must have the same compute device. |
| 315 | if (srcLayer && dstLayer) |
| 316 | { |
| 317 | CHECK((srcLayer->GetBackendId() == dstLayer->GetBackendId())); |
| 318 | } |
| 319 | |
| 320 | // Marks edge in original graph as observed (by deleting it). |
| 321 | origEdges.erase(origEdges.begin() + originalEdge); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | // Edge did not exist in the original graph. |
| 326 | // It must then be an edge connecting a layer and a copy layer. |
| 327 | const armnn::Layer* srcLayer = edge.first; |
| 328 | const armnn::Layer* dstLayer = edge.second; |
| 329 | |
| 330 | if (srcLayer == nullptr || dstLayer == nullptr) |
| 331 | { |
no test coverage detected