From c42a987aa53d0fd842c34dee90abef5a9ff15fa4 Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Wed, 2 Feb 2022 16:35:09 +0000 Subject: IVGCVSW-6635 Move MemCopyTestImpl from acl to armnnTestUtils. * Move MemCopyTestImpl.hpp from src/backends/aclCommon/test/ to include/armnnTestutils. * Refactor MemCopyTests in aclCommon, cl and Neon. * Introduce RefMemCopyTests to exercise this utility in x86 builds. Signed-off-by: Colm Donelan Change-Id: I8824f013d3656658ed0a2904bb79384e3af68641 --- include/armnnTestUtils/MemCopyTestImpl.hpp | 115 +++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 include/armnnTestUtils/MemCopyTestImpl.hpp (limited to 'include/armnnTestUtils/MemCopyTestImpl.hpp') diff --git a/include/armnnTestUtils/MemCopyTestImpl.hpp b/include/armnnTestUtils/MemCopyTestImpl.hpp new file mode 100644 index 0000000000..1856dcb056 --- /dev/null +++ b/include/armnnTestUtils/MemCopyTestImpl.hpp @@ -0,0 +1,115 @@ +// +// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include "LayerTestResult.hpp" +#include "TensorCopyUtils.hpp" +#include "TensorHelpers.hpp" +#include "WorkloadTestUtils.hpp" +#include +#include +#include + +namespace +{ + +template> +LayerTestResult MemCopyTest(armnn::IWorkloadFactory& srcWorkloadFactory, + armnn::IWorkloadFactory& dstWorkloadFactory, + bool withSubtensors) +{ + const std::array shapeData = { { 1u, 1u, 6u, 5u } }; + const armnn::TensorShape tensorShape(4, shapeData.data()); + const armnn::TensorInfo tensorInfo(tensorShape, dataType); + std::vector inputData = + { + 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, + }; + + LayerTestResult ret(tensorInfo); + ret.m_ExpectedData = inputData; + + std::vector actualOutput(tensorInfo.GetNumElements()); + + ARMNN_NO_DEPRECATE_WARN_BEGIN + auto inputTensorHandle = srcWorkloadFactory.CreateTensorHandle(tensorInfo); + auto outputTensorHandle = dstWorkloadFactory.CreateTensorHandle(tensorInfo); + ARMNN_NO_DEPRECATE_WARN_END + + AllocateAndCopyDataToITensorHandle(inputTensorHandle.get(), inputData.data()); + outputTensorHandle->Allocate(); + + armnn::MemCopyQueueDescriptor memCopyQueueDesc; + armnn::WorkloadInfo workloadInfo; + + const unsigned int origin[4] = {}; + + ARMNN_NO_DEPRECATE_WARN_BEGIN + auto workloadInput = (withSubtensors && srcWorkloadFactory.SupportsSubTensors()) + ? srcWorkloadFactory.CreateSubTensorHandle(*inputTensorHandle, tensorShape, origin) + : std::move(inputTensorHandle); + auto workloadOutput = (withSubtensors && dstWorkloadFactory.SupportsSubTensors()) + ? dstWorkloadFactory.CreateSubTensorHandle(*outputTensorHandle, tensorShape, origin) + : std::move(outputTensorHandle); + ARMNN_NO_DEPRECATE_WARN_END + + AddInputToWorkload(memCopyQueueDesc, workloadInfo, tensorInfo, workloadInput.get()); + AddOutputToWorkload(memCopyQueueDesc, workloadInfo, tensorInfo, workloadOutput.get()); + + dstWorkloadFactory.CreateWorkload(armnn::LayerType::MemCopy, memCopyQueueDesc, workloadInfo)->Execute(); + + CopyDataFromITensorHandle(actualOutput.data(), workloadOutput.get()); + ret.m_ActualData = actualOutput; + + return ret; +} + +template +struct MemCopyTestHelper +{}; +template <> +struct MemCopyTestHelper +{ + static armnn::IBackendInternal::IMemoryManagerSharedPtr GetMemoryManager() + { + armnn::MockBackend backend; + return backend.CreateMemoryManager(); + } + + static armnn::MockWorkloadFactory + GetFactory(const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager = nullptr) + { + IgnoreUnused(memoryManager); + return armnn::MockWorkloadFactory(); + } +}; + +using MockMemCopyTestHelper = MemCopyTestHelper; + +template > +LayerTestResult MemCopyTest(bool withSubtensors) +{ + + armnn::IBackendInternal::IMemoryManagerSharedPtr srcMemoryManager = + MemCopyTestHelper::GetMemoryManager(); + + armnn::IBackendInternal::IMemoryManagerSharedPtr dstMemoryManager = + MemCopyTestHelper::GetMemoryManager(); + + SrcWorkloadFactory srcWorkloadFactory = MemCopyTestHelper::GetFactory(srcMemoryManager); + DstWorkloadFactory dstWorkloadFactory = MemCopyTestHelper::GetFactory(dstMemoryManager); + + return MemCopyTest(srcWorkloadFactory, dstWorkloadFactory, withSubtensors); +} + +} // anonymous namespace -- cgit v1.2.1