// // Copyright © 2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "BroadcastToTestImpl.hpp" #include #include #include #include #include #include #include #include #include #include namespace { template LayerTestResult BroadcastToTestImpl( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory, armnn::BroadcastToDescriptor descriptor, armnn::TensorInfo& inputInfo, armnn::TensorInfo& outputInfo, std::vector& inputData, std::vector& expectedOutputData) { CHECK(descriptor.m_BroadcastToShape == outputInfo.GetShape()); LayerTestResult result(outputInfo); std::vector outputActual(outputInfo.GetNumElements()); armnn::BroadcastToQueueDescriptor queueDescriptor; queueDescriptor.m_Parameters = std::move(descriptor); armnn::WorkloadInfo workloadInfo; std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputInfo); std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputInfo); AddInputToWorkload(queueDescriptor, workloadInfo, inputInfo, inputHandle.get()); AddOutputToWorkload(queueDescriptor, workloadInfo, outputInfo, outputHandle.get()); const armnn::BackendId& backend = workloadFactory.GetBackendId(); armnn::LayerSupportHandle handle = armnn::GetILayerSupportByBackendId(backend); auto workload = workloadFactory.CreateWorkload(armnn::LayerType::BroadcastTo, queueDescriptor, workloadInfo); inputHandle->Allocate(); outputHandle->Allocate(); CopyDataToITensorHandle(inputHandle.get(), inputData.data()); workload->PostAllocationConfigure(); ExecuteWorkload(*workload, memoryManager); CopyDataFromITensorHandle(outputActual.data(), outputHandle.get()); return LayerTestResult(outputActual, expectedOutputData, outputHandle->GetShape(), outputInfo.GetShape()); } } template LayerTestResult BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape( {1, 4} )); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 1, 1 }; armnn::TensorShape outputShape = { 1, 4 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 1.f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 1.f, 1.f, 1.f, 1.f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult BroadcastTo2dAxis0Test(armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape({ 4, 3 })); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 1, 3 }; armnn::TensorShape outputShape = { 4, 3 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 0.f, 1.f, 2.f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 0.f, 1.f, 2.f, 0.f, 1.f, 2.f, 0.f, 1.f, 2.f, 0.f, 1.f, 2.f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult BroadcastTo2dAxis1Test(armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape({ 3, 4 })); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 3, 1 }; armnn::TensorShape outputShape = { 3, 4 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 0.f, 1.f, 2.f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult BroadcastTo3dAxis0Test(armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape({ 2, 1, 3 })); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 1, 1, 3 }; armnn::TensorShape outputShape = { 2, 1, 3 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 1.1f, 2.12f, 3.3f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 1.1f, 2.12f, 3.3f, 1.1f, 2.12f, 3.3f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult BroadcastTo3dAxis1Test(armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape({ 1, 3, 3 })); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 1, 1, 3 }; armnn::TensorShape outputShape = { 1, 3, 3 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 1.1f, 2.12f, 3.3f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 1.1f, 2.12f, 3.3f, 1.1f, 2.12f, 3.3f, 1.1f, 2.12f, 3.3f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult BroadcastTo3dAxis2Test(armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape({ 1, 3, 3 })); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 1, 3, 1 }; armnn::TensorShape outputShape = { 1, 3, 3 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 1.1f, 2.12f, 3.3f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 1.1f, 1.1f, 1.1f, 2.12f, 2.12f, 2.12f, 3.3f, 3.3f, 3.3f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult BroadcastTo4dTest(armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { auto descriptor = armnn::BroadcastToDescriptor(armnn::TensorShape({ 3, 1, 2, 3 })); float qScale = 1.0f; int32_t qOffset = 0; armnn::TensorShape inputShape = { 1, 1, 1, 3 }; armnn::TensorShape outputShape = { 3, 1, 2, 3 }; armnn::TensorInfo inputInfo(inputShape, ArmnnType); armnn::TensorInfo outputInfo(outputShape, ArmnnType); std::vector input = armnnUtils::QuantizedVector( { 0.f, 1.f, 2.f }, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector( { 0.f, 1.f, 2.f, 0.f, 1.f, 2.f, 0.f, 1.f, 2.f, 0.f, 1.f, 2.f, 0.f, 1.f, 2.f, 0.f, 1.f, 2.f }, qScale, qOffset); return BroadcastToTestImpl(workloadFactory, memoryManager, tensorHandleFactory, descriptor, inputInfo, outputInfo, input, expectedOutput); } template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 1> BroadcastTo1dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 2> BroadcastTo2dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 3> BroadcastTo3dAxis2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); template LayerTestResult, 4> BroadcastTo4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory);