aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNarumol Prangnawarat <narumol.prangnawarat@arm.com>2022-01-17 18:03:14 +0000
committerNarumol Prangnawarat <narumol.prangnawarat@arm.com>2022-01-24 20:24:12 +0000
commitd12b40792591309c627f215574aa082a5efd03ca (patch)
tree98f5f903db2dd6e782c5c46a7a7797bd4302bb4a
parentfaf2966888ecd0b93726602bf4b0b1bd36301d8c (diff)
downloadarmnn-d12b40792591309c627f215574aa082a5efd03ca.tar.gz
IVGCVSW-6677 Register CopyAndImportFactoryPairs to ClBackend and unit tests
Signed-off-by: Narumol Prangnawarat <narumol.prangnawarat@arm.com> Change-Id: Ib0bf99c81ae1b30079be194a82b207761cb56028
-rw-r--r--src/backends/cl/ClBackend.cpp59
-rw-r--r--src/backends/cl/backend.mk1
-rw-r--r--src/backends/cl/test/CMakeLists.txt1
-rw-r--r--src/backends/cl/test/ClBackendTests.cpp83
4 files changed, 131 insertions, 13 deletions
diff --git a/src/backends/cl/ClBackend.cpp b/src/backends/cl/ClBackend.cpp
index cf5f50025a..8abb16ccca 100644
--- a/src/backends/cl/ClBackend.cpp
+++ b/src/backends/cl/ClBackend.cpp
@@ -84,10 +84,16 @@ IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory(
memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
}
+ std::unique_ptr<ITensorHandleFactory> factory = std::make_unique<ClTensorHandleFactory>(memoryManager);
+ std::unique_ptr<ITensorHandleFactory> importFactory = std::make_unique<ClImportTensorHandleFactory>(
+ static_cast<MemorySourceFlags>(MemorySource::Malloc), static_cast<MemorySourceFlags>(MemorySource::Malloc));
+
+ registry.RegisterCopyAndImportFactoryPair(factory->GetId(), importFactory->GetId());
+ registry.RegisterCopyAndImportFactoryPair(importFactory->GetId(), factory->GetId());
+
registry.RegisterMemoryManager(memoryManager);
- registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager));
- registry.RegisterFactory(std::make_unique<ClImportTensorHandleFactory>(
- static_cast<MemorySourceFlags>(MemorySource::Malloc), static_cast<MemorySourceFlags>(MemorySource::Malloc)));
+ registry.RegisterFactory(std::move(factory));
+ registry.RegisterFactory(std::move(importFactory));
return std::make_unique<ClWorkloadFactory>(
PolymorphicPointerDowncast<ClMemoryManager>(memoryManager));
@@ -106,10 +112,16 @@ IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory(
memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
}
+ std::unique_ptr<ITensorHandleFactory> factory = std::make_unique<ClTensorHandleFactory>(memoryManager);
+ std::unique_ptr<ITensorHandleFactory> importFactory = std::make_unique<ClImportTensorHandleFactory>(
+ static_cast<MemorySourceFlags>(MemorySource::Malloc), static_cast<MemorySourceFlags>(MemorySource::Malloc));
+
+ registry.RegisterCopyAndImportFactoryPair(factory->GetId(), importFactory->GetId());
+ registry.RegisterCopyAndImportFactoryPair(importFactory->GetId(), factory->GetId());
+
registry.RegisterMemoryManager(memoryManager);
- registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager));
- registry.RegisterFactory(std::make_unique<ClImportTensorHandleFactory>(
- static_cast<MemorySourceFlags>(MemorySource::Malloc), static_cast<MemorySourceFlags>(MemorySource::Malloc)));
+ registry.RegisterFactory(std::move(factory));
+ registry.RegisterFactory(std::move(importFactory));
return std::make_unique<ClWorkloadFactory>(
PolymorphicPointerDowncast<ClMemoryManager>(memoryManager), CreateBackendSpecificModelContext(modelOptions));
@@ -131,9 +143,16 @@ IBackendInternal::IWorkloadFactoryPtr ClBackend::CreateWorkloadFactory(
memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
}
+ std::unique_ptr<ITensorHandleFactory> factory = std::make_unique<ClTensorHandleFactory>(memoryManager);
+ std::unique_ptr<ITensorHandleFactory> importFactory = std::make_unique<ClImportTensorHandleFactory>(
+ inputFlags, outputFlags);
+
+ registry.RegisterCopyAndImportFactoryPair(factory->GetId(), importFactory->GetId());
+ registry.RegisterCopyAndImportFactoryPair(importFactory->GetId(), factory->GetId());
+
registry.RegisterMemoryManager(memoryManager);
- registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager));
- registry.RegisterFactory(std::make_unique<ClImportTensorHandleFactory>(inputFlags, outputFlags));
+ registry.RegisterFactory(std::move(factory));
+ registry.RegisterFactory(std::move(importFactory));
return std::make_unique<ClWorkloadFactory>(
PolymorphicPointerDowncast<ClMemoryManager>(memoryManager), CreateBackendSpecificModelContext(modelOptions));
@@ -157,10 +176,17 @@ void ClBackend::RegisterTensorHandleFactories(TensorHandleFactoryRegistry& regis
memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
}
+ std::unique_ptr<ITensorHandleFactory> factory = std::make_unique<ClTensorHandleFactory>(memoryManager);
+ std::unique_ptr<ITensorHandleFactory> importFactory = std::make_unique<ClImportTensorHandleFactory>(
+ static_cast<MemorySourceFlags>(MemorySource::Malloc), static_cast<MemorySourceFlags>(MemorySource::Malloc));
+
+ registry.RegisterCopyAndImportFactoryPair(factory->GetId(), importFactory->GetId());
+ registry.RegisterCopyAndImportFactoryPair(importFactory->GetId(), factory->GetId());
+
registry.RegisterMemoryManager(memoryManager);
- registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager));
- registry.RegisterFactory(std::make_unique<ClImportTensorHandleFactory>(
- static_cast<MemorySourceFlags>(MemorySource::Malloc), static_cast<MemorySourceFlags>(MemorySource::Malloc)));
+ registry.RegisterFactory(std::move(factory));
+ registry.RegisterFactory(std::move(importFactory));
+
}
void ClBackend::RegisterTensorHandleFactories(TensorHandleFactoryRegistry& registry,
@@ -177,9 +203,16 @@ void ClBackend::RegisterTensorHandleFactories(TensorHandleFactoryRegistry& regis
memoryManager = std::make_shared<ClMemoryManager>(std::make_unique<arm_compute::CLBufferAllocator>());
}
+ std::unique_ptr<ITensorHandleFactory> factory = std::make_unique<ClTensorHandleFactory>(memoryManager);
+ std::unique_ptr<ITensorHandleFactory> importFactory = std::make_unique<ClImportTensorHandleFactory>(
+ inputFlags, outputFlags);
+
+ registry.RegisterCopyAndImportFactoryPair(factory->GetId(), importFactory->GetId());
+ registry.RegisterCopyAndImportFactoryPair(importFactory->GetId(), factory->GetId());
+
registry.RegisterMemoryManager(memoryManager);
- registry.RegisterFactory(std::make_unique<ClTensorHandleFactory>(memoryManager));
- registry.RegisterFactory(std::make_unique<ClImportTensorHandleFactory>(inputFlags, outputFlags));
+ registry.RegisterFactory(std::move(factory));
+ registry.RegisterFactory(std::move(importFactory));
}
IBackendInternal::IBackendContextPtr ClBackend::CreateBackendContext(const IRuntime::CreationOptions& options) const
diff --git a/src/backends/cl/backend.mk b/src/backends/cl/backend.mk
index c59a22dee4..5bef3a786b 100644
--- a/src/backends/cl/backend.mk
+++ b/src/backends/cl/backend.mk
@@ -106,6 +106,7 @@ ifeq ($(ARMNN_COMPUTE_CL_ENABLED),1)
# Include the source files for the CL backend tests
BACKEND_TEST_SOURCES := \
+ test/ClBackendTests.cpp \
test/ClContextSerializerTests.cpp \
test/ClCreateWorkloadTests.cpp \
test/ClEndToEndTests.cpp \
diff --git a/src/backends/cl/test/CMakeLists.txt b/src/backends/cl/test/CMakeLists.txt
index af116a4e9f..9840b8289f 100644
--- a/src/backends/cl/test/CMakeLists.txt
+++ b/src/backends/cl/test/CMakeLists.txt
@@ -4,6 +4,7 @@
#
list(APPEND armnnClBackendUnitTests_sources
+ ClBackendTests.cpp
ClContextControlFixture.hpp
ClContextSerializerTests.cpp
ClCustomAllocatorTests.cpp
diff --git a/src/backends/cl/test/ClBackendTests.cpp b/src/backends/cl/test/ClBackendTests.cpp
new file mode 100644
index 0000000000..33f321653c
--- /dev/null
+++ b/src/backends/cl/test/ClBackendTests.cpp
@@ -0,0 +1,83 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <cl/ClBackend.hpp>
+#include <cl/ClTensorHandleFactory.hpp>
+#include <cl/ClImportTensorHandleFactory.hpp>
+#include <cl/test/ClContextControlFixture.hpp>
+
+#include <doctest/doctest.h>
+
+using namespace armnn;
+
+TEST_SUITE("ClBackendTests")
+{
+TEST_CASE("ClRegisterTensorHandleFactoriesMatchingImportFactoryId")
+{
+ auto clBackend = std::make_unique<ClBackend>();
+ TensorHandleFactoryRegistry registry;
+ clBackend->RegisterTensorHandleFactories(registry);
+
+ // When calling RegisterTensorHandleFactories, CopyAndImportFactoryPair is registered
+ // Get ClImportTensorHandleFactory id as the matching import factory id
+ CHECK((registry.GetMatchingImportFactoryId(ClTensorHandleFactory::GetIdStatic()) ==
+ ClImportTensorHandleFactory::GetIdStatic()));
+}
+
+TEST_CASE("ClRegisterTensorHandleFactoriesWithMemorySourceFlagsMatchingImportFactoryId")
+{
+ auto clBackend = std::make_unique<ClBackend>();
+ TensorHandleFactoryRegistry registry;
+ clBackend->RegisterTensorHandleFactories(registry,
+ static_cast<MemorySourceFlags>(MemorySource::Malloc),
+ static_cast<MemorySourceFlags>(MemorySource::Malloc));
+
+ // When calling RegisterTensorHandleFactories with MemorySourceFlags, CopyAndImportFactoryPair is registered
+ // Get ClImportTensorHandleFactory id as the matching import factory id
+ CHECK((registry.GetMatchingImportFactoryId(ClTensorHandleFactory::GetIdStatic()) ==
+ ClImportTensorHandleFactory::GetIdStatic()));
+}
+
+TEST_CASE_FIXTURE(ClContextControlFixture, "ClCreateWorkloadFactoryMatchingImportFactoryId")
+{
+ auto clBackend = std::make_unique<ClBackend>();
+ TensorHandleFactoryRegistry registry;
+ clBackend->CreateWorkloadFactory(registry);
+
+ // When calling CreateWorkloadFactory, CopyAndImportFactoryPair is registered
+ // Get ClImportTensorHandleFactory id as the matching import factory id
+ CHECK((registry.GetMatchingImportFactoryId(ClTensorHandleFactory::GetIdStatic()) ==
+ ClImportTensorHandleFactory::GetIdStatic()));
+}
+
+TEST_CASE_FIXTURE(ClContextControlFixture, "ClCreateWorkloadFactoryWithOptionsMatchingImportFactoryId")
+{
+ auto clBackend = std::make_unique<ClBackend>();
+ TensorHandleFactoryRegistry registry;
+ ModelOptions modelOptions;
+ clBackend->CreateWorkloadFactory(registry, modelOptions);
+
+ // When calling CreateWorkloadFactory with ModelOptions, CopyAndImportFactoryPair is registered
+ // Get ClImportTensorHandleFactory id as the matching import factory id
+ CHECK((registry.GetMatchingImportFactoryId(ClTensorHandleFactory::GetIdStatic()) ==
+ ClImportTensorHandleFactory::GetIdStatic()));
+}
+
+TEST_CASE_FIXTURE(ClContextControlFixture, "ClCreateWorkloadFactoryWitMemoryFlagsMatchingImportFactoryId")
+{
+ auto clBackend = std::make_unique<ClBackend>();
+ TensorHandleFactoryRegistry registry;
+ ModelOptions modelOptions;
+ clBackend->CreateWorkloadFactory(registry, modelOptions,
+ static_cast<MemorySourceFlags>(MemorySource::Malloc),
+ static_cast<MemorySourceFlags>(MemorySource::Malloc));
+
+ // When calling CreateWorkloadFactory with ModelOptions and MemorySourceFlags,
+ // CopyAndImportFactoryPair is registered
+ // Get ClImportTensorHandleFactory id as the matching import factory id
+ CHECK((registry.GetMatchingImportFactoryId(ClTensorHandleFactory::GetIdStatic()) ==
+ ClImportTensorHandleFactory::GetIdStatic()));
+}
+}