From d9e55f05847792edbbf6a8c2c4d3901d37f63d1f Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Wed, 11 Jan 2023 13:03:21 +0000 Subject: Move tuning and IClTensorHandle code from cl to aclCommon backend. * Required to enable easier future merging and rebase into experimental/GpuFsa as part of IVGCVSW-7380. Signed-off-by: Cathal Corbett Change-Id: I066dcf00523ff430a0908666e452548ab848bd86 --- src/backends/cl/test/CMakeLists.txt | 4 +- src/backends/cl/test/ClDefaultAllocatorTests.cpp | 194 +++++++++++++++++++++++ src/backends/cl/test/DefaultAllocatorTests.cpp | 194 ----------------------- 3 files changed, 196 insertions(+), 196 deletions(-) create mode 100644 src/backends/cl/test/ClDefaultAllocatorTests.cpp delete mode 100644 src/backends/cl/test/DefaultAllocatorTests.cpp (limited to 'src/backends/cl/test') diff --git a/src/backends/cl/test/CMakeLists.txt b/src/backends/cl/test/CMakeLists.txt index ec1d0a6c2f..6568d48ce5 100644 --- a/src/backends/cl/test/CMakeLists.txt +++ b/src/backends/cl/test/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright © 2017 Arm Ltd. All rights reserved. +# Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -8,6 +8,7 @@ list(APPEND armnnClBackendUnitTests_sources ClContextControlFixture.hpp ClContextSerializerTests.cpp ClCustomAllocatorTests.cpp + ClDefaultAllocatorTests.cpp ClCreateWorkloadTests.cpp ClEndToEndTests.cpp ClImportTensorHandleFactoryTests.cpp @@ -18,7 +19,6 @@ list(APPEND armnnClBackendUnitTests_sources ClOptimizedNetworkTests.cpp ClRuntimeTests.cpp ClWorkloadFactoryHelper.hpp - DefaultAllocatorTests.cpp Fp16SupportTest.cpp ICLTensorProxyTests.cpp OpenClTimerTest.cpp diff --git a/src/backends/cl/test/ClDefaultAllocatorTests.cpp b/src/backends/cl/test/ClDefaultAllocatorTests.cpp new file mode 100644 index 0000000000..411a480815 --- /dev/null +++ b/src/backends/cl/test/ClDefaultAllocatorTests.cpp @@ -0,0 +1,194 @@ +// +// Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include +#include +#include +#include +#include +#include +// Requires the OpenCl backend to be included (GpuAcc) +#include +#include +#include +#include +#include + +using namespace armnn; + + +namespace +{ + +TEST_SUITE("DefaultAllocatorTests") +{ + +TEST_CASE("DefaultAllocatorTest") +{ + float number = 3; + + TensorInfo inputTensorInfo(TensorShape({1, 1}), DataType::Float32); + + // Create ArmNN runtime + IRuntime::CreationOptions options; // default options + auto customAllocator = std::make_shared(); + options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; + IRuntimePtr run = IRuntime::Create(options); + + // Creates structures for input & output + unsigned int numElements = inputTensorInfo.GetNumElements(); + size_t totalBytes = numElements * sizeof(float); + + void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); + + auto* inputPtr = reinterpret_cast(alignedInputPtr); + std::fill_n(inputPtr, numElements, number); + CHECK(inputPtr[0] == 3); + + auto& backendRegistry = armnn::BackendRegistryInstance(); + backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); +} + +TEST_CASE("DefaultAllocatorTestMulti") +{ + float number = 3; + + TensorInfo inputTensorInfo(TensorShape({2, 1}), DataType::Float32); + + // Create ArmNN runtime + IRuntime::CreationOptions options; // default options + auto customAllocator = std::make_shared(); + options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; + IRuntimePtr run = IRuntime::Create(options); + + // Creates structures for input & output + unsigned int numElements = inputTensorInfo.GetNumElements(); + size_t totalBytes = numElements * sizeof(float); + + void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); + void* alignedInputPtr2 = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); + + auto* inputPtr = reinterpret_cast(alignedInputPtr); + std::fill_n(inputPtr, numElements, number); + CHECK(inputPtr[0] == 3); + CHECK(inputPtr[1] == 3); + + auto* inputPtr2 = reinterpret_cast(alignedInputPtr2); + std::fill_n(inputPtr2, numElements, number); + CHECK(inputPtr2[0] == 3); + CHECK(inputPtr2[1] == 3); + + // No overlap + CHECK(inputPtr[0] == 3); + CHECK(inputPtr[1] == 3); + + auto& backendRegistry = armnn::BackendRegistryInstance(); + backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); +} + +TEST_CASE("DefaultAllocatorTestMock") +{ + // Create ArmNN runtime + IRuntime::CreationOptions options; // default options + IRuntimePtr run = IRuntime::Create(options); + + // Initialize Mock Backend + MockBackendInitialiser initialiser; + auto factoryFun = BackendRegistryInstance().GetFactory(MockBackend().GetIdStatic()); + ARMNN_ASSERT(factoryFun != nullptr); + auto backend = factoryFun(); + auto defaultAllocator = backend->GetDefaultAllocator(); + + // GetMemorySourceType + CHECK(defaultAllocator->GetMemorySourceType() == MemorySource::Malloc); + + size_t totalBytes = 1 * sizeof(float); + // Allocate + void* ptr = defaultAllocator->allocate(totalBytes, 0); + + // GetMemoryRegionAtOffset + CHECK(defaultAllocator->GetMemoryRegionAtOffset(ptr, 0, 0)); + + // Free + defaultAllocator->free(ptr); + + // Clean up + auto& backendRegistry = armnn::BackendRegistryInstance(); + backendRegistry.Deregister(MockBackend().GetIdStatic()); + backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); +} + +} + + +TEST_SUITE("ClDefaultAllocatorTests") +{ + +TEST_CASE("ClDefaultAllocatorTest") +{ + float number = 3; + + TensorInfo inputTensorInfo(TensorShape({1, 1}), DataType::Float32); + + // Create ArmNN runtime + IRuntime::CreationOptions options; // default options + auto customAllocator = std::make_shared(); + options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; + IRuntimePtr run = IRuntime::Create(options); + + // Creates structures for input & output + unsigned int numElements = inputTensorInfo.GetNumElements(); + size_t totalBytes = numElements * sizeof(float); + + void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); + + auto* inputPtr = reinterpret_cast(alignedInputPtr); + std::fill_n(inputPtr, numElements, number); + CHECK(inputPtr[0] == 3); + + auto& backendRegistry = armnn::BackendRegistryInstance(); + backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); +} + +TEST_CASE("ClDefaultAllocatorTestMulti") +{ + float number = 3; + + TensorInfo inputTensorInfo(TensorShape({2, 1}), DataType::Float32); + + // Create ArmNN runtime + IRuntime::CreationOptions options; // default options + auto customAllocator = std::make_shared(); + options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; + IRuntimePtr run = IRuntime::Create(options); + + // Creates structures for input & output + unsigned int numElements = inputTensorInfo.GetNumElements(); + size_t totalBytes = numElements * sizeof(float); + + void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); + void* alignedInputPtr2 = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); + + auto* inputPtr = reinterpret_cast(alignedInputPtr); + std::fill_n(inputPtr, numElements, number); + CHECK(inputPtr[0] == 3); + CHECK(inputPtr[1] == 3); + + auto* inputPtr2 = reinterpret_cast(alignedInputPtr2); + std::fill_n(inputPtr2, numElements, number); + CHECK(inputPtr2[0] == 3); + CHECK(inputPtr2[1] == 3); + + // No overlap + CHECK(inputPtr[0] == 3); + CHECK(inputPtr[1] == 3); + + auto& backendRegistry = armnn::BackendRegistryInstance(); + backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); +} + +} + +} // namespace armnn \ No newline at end of file diff --git a/src/backends/cl/test/DefaultAllocatorTests.cpp b/src/backends/cl/test/DefaultAllocatorTests.cpp deleted file mode 100644 index eaa30c8800..0000000000 --- a/src/backends/cl/test/DefaultAllocatorTests.cpp +++ /dev/null @@ -1,194 +0,0 @@ -// -// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include -#include -#include -#include -#include -#include -// Requires the OpenCl backend to be included (GpuAcc) -#include -#include -#include -#include -#include - -using namespace armnn; - - -namespace -{ - -TEST_SUITE("DefaultAllocatorTests") -{ - -TEST_CASE("DefaultAllocatorTest") -{ - float number = 3; - - TensorInfo inputTensorInfo(TensorShape({1, 1}), DataType::Float32); - - // Create ArmNN runtime - IRuntime::CreationOptions options; // default options - auto customAllocator = std::make_shared(); - options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; - IRuntimePtr run = IRuntime::Create(options); - - // Creates structures for input & output - unsigned int numElements = inputTensorInfo.GetNumElements(); - size_t totalBytes = numElements * sizeof(float); - - void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); - - auto* inputPtr = reinterpret_cast(alignedInputPtr); - std::fill_n(inputPtr, numElements, number); - CHECK(inputPtr[0] == 3); - - auto& backendRegistry = armnn::BackendRegistryInstance(); - backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); -} - -TEST_CASE("DefaultAllocatorTestMulti") -{ - float number = 3; - - TensorInfo inputTensorInfo(TensorShape({2, 1}), DataType::Float32); - - // Create ArmNN runtime - IRuntime::CreationOptions options; // default options - auto customAllocator = std::make_shared(); - options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; - IRuntimePtr run = IRuntime::Create(options); - - // Creates structures for input & output - unsigned int numElements = inputTensorInfo.GetNumElements(); - size_t totalBytes = numElements * sizeof(float); - - void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); - void* alignedInputPtr2 = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); - - auto* inputPtr = reinterpret_cast(alignedInputPtr); - std::fill_n(inputPtr, numElements, number); - CHECK(inputPtr[0] == 3); - CHECK(inputPtr[1] == 3); - - auto* inputPtr2 = reinterpret_cast(alignedInputPtr2); - std::fill_n(inputPtr2, numElements, number); - CHECK(inputPtr2[0] == 3); - CHECK(inputPtr2[1] == 3); - - // No overlap - CHECK(inputPtr[0] == 3); - CHECK(inputPtr[1] == 3); - - auto& backendRegistry = armnn::BackendRegistryInstance(); - backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); -} - -TEST_CASE("DefaultAllocatorTestMock") -{ - // Create ArmNN runtime - IRuntime::CreationOptions options; // default options - IRuntimePtr run = IRuntime::Create(options); - - // Initialize Mock Backend - MockBackendInitialiser initialiser; - auto factoryFun = BackendRegistryInstance().GetFactory(MockBackend().GetIdStatic()); - ARMNN_ASSERT(factoryFun != nullptr); - auto backend = factoryFun(); - auto defaultAllocator = backend->GetDefaultAllocator(); - - // GetMemorySourceType - CHECK(defaultAllocator->GetMemorySourceType() == MemorySource::Malloc); - - size_t totalBytes = 1 * sizeof(float); - // Allocate - void* ptr = defaultAllocator->allocate(totalBytes, 0); - - // GetMemoryRegionAtOffset - CHECK(defaultAllocator->GetMemoryRegionAtOffset(ptr, 0, 0)); - - // Free - defaultAllocator->free(ptr); - - // Clean up - auto& backendRegistry = armnn::BackendRegistryInstance(); - backendRegistry.Deregister(MockBackend().GetIdStatic()); - backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); -} - -} - - -TEST_SUITE("ClDefaultAllocatorTests") -{ - -TEST_CASE("ClDefaultAllocatorTest") -{ - float number = 3; - - TensorInfo inputTensorInfo(TensorShape({1, 1}), DataType::Float32); - - // Create ArmNN runtime - IRuntime::CreationOptions options; // default options - auto customAllocator = std::make_shared(); - options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; - IRuntimePtr run = IRuntime::Create(options); - - // Creates structures for input & output - unsigned int numElements = inputTensorInfo.GetNumElements(); - size_t totalBytes = numElements * sizeof(float); - - void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); - - auto* inputPtr = reinterpret_cast(alignedInputPtr); - std::fill_n(inputPtr, numElements, number); - CHECK(inputPtr[0] == 3); - - auto& backendRegistry = armnn::BackendRegistryInstance(); - backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); -} - -TEST_CASE("ClDefaultAllocatorTestMulti") -{ - float number = 3; - - TensorInfo inputTensorInfo(TensorShape({2, 1}), DataType::Float32); - - // Create ArmNN runtime - IRuntime::CreationOptions options; // default options - auto customAllocator = std::make_shared(); - options.m_CustomAllocatorMap = {{"GpuAcc", std::move(customAllocator)}}; - IRuntimePtr run = IRuntime::Create(options); - - // Creates structures for input & output - unsigned int numElements = inputTensorInfo.GetNumElements(); - size_t totalBytes = numElements * sizeof(float); - - void* alignedInputPtr = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); - void* alignedInputPtr2 = options.m_CustomAllocatorMap["GpuAcc"]->allocate(totalBytes, 0); - - auto* inputPtr = reinterpret_cast(alignedInputPtr); - std::fill_n(inputPtr, numElements, number); - CHECK(inputPtr[0] == 3); - CHECK(inputPtr[1] == 3); - - auto* inputPtr2 = reinterpret_cast(alignedInputPtr2); - std::fill_n(inputPtr2, numElements, number); - CHECK(inputPtr2[0] == 3); - CHECK(inputPtr2[1] == 3); - - // No overlap - CHECK(inputPtr[0] == 3); - CHECK(inputPtr[1] == 3); - - auto& backendRegistry = armnn::BackendRegistryInstance(); - backendRegistry.DeregisterAllocator(ClBackend::GetIdStatic()); -} - -} - -} // namespace armnn \ No newline at end of file -- cgit v1.2.1