diff options
author | Narumol Prangnawarat <narumol.prangnawarat@arm.com> | 2022-01-17 18:03:14 +0000 |
---|---|---|
committer | Narumol Prangnawarat <narumol.prangnawarat@arm.com> | 2022-01-24 20:24:12 +0000 |
commit | d12b40792591309c627f215574aa082a5efd03ca (patch) | |
tree | 98f5f903db2dd6e782c5c46a7a7797bd4302bb4a /src/backends/cl/test/ClBackendTests.cpp | |
parent | faf2966888ecd0b93726602bf4b0b1bd36301d8c (diff) | |
download | armnn-d12b40792591309c627f215574aa082a5efd03ca.tar.gz |
IVGCVSW-6677 Register CopyAndImportFactoryPairs to ClBackend and unit tests
Signed-off-by: Narumol Prangnawarat <narumol.prangnawarat@arm.com>
Change-Id: Ib0bf99c81ae1b30079be194a82b207761cb56028
Diffstat (limited to 'src/backends/cl/test/ClBackendTests.cpp')
-rw-r--r-- | src/backends/cl/test/ClBackendTests.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
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())); +} +} |