MCPcopy Create free account
hub / github.com/ARM-software/armnn / GetWorkingCopy

Method GetWorkingCopy

src/armnn/SubgraphView.cpp:396–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394};
395
396SubgraphView SubgraphView::GetWorkingCopy() const
397{
398 if (p_WorkingCopyImpl)
399 {
400 throw Exception("The SubgraphView calling GetWorkingCopy() is already a working copy. This function "
401 "should be called on original SubgraphView obtained from OptimizeSubgraphView()");
402 }
403
404 // Create a cut down SubgraphView with underlying graph containing only the relevant layers.
405 // It needs its own underlying layers so that they can be replaced safely.
406 auto ptr = std::make_shared<SubgraphViewWorkingCopy>(Graph(), shared_from_this());
407
408 std::unordered_map<const IConnectableLayer*, IConnectableLayer*> originalToClonedLayerMap;
409 std::list<armnn::IConnectableLayer*> originalSubgraphLayers = GetIConnectableLayers();
410
411 for (auto&& originalLayer : originalSubgraphLayers)
412 {
413 Layer* const layer = PolymorphicDowncast<const Layer*>(originalLayer)->Clone(ptr->m_Graph);
414 originalToClonedLayerMap.emplace(originalLayer, layer);
415 }
416
417 SubgraphView::IInputSlots workingCopyInputs;
418 // Add IInputSlots to workingCopy
419 for (auto originalSubgraphInputSlot : GetIInputSlots())
420 {
421 const IConnectableLayer& originalSubgraphLayer =
422 PolymorphicDowncast<InputSlot*>(originalSubgraphInputSlot)->GetOwningLayer();
423
424 auto* clonedLayer = originalToClonedLayerMap[&originalSubgraphLayer];
425
426 workingCopyInputs.push_back(&clonedLayer->GetInputSlot(originalSubgraphInputSlot->GetSlotIndex()));
427 }
428
429 for (auto originalSubgraphLayer : originalSubgraphLayers)
430 {
431 IConnectableLayer* const clonedLayer = originalToClonedLayerMap[originalSubgraphLayer];
432
433 // OutputLayers have no OutputSlots to be connected
434 if (clonedLayer->GetType() != LayerType::Output)
435 {
436 // connect all cloned layers as per original subgraph
437 for (unsigned int i = 0; i < clonedLayer->GetNumOutputSlots(); i++)
438 {
439 auto& originalOutputSlot = originalSubgraphLayer->GetOutputSlot(i);
440 auto& clonedOutputSlot = clonedLayer->GetOutputSlot(i);
441 for (unsigned int j = 0; j < originalOutputSlot.GetNumConnections(); j++)
442 {
443 // nextLayer is the layer with IInputSlot connected to IOutputSlot we are working on
444 const IConnectableLayer& nextLayerOnOriginalSubgraph =
445 originalOutputSlot.GetConnection(j)->GetOwningIConnectableLayer();
446
447 // Check the layer is in our map and so has a clonedLayer
448 if (originalToClonedLayerMap.find(&nextLayerOnOriginalSubgraph) != originalToClonedLayerMap.end())
449 {
450 auto* nextLayerOnClonedSubgraph = originalToClonedLayerMap[&nextLayerOnOriginalSubgraph];
451
452 auto index = PolymorphicDowncast<OutputSlot*>(
453 &originalOutputSlot)->GetConnection(j)->GetSlotIndex();

Callers 2

Calls 15

emplaceMethod · 0.80
push_backMethod · 0.80
GetSlotIndexMethod · 0.80
GetOutputSlotMethod · 0.80
GetNumConnectionsMethod · 0.80
CalculateIndexOnOwnerMethod · 0.80
GraphClass · 0.70
GetConnectionMethod · 0.60
ExceptionClass · 0.50
CloneMethod · 0.45
GetTypeMethod · 0.45
GetNumOutputSlotsMethod · 0.45

Tested by 1