aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Hughes <robert.hughes@arm.com>2021-02-19 09:24:44 +0000
committerJim Flynn <jim.flynn@arm.com>2021-03-01 16:38:56 +0000
commit1addbf3e52fe1b25e8101de81da7f35e718d68b9 (patch)
tree177ec84075c9a1c9b1d373a3fc9c81ce4b594548
parent27a9bd93bd0f02c8ad866ae0fb70f1c4bb67ef0c (diff)
downloadarmnn-1addbf3e52fe1b25e8101de81da7f35e718d68b9.tar.gz
Make SubgraphViewSelector give deterministic results
The subgraphs produced by SubgraphViewSelector were not deterministic as the order of the input slots, outputs slots and layers within each subgraph were determined by the pointer values of those objects, which are not guaranteed to be the same for each execution. This patch adds a post-processing sorting step based on the GUIDs of the layers and the slot indices so that the results will be the same for each execution. This makes debugging the optimised graph much easier as subsequent stages can also be deterministic. Change-Id: Ifbcb199733066f99e9f95808a8da22023e5944f1 Signed-off-by: Rob Hughes <robert.hughes@arm.com>
-rw-r--r--src/armnn/SubgraphViewSelector.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/armnn/SubgraphViewSelector.cpp b/src/armnn/SubgraphViewSelector.cpp
index 96e75abf8b..21fbb7cd80 100644
--- a/src/armnn/SubgraphViewSelector.cpp
+++ b/src/armnn/SubgraphViewSelector.cpp
@@ -472,6 +472,39 @@ SubgraphViewSelector::SelectSubgraphs(SubgraphView& subgraph, const LayerSelecto
infoPtr->CollectNonSelectedOutputSlots(layerInfos, outputs);
layers.push_back(infoPtr->m_Layer);
}
+
+ // Sort lists into deterministic order, not relying on pointer values which may be different on each execution.
+ // This makes debugging the optimised graph much easier as subsequent stages can also be deterministic.
+ std::sort(inputs.begin(), inputs.end(), [](const InputSlot* a, const InputSlot* b)
+ {
+ const LayerGuid guidA = a->GetOwningLayer().GetGuid();
+ const LayerGuid guidB = b->GetOwningLayer().GetGuid();
+ if (guidA < guidB)
+ {
+ return true;
+ }
+ else if (guidA == guidB)
+ {
+ return (a->GetSlotIndex() < b->GetSlotIndex());
+ }
+ return false;
+ });
+ std::sort(outputs.begin(), outputs.end(), [](const OutputSlot* a, const OutputSlot* b)
+ {
+ const LayerGuid guidA = a->GetOwningLayer().GetGuid();
+ const LayerGuid guidB = b->GetOwningLayer().GetGuid();
+ if (guidA < guidB)
+ {
+ return true;
+ }
+ else if (guidA == guidB)
+ {
+ return (a->CalculateIndexOnOwner() < b->CalculateIndexOnOwner());
+ }
+ return false;
+ });
+ layers.sort([](const Layer* a, const Layer* b) { return a->GetGuid() < b->GetGuid(); });
+
// Create a new sub-graph with the new lists of input/output slots and layer
result.emplace_back(std::make_unique<SubgraphView>(std::move(inputs),
std::move(outputs),