aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/NetworkUtils.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-01-11 13:25:59 +0000
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-01-15 08:59:50 +0000
commit4912402497a51c6afe0898b3900f87feefa006a6 (patch)
tree4e9b5161781d2b0be041aec17227193da5977443 /src/armnn/NetworkUtils.cpp
parentd0a1608e2c41639d8f3e3f9305d79c5f92c9cff8 (diff)
downloadarmnn-4912402497a51c6afe0898b3900f87feefa006a6.tar.gz
IVGCVSW-2454 Merge together the pluggable backends work (was in a
separate branch) and master * Brings in all the changes done for the pluggable backends * Added sub-graph support and tests * Added precompiled layer support and tests * Moved BackendSettings to a separate file * Removed the backend-specific code * Ported DebugLayer and associated functionality * Included fixes to make those changes work with master Change-Id: Id7028fa7917527b844628d5aff5732e3d94c0488
Diffstat (limited to 'src/armnn/NetworkUtils.cpp')
-rw-r--r--src/armnn/NetworkUtils.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/armnn/NetworkUtils.cpp b/src/armnn/NetworkUtils.cpp
index 9a4ce87b59..735a6244d5 100644
--- a/src/armnn/NetworkUtils.cpp
+++ b/src/armnn/NetworkUtils.cpp
@@ -5,6 +5,12 @@
#include "NetworkUtils.hpp"
+#include "SubGraphSelector.hpp"
+
+#include <armnn/Exceptions.hpp>
+
+#include <backendsCommon/BackendRegistry.hpp>
+
namespace armnn
{
@@ -74,7 +80,6 @@ std::vector<ConvertFp32ToFp16Layer*> InsertConvertFp32ToFp16LayersAfter(Graph& g
return convertLayers;
}
-
std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer)
{
std::vector<DebugLayer*> debugLayers;
@@ -97,10 +102,58 @@ std::vector<DebugLayer*> InsertDebugLayerAfter(Graph& graph, Layer& layer)
debugLayer->GetOutputSlot().SetTensorInfo(debugInfo);
+ // NOTE: It is OK to do this because DebugLayer is only supported on CpuRef
+ debugLayer->SetBackendId(Compute::CpuRef);
+
debugLayers.emplace_back(debugLayer);
}
return debugLayers;
}
+PreCompiledLayer* CreatePreCompiledLayer(Graph& graph,
+ const SubGraph& subGraph,
+ unsigned int subGraphIndex,
+ const IBackendInternalUniquePtr& backendObjPtr)
+{
+ BOOST_ASSERT(backendObjPtr);
+
+ IBackendInternal::ISubGraphConverterPtr converter =
+ backendObjPtr->CreateSubGraphConverter(std::make_shared<SubGraph>(subGraph));
+ if (!converter)
+ {
+ return nullptr;
+ }
+
+ try
+ {
+ // Attempt to convert and compile sub-graph
+ auto preCompiledObject = converter->GetOutput();
+ }
+ catch (std::exception&)
+ {
+ return nullptr;
+ }
+
+ // Create pre-compiled layer
+ std::string name = "pre-compiled" + std::to_string(subGraphIndex);
+ PreCompiledLayer* preCompiledLayer = graph.AddLayer<PreCompiledLayer>(
+ PreCompiledDescriptor(subGraph.GetNumInputSlots(), subGraph.GetNumOutputSlots()), name.c_str());
+
+ // Copy output tensor infos from sub-graph
+ for (unsigned int i = 0u; i < subGraph.GetNumOutputSlots(); i++)
+ {
+ preCompiledLayer->GetOutputSlot(i).SetTensorInfo(subGraph.GetOutputSlot(i)->GetTensorInfo());
+ }
+
+ // Assign pre-compiled object to layer
+ preCompiledLayer->SetPreCompiledObject(converter->GetOutput());
+
+ // Set the backend-id for the pre-compiled layer
+ BackendId backendId = backendObjPtr->GetId();
+ preCompiledLayer->SetBackendId(backendId);
+
+ return preCompiledLayer;
+}
+
} // namespace armnn