// // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include "StridedSliceTestImpl.hpp" #include #include #include #include #include namespace { template LayerTestResult StridedSliceTestImpl( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory, armnn::TensorInfo& inputTensorInfo, armnn::TensorInfo& outputTensorInfo, std::vector& inputData, std::vector& outputExpectedData, armnn::StridedSliceQueueDescriptor descriptor, const float qScale = 1.0f, const int32_t qOffset = 0) { IgnoreUnused(memoryManager); if(armnn::IsQuantizedType()) { inputTensorInfo.SetQuantizationScale(qScale); inputTensorInfo.SetQuantizationOffset(qOffset); outputTensorInfo.SetQuantizationScale(qScale); outputTensorInfo.SetQuantizationOffset(qOffset); } std::vector input = armnnUtils::QuantizedVector(inputData, qScale, qOffset); std::vector expectedOutput = armnnUtils::QuantizedVector(outputExpectedData, qScale, qOffset); std::vector actualOutput(outputTensorInfo.GetNumElements()); std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); armnn::WorkloadInfo info; AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); std::unique_ptr workload = workloadFactory.CreateWorkload(armnn::LayerType::StridedSlice, descriptor, info); inputHandle->Allocate(); outputHandle->Allocate(); CopyDataToITensorHandle(inputHandle.get(), input.data()); ExecuteWorkload(*workload, memoryManager); CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); return LayerTestResult(actualOutput, expectedOutput, outputHandle->GetShape(), outputTensorInfo.GetShape()); } template> LayerTestResult StridedSlice4dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {1, 2, 3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {1, 0, 0, 0}; desc.m_Parameters.m_End = {2, 2, 3, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f }); std::vector outputExpected = std::vector( { 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSlice4dReverseTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {1, 2, 3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {1, -1, 0, 0}; desc.m_Parameters.m_End = {2, -3, 3, 1}; desc.m_Parameters.m_Stride = {1, -1, 1, 1}; inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f }); std::vector outputExpected = std::vector( { 4.0f, 4.0f, 4.0f, 3.0f, 3.0f, 3.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceSimpleStrideTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {2, 1, 2, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {3, 2, 3, 1}; desc.m_Parameters.m_Stride = {2, 2, 2, 1}; inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f }); std::vector outputExpected = std::vector( { 1.0f, 1.0f, 5.0f, 5.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceSimpleRangeMaskTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3, 2, 3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {1, 1, 1, 1}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_BeginMask = (1 << 4) - 1; desc.m_Parameters.m_EndMask = (1 << 4) - 1; inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f }); std::vector outputExpected = std::vector( { 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 1, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 1) | (1 << 2); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 2.0f, 8.0f, 14.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition0Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {2, 3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 0); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3, 3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 1); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f, 7.0f, 8.0f, 9.0f, 13.0f, 14.0f, 15.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3, 2, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 2); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 4.0f, 7.0f, 10.0f, 13.0f, 16.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition3Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3, 2, 3}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 3); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And1Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 0) | (1 << 1); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition0Dim3Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {2, 3, 1}; unsigned int outputShape[] = {3, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0}; desc.m_Parameters.m_End = {0, 0, 0}; desc.m_Parameters.m_Stride = {1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 0); inputTensorInfo = armnn::TensorInfo(3, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } void FillVector(std::vector& inputArray, float start, float step) { for (uint32_t i = 0; i < inputArray.size(); ++i) { inputArray[i] = start; start += step; } } template> LayerTestResult StridedSliceShrinkAxisMaskCTSTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {1, 1, 8, 942}; unsigned int outputShape[] = {1, 1, 1, 279}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 1, 229}; desc.m_Parameters.m_End = {1, 1, 2, 787}; desc.m_Parameters.m_Stride = {2, 3, 3, 2}; desc.m_Parameters.m_BeginMask = 2; desc.m_Parameters.m_EndMask = 0; desc.m_Parameters.m_ShrinkAxisMask = 0; inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); // Array from 1 to 7535 std::vector input(7536); FillVector(input, 1.0f, 1.0f); // Array from 1171 to 1727 in steps of 2 std::vector outputExpected(279); FillVector(outputExpected, 1171.0, 2.0f); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And2Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {2, 1}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 0) | (1 << 2); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 4.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And3Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {2, 3}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 0) | (1 << 3); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And1And3Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 2, 3, 1}; unsigned int outputShape[] = {3}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1, 1}; desc.m_Parameters.m_Stride = {1, 1, 1, 1}; desc.m_Parameters.m_EndMask = (1 << 4) - 1; desc.m_Parameters.m_ShrinkAxisMask = (1 << 0) | (1 << 1) | (1 << 3); inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(1, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f }); std::vector outputExpected = std::vector( { 1.0f, 2.0f, 3.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSlice3dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 3, 3}; unsigned int outputShape[] = {2, 2, 2}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0, 0}; desc.m_Parameters.m_End = {1, 1, 1}; desc.m_Parameters.m_Stride = {2, 2, 2}; desc.m_Parameters.m_EndMask = (1 << 3) - 1; inputTensorInfo = armnn::TensorInfo(3, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f }); std::vector outputExpected = std::vector( { 1.0f, 3.0f, 7.0f, 9.0f, 19.0f, 21.0f, 25.0f, 27.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSlice3dReverseTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 3, 3}; unsigned int outputShape[] = {2, 2, 2}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {-1, -1, -1}; desc.m_Parameters.m_End = {-4, -4, -4}; desc.m_Parameters.m_Stride = {-2, -2, -2}; inputTensorInfo = armnn::TensorInfo(3, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f }); std::vector outputExpected = std::vector( { 27.0f, 25.0f, 21.0f, 19.0f, 9.0f, 7.0f, 3.0f, 1.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSlice2dTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 3}; unsigned int outputShape[] = {2, 2}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0}; desc.m_Parameters.m_End = {1, 1}; desc.m_Parameters.m_Stride = {2, 2}; desc.m_Parameters.m_EndMask = (1 << 2) - 1; inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }); std::vector outputExpected = std::vector( { 1.0f, 3.0f, 7.0f, 9.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } template> LayerTestResult StridedSlice2dReverseTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { armnn::TensorInfo inputTensorInfo; armnn::TensorInfo outputTensorInfo; unsigned int inputShape[] = {3, 3}; unsigned int outputShape[] = {2, 2}; armnn::StridedSliceQueueDescriptor desc; desc.m_Parameters.m_Begin = {0, 0}; desc.m_Parameters.m_End = {1, 1}; desc.m_Parameters.m_Stride = {-2, -2}; desc.m_Parameters.m_BeginMask = (1 << 2) - 1; desc.m_Parameters.m_EndMask = (1 << 2) - 1; inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); std::vector input = std::vector( { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }); std::vector outputExpected = std::vector( { 9.0f, 7.0f, 3.0f, 1.0f }); return StridedSliceTestImpl( workloadFactory, memoryManager, tensorHandleFactory, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); } } // anonymous namespace LayerTestResult StridedSlice4dFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice4dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice4dReverseFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice4dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceSimpleStrideFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceSimpleStrideTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceSimpleRangeMaskFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceSimpleRangeMaskTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskCTSFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskCTSTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0Dim3Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0Dim3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition1Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition1Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition2Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition2Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition3Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And1Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And1Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And2Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And2Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And3Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And1And3Float32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And1And3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice3dFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice3dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice3dReverseFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice3dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice2dFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice2dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice2dReverseFloat32Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice2dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice4dUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice4dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice4dReverseUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice4dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceSimpleStrideUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceSimpleStrideTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceSimpleRangeMaskUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceSimpleRangeMaskTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0Dim3Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0Dim3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition1Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition1Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition2Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition2Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition3Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And1Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And1Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And2Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And2Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And3Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskBitPosition0And1And3Uint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskBitPosition0And1And3Test(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice3dUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice3dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice3dReverseUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice3dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice2dUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice2dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice2dReverseUint8Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice2dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice4dInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice4dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice4dReverseInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice4dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceSimpleStrideInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceSimpleStrideTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceSimpleRangeMaskInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceSimpleRangeMaskTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSliceShrinkAxisMaskInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSliceShrinkAxisMaskTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice3dInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice3dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice3dReverseInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice3dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice2dInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice2dTest(workloadFactory, memoryManager, tensorHandleFactory); } LayerTestResult StridedSlice2dReverseInt16Test( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory) { return StridedSlice2dReverseTest(workloadFactory, memoryManager, tensorHandleFactory); }