aboutsummaryrefslogtreecommitdiff
path: root/src/backends/tosaReference/TosaRefBackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/backends/tosaReference/TosaRefBackend.cpp')
-rw-r--r--src/backends/tosaReference/TosaRefBackend.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/backends/tosaReference/TosaRefBackend.cpp b/src/backends/tosaReference/TosaRefBackend.cpp
index 093802958b..688cf93b49 100644
--- a/src/backends/tosaReference/TosaRefBackend.cpp
+++ b/src/backends/tosaReference/TosaRefBackend.cpp
@@ -9,6 +9,7 @@
#include "TosaRefLayerSupport.hpp"
#include "TosaRefTensorHandleFactory.hpp"
+#include <tosaCommon/TosaMappings.hpp>
#include <armnn/BackendRegistry.hpp>
#include <armnn/backends/IBackendContext.hpp>
#include <armnn/backends/IMemoryManager.hpp>
@@ -21,6 +22,13 @@
namespace armnn
{
+// Utility function to construct a valid Deleter for TosaSerializationHandler ptrs passed back to ArmNN
+template <typename T>
+void DeleteAsType(const void* const blob)
+{
+ delete static_cast<const T*>(blob);
+}
+
const BackendId& TosaRefBackend::GetIdStatic()
{
static const BackendId s_Id{TosaRefBackendId()};
@@ -75,11 +83,44 @@ OptimizationViews TosaRefBackend::OptimizeSubgraphView(const SubgraphView& subgr
const ModelOptions& modelOptions) const
{
OptimizationViews optimizationViews(modelOptions);
- optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
-
+ auto handler = std::make_unique<TosaSerializationHandler>();
+
+ auto it = subgraph.endIConnectable();
+ while (it != subgraph.beginIConnectable())
+ {
+ --it;
+ Layer &base = *(PolymorphicDowncast<Layer*>(*it));
+
+ if(base.GetType() == armnn::LayerType::Input ||
+ base.GetType() == armnn::LayerType::Output)
+ {
+ continue;
+ }
+
+ tosa::TosaSerializationBasicBlock* mappings = GetTosaMappingFromLayer(&base);
+ handler.get()->GetBlocks().push_back(mappings);
+ }
+
+ auto compiledBlob =
+ std::make_unique<PreCompiledObjectPtr>(handler.release(), DeleteAsType<TosaSerializationHandler>);
+
+ IConnectableLayer* preCompiledLayer = optimizationViews.GetINetwork()->AddPrecompiledLayer(
+ PreCompiledDescriptor(subgraph.GetNumInputSlots(), subgraph.GetNumOutputSlots()),
+ std::move(*compiledBlob),
+ armnn::Optional<BackendId>(GetId()),
+ "TOSA_Pre_Compiled_Layer");
+
+ // Copy the output tensor infos from sub-graph
+ for (unsigned int i = 0; i < subgraph.GetNumOutputSlots(); i++)
+ {
+ preCompiledLayer->GetOutputSlot(i).SetTensorInfo(subgraph.GetIOutputSlot(i)->GetTensorInfo());
+ }
+
+ optimizationViews.AddSubstitution({ std::move(subgraph), SubgraphView(preCompiledLayer) });
return optimizationViews;
}
+
std::vector<ITensorHandleFactory::FactoryId> TosaRefBackend::GetHandleFactoryPreferences() const
{
return std::vector<ITensorHandleFactory::FactoryId> { TosaRefTensorHandleFactory::GetIdStatic() };