diff options
author | Matthew Bentham <matthew.bentham@arm.com> | 2022-02-11 08:29:42 +0000 |
---|---|---|
committer | Matthew Bentham <matthew.bentham@arm.com> | 2022-02-11 12:29:03 +0000 |
commit | 79bb6531358d5a780e8e86bce99fd39ae847c2f4 (patch) | |
tree | c818b67a263194947ba2181aa3b42de7ff86fc6e /src | |
parent | bfa767ca56f9776e7dd3eecb4025cfeed87f9936 (diff) | |
download | armnn-79bb6531358d5a780e8e86bce99fd39ae847c2f4.tar.gz |
Fix unit test where NeonMemoryManager was used instead of RefMemoryManager
Although the Neon and Ref backends can use each other's TensorHandles,
their TensorHandleFactories can't use each other's MemoryManagers.
Incorrectly passing the NeonMemoryManager to the RefTensorHandleFactory
in unit test utility code resulted in an incorrect static_pointer_cast
and a warning from the Undefined Behaviour Sanitizer.
This change fixes the test code, and replaces use of static_pointer_cast
with armnn::PolymorphicPointerDowncast which will check that the cast is
legal in debug builds.
Also, remove MockWorkloadFactoryHelper.hpp as it is unused.
Signed-off-by: Matthew Bentham <matthew.bentham@arm.com>
Change-Id: I2b425e86fccacd7cc5ff186521fc6e53e7e50c77
Diffstat (limited to 'src')
-rwxr-xr-x | src/armnnTestUtils/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/armnnTestUtils/UnitTests.hpp | 6 | ||||
-rw-r--r-- | src/backends/neon/NeonTimer.cpp | 3 | ||||
-rw-r--r-- | src/backends/reference/test/RefWorkloadFactoryHelper.hpp | 4 |
4 files changed, 9 insertions, 7 deletions
diff --git a/src/armnnTestUtils/CMakeLists.txt b/src/armnnTestUtils/CMakeLists.txt index e33fed77d7..061dd90d3d 100755 --- a/src/armnnTestUtils/CMakeLists.txt +++ b/src/armnnTestUtils/CMakeLists.txt @@ -11,7 +11,6 @@ list(APPEND armnnTestUtils_sources ../../include/armnnTestUtils/MockBackend.hpp ../../include/armnnTestUtils/MockMemoryManager.hpp ../../include/armnnTestUtils/MockTensorHandle.hpp - ../../include/armnnTestUtils/MockWorkloadFactoryHelper.hpp ../../include/armnnTestUtils/PredicateResult.hpp ../../include/armnnTestUtils/TensorCopyUtils.hpp ../../include/armnnTestUtils/WorkloadTestUtils.hpp @@ -57,4 +56,4 @@ install(TARGETS armnnTestUtils ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -add_library(Armnn::armnnTestUtils ALIAS armnnTestUtils)
\ No newline at end of file +add_library(Armnn::armnnTestUtils ALIAS armnnTestUtils) diff --git a/src/armnnTestUtils/UnitTests.hpp b/src/armnnTestUtils/UnitTests.hpp index f560720c9b..71324dbf81 100644 --- a/src/armnnTestUtils/UnitTests.hpp +++ b/src/armnnTestUtils/UnitTests.hpp @@ -155,11 +155,11 @@ void CompareRefTestFunctionUsingTensorHandleFactory(const char* testName, TFuncP { auto memoryManager = WorkloadFactoryHelper<FactoryType>::GetMemoryManager(); FactoryType workloadFactory = WorkloadFactoryHelper<FactoryType>::GetFactory(memoryManager); + auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager); armnn::RefWorkloadFactory refWorkloadFactory; - auto tensorHandleFactory = WorkloadFactoryHelper<FactoryType>::GetTensorHandleFactory(memoryManager); - auto refTensorHandleFactory = - RefWorkloadFactoryHelper::GetTensorHandleFactory(memoryManager); + auto refMemoryManager = WorkloadFactoryHelper<armnn::RefWorkloadFactory>::GetMemoryManager(); + auto refTensorHandleFactory = RefWorkloadFactoryHelper::GetTensorHandleFactory(refMemoryManager); auto testResult = (*testFunction)( workloadFactory, memoryManager, refWorkloadFactory, tensorHandleFactory, refTensorHandleFactory, args...); diff --git a/src/backends/neon/NeonTimer.cpp b/src/backends/neon/NeonTimer.cpp index 5cce0511ab..a7d3032b13 100644 --- a/src/backends/neon/NeonTimer.cpp +++ b/src/backends/neon/NeonTimer.cpp @@ -7,6 +7,7 @@ #include "NeonInterceptorScheduler.hpp" #include <armnn/utility/Assert.hpp> +#include <armnn/utility/PolymorphicDowncast.hpp> #include <memory> @@ -29,7 +30,7 @@ void NeonTimer::Start() { // Keep the real schedule and add NeonInterceptorScheduler as an interceptor m_RealScheduler = &arm_compute::Scheduler::get(); - arm_compute::Scheduler::set(std::static_pointer_cast<arm_compute::IScheduler>(g_Interceptor)); + arm_compute::Scheduler::set(armnn::PolymorphicPointerDowncast<arm_compute::IScheduler>(g_Interceptor)); } } diff --git a/src/backends/reference/test/RefWorkloadFactoryHelper.hpp b/src/backends/reference/test/RefWorkloadFactoryHelper.hpp index e413d045f9..f0a842de57 100644 --- a/src/backends/reference/test/RefWorkloadFactoryHelper.hpp +++ b/src/backends/reference/test/RefWorkloadFactoryHelper.hpp @@ -7,6 +7,8 @@ #include <backendsCommon/test/WorkloadFactoryHelper.hpp> +#include <armnn/utility/PolymorphicDowncast.hpp> + #include <reference/RefBackend.hpp> #include <reference/RefWorkloadFactory.hpp> #include "reference/RefTensorHandleFactory.hpp" @@ -34,7 +36,7 @@ struct WorkloadFactoryHelper<armnn::RefWorkloadFactory> const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager = nullptr) { - return armnn::RefTensorHandleFactory(std::static_pointer_cast<armnn::RefMemoryManager>(memoryManager)); + return armnn::RefTensorHandleFactory(armnn::PolymorphicPointerDowncast<armnn::RefMemoryManager>(memoryManager)); } }; |