aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/Network.cpp9
-rw-r--r--src/armnn/OptimizedNetworkImpl.hpp1
-rw-r--r--src/armnn/layers/PreCompiledLayer.cpp4
-rw-r--r--src/armnn/layers/PreCompiledLayer.hpp2
-rw-r--r--src/armnn/test/CloneTests.cpp103
5 files changed, 116 insertions, 3 deletions
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp
index 71f19313b8..74c195f676 100644
--- a/src/armnn/Network.cpp
+++ b/src/armnn/Network.cpp
@@ -543,6 +543,8 @@ void INetwork::Destroy(INetwork* network)
delete network;
}
+IOptimizedNetwork::IOptimizedNetwork(const IOptimizedNetwork& other, const ModelOptions& modelOptions)
+ : pOptimizedNetworkImpl(new OptimizedNetworkImpl(*other.pOptimizedNetworkImpl.get(), modelOptions)) {}
IOptimizedNetwork::IOptimizedNetwork(std::unique_ptr<Graph> graph)
: pOptimizedNetworkImpl(new OptimizedNetworkImpl(std::move(graph))) {}
@@ -2621,6 +2623,13 @@ void NetworkImpl::ExecuteStrategy(IStrategy& strategy) const
};
}
+OptimizedNetworkImpl::OptimizedNetworkImpl(const OptimizedNetworkImpl& other, const ModelOptions& modelOptions)
+ : m_Graph(new Graph(*other.m_Graph.get()))
+ , m_Guid(profiling::ProfilingService::GetNextGuid())
+ , m_ModelOptions(modelOptions)
+{
+}
+
OptimizedNetworkImpl::OptimizedNetworkImpl(std::unique_ptr<Graph> graph)
: m_Graph(std::move(graph)), m_Guid(profiling::ProfilingService::GetNextGuid())
{
diff --git a/src/armnn/OptimizedNetworkImpl.hpp b/src/armnn/OptimizedNetworkImpl.hpp
index fe55ca233b..d42cff7346 100644
--- a/src/armnn/OptimizedNetworkImpl.hpp
+++ b/src/armnn/OptimizedNetworkImpl.hpp
@@ -11,6 +11,7 @@ namespace armnn
class OptimizedNetworkImpl
{
public:
+ OptimizedNetworkImpl(const OptimizedNetworkImpl& other, const ModelOptions& modelOptions);
OptimizedNetworkImpl(std::unique_ptr<Graph> graph);
OptimizedNetworkImpl(std::unique_ptr<Graph> graph, const ModelOptions& modelOptions);
virtual ~OptimizedNetworkImpl();
diff --git a/src/armnn/layers/PreCompiledLayer.cpp b/src/armnn/layers/PreCompiledLayer.cpp
index 75c1e46a84..0cc9c5a75a 100644
--- a/src/armnn/layers/PreCompiledLayer.cpp
+++ b/src/armnn/layers/PreCompiledLayer.cpp
@@ -24,7 +24,7 @@ PreCompiledLayer::~PreCompiledLayer()
PreCompiledLayer* PreCompiledLayer::Clone(Graph& graph) const
{
PreCompiledLayer* clone = CloneBase<PreCompiledLayer>(graph, m_Param, GetName());
- clone->m_PreCompiledObject.reset(const_cast<PreCompiledLayer*>(this)->m_PreCompiledObject.release());
+ clone->m_PreCompiledObject = const_cast<PreCompiledLayer*>(this)->m_PreCompiledObject;
return clone;
}
@@ -46,7 +46,7 @@ void PreCompiledLayer::ValidateTensorShapesFromInputs()
void PreCompiledLayer::SetPreCompiledObject(PreCompiledObjectPtr preCompiledObject)
{
- m_PreCompiledObject = std::move(preCompiledObject);
+ m_PreCompiledObject = std::make_shared<const void*>(preCompiledObject.release());
}
void PreCompiledLayer::Accept(ILayerVisitor& visitor) const
diff --git a/src/armnn/layers/PreCompiledLayer.hpp b/src/armnn/layers/PreCompiledLayer.hpp
index 2ed87578a4..6a8ac683ac 100644
--- a/src/armnn/layers/PreCompiledLayer.hpp
+++ b/src/armnn/layers/PreCompiledLayer.hpp
@@ -41,7 +41,7 @@ private:
PreCompiledLayer(const PreCompiledLayer& other) = delete;
PreCompiledLayer& operator=(const PreCompiledLayer& other) = delete;
- PreCompiledObjectPtr m_PreCompiledObject;
+ std::shared_ptr<const void*> m_PreCompiledObject;
};
} // namespace armnn
diff --git a/src/armnn/test/CloneTests.cpp b/src/armnn/test/CloneTests.cpp
new file mode 100644
index 0000000000..2ee2cdad0e
--- /dev/null
+++ b/src/armnn/test/CloneTests.cpp
@@ -0,0 +1,103 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <Graph.hpp>
+#include <Layer.hpp>
+
+#include <armnn/TypesUtils.hpp>
+#include <armnn/Exceptions.hpp>
+#include <armnn/Optional.hpp>
+#include <armnn/backends/IBackendInternal.hpp>
+#include <armnn/utility/PolymorphicDowncast.hpp>
+
+#include <backendsCommon/TensorHandle.hpp>
+#include <backendsCommon/WorkloadFactoryBase.hpp>
+
+#include <doctest/doctest.h>
+
+namespace {
+
+const armnn::BackendId& GetCloneIdStatic()
+{
+ static const armnn::BackendId s_Id{"Tests"};
+ return s_Id;
+}
+
+class TestWorkloadFactory : public armnn::WorkloadFactoryBase
+{
+public:
+
+ TestWorkloadFactory()
+ : m_Ptr(nullptr)
+ {}
+
+ const armnn::BackendId& GetBackendId() const override
+ {
+ return GetCloneIdStatic();
+ }
+
+ std::unique_ptr<armnn::IWorkload> CreatePreCompiled(const armnn::PreCompiledQueueDescriptor& descriptor,
+ const armnn::WorkloadInfo&) const override
+ {
+ if (m_Ptr)
+ {
+ CHECK(descriptor.m_PreCompiledObject == m_Ptr);
+ }
+ else
+ {
+ m_Ptr = descriptor.m_PreCompiledObject;
+ }
+ return nullptr;
+ }
+
+ mutable void* m_Ptr;
+};
+
+TEST_SUITE("CloneTests")
+{
+
+TEST_CASE ("PreCompiledLayerClonePreservesObject")
+{
+ armnn::Graph graph1;
+ armnn::Graph graph2;
+
+ armnn::PreCompiledDescriptor descriptor(0u, 0u);
+
+ armnn::Layer* const preCompiledLayer = graph1.AddLayer<armnn::PreCompiledLayer>(descriptor, "preCompiled");
+ armnn::PreCompiledLayer* layer = armnn::PolymorphicDowncast<armnn::PreCompiledLayer*>(preCompiledLayer);
+
+ armnn::PreCompiledObjectPtr payloadObject;
+ TestWorkloadFactory factory;
+
+ layer->SetPreCompiledObject(std::move(payloadObject));
+ layer->CreateWorkload(factory);
+
+ armnn::PreCompiledLayer* clone = layer->Clone(graph2);
+ CHECK(std::strcmp(clone->GetName(), "preCompiled") == 0);
+ clone->CreateWorkload(factory);
+}
+
+TEST_CASE ("PreCompiledLayerCloneNoObject")
+{
+ armnn::Graph graph1;
+
+ armnn::Graph graph2;
+
+ armnn::PreCompiledDescriptor descriptor(0u, 0u);
+
+ armnn::Layer* const preCompiledLayer = graph1.AddLayer<armnn::PreCompiledLayer>(descriptor, "preCompiled");
+ armnn::PreCompiledLayer* layer = armnn::PolymorphicDowncast<armnn::PreCompiledLayer*>(preCompiledLayer);
+
+ TestWorkloadFactory factory;
+ layer->CreateWorkload(factory);
+
+ armnn::PreCompiledLayer* clone = layer->Clone(graph2);
+ CHECK(std::strcmp(clone->GetName(), "preCompiled") == 0);
+ clone->CreateWorkload(factory);
+}
+
+}
+
+} // end anonymous namespace