aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kelly <mike.kelly@arm.com>2021-08-04 17:27:40 +0100
committerMike Kelly <mike.kelly@arm.com>2021-08-04 19:06:26 +0100
commit8c999dfeeca7b02a6ea1d0cdcd8c34472f6c9cce (patch)
treeb307c2210745b663dde3ddf00769ae2e929599db
parent554fa09a0f3d6c9c572634c9d2de9bfb6c3218b0 (diff)
downloadarmnn-8c999dfeeca7b02a6ea1d0cdcd8c34472f6c9cce.tar.gz
Fixed bugs in PreCompiledLayer
* Fixed PreCompiledObject type (was const void** instead of void*) * Fixed bug where a new shared_ptr was being created instead of allowing std::move to convert the unique_ptr into a shared_ptr. * Improved tests to ensure that the original pointer is maintained. Signed-off-by: Mike Kelly <mike.kelly@arm.com> Change-Id: I3f50d51775ee0180c894c2843ed7bc990a771dea
-rw-r--r--src/armnn/layers/PreCompiledLayer.cpp2
-rw-r--r--src/armnn/layers/PreCompiledLayer.hpp2
-rw-r--r--src/armnn/test/CloneTests.cpp26
3 files changed, 15 insertions, 15 deletions
diff --git a/src/armnn/layers/PreCompiledLayer.cpp b/src/armnn/layers/PreCompiledLayer.cpp
index 0cc9c5a75a..67c1db4011 100644
--- a/src/armnn/layers/PreCompiledLayer.cpp
+++ b/src/armnn/layers/PreCompiledLayer.cpp
@@ -46,7 +46,7 @@ void PreCompiledLayer::ValidateTensorShapesFromInputs()
void PreCompiledLayer::SetPreCompiledObject(PreCompiledObjectPtr preCompiledObject)
{
- m_PreCompiledObject = std::make_shared<const void*>(preCompiledObject.release());
+ m_PreCompiledObject = std::move(preCompiledObject);
}
void PreCompiledLayer::Accept(ILayerVisitor& visitor) const
diff --git a/src/armnn/layers/PreCompiledLayer.hpp b/src/armnn/layers/PreCompiledLayer.hpp
index 6a8ac683ac..0db1472413 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;
- std::shared_ptr<const void*> m_PreCompiledObject;
+ std::shared_ptr<void> m_PreCompiledObject;
};
} // namespace armnn
diff --git a/src/armnn/test/CloneTests.cpp b/src/armnn/test/CloneTests.cpp
index 2ee2cdad0e..b59e8a4806 100644
--- a/src/armnn/test/CloneTests.cpp
+++ b/src/armnn/test/CloneTests.cpp
@@ -25,12 +25,18 @@ const armnn::BackendId& GetCloneIdStatic()
return s_Id;
}
+template <typename T>
+void DeleteAsType(const void* const blob)
+{
+ delete static_cast<const T*>(blob);
+}
+
class TestWorkloadFactory : public armnn::WorkloadFactoryBase
{
public:
- TestWorkloadFactory()
- : m_Ptr(nullptr)
+ TestWorkloadFactory(void* ptr)
+ : m_Ptr(ptr)
{}
const armnn::BackendId& GetBackendId() const override
@@ -41,14 +47,7 @@ public:
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;
- }
+ CHECK(descriptor.m_PreCompiledObject == m_Ptr);
return nullptr;
}
@@ -67,9 +66,10 @@ TEST_CASE ("PreCompiledLayerClonePreservesObject")
armnn::Layer* const preCompiledLayer = graph1.AddLayer<armnn::PreCompiledLayer>(descriptor, "preCompiled");
armnn::PreCompiledLayer* layer = armnn::PolymorphicDowncast<armnn::PreCompiledLayer*>(preCompiledLayer);
+ std::unique_ptr<std::string> payload = std::make_unique<std::string>("Hello");
- armnn::PreCompiledObjectPtr payloadObject;
- TestWorkloadFactory factory;
+ armnn::PreCompiledObjectPtr payloadObject(payload.release(), DeleteAsType<std::string>);
+ TestWorkloadFactory factory(payloadObject.get());
layer->SetPreCompiledObject(std::move(payloadObject));
layer->CreateWorkload(factory);
@@ -90,7 +90,7 @@ TEST_CASE ("PreCompiledLayerCloneNoObject")
armnn::Layer* const preCompiledLayer = graph1.AddLayer<armnn::PreCompiledLayer>(descriptor, "preCompiled");
armnn::PreCompiledLayer* layer = armnn::PolymorphicDowncast<armnn::PreCompiledLayer*>(preCompiledLayer);
- TestWorkloadFactory factory;
+ TestWorkloadFactory factory(nullptr);
layer->CreateWorkload(factory);
armnn::PreCompiledLayer* clone = layer->Clone(graph2);