2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "ReshapeTestImpl.hpp"
8 #include <backendsCommon/test/DataTypeUtils.hpp>
9 #include <backendsCommon/test/TensorCopyUtils.hpp>
10 #include <backendsCommon/test/WorkloadTestUtils.hpp>
12 #include <test/TensorHelpers.hpp>
17 template<typename T, size_t NumDims>
18 LayerTestResult<T, NumDims> SimpleReshapeTestImpl(
19 armnn::IWorkloadFactory& workloadFactory,
20 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager,
21 armnn::TensorInfo inputTensorInfo,
22 armnn::TensorInfo outputTensorInfo,
23 const std::vector<T>& inputData,
24 const std::vector<T>& outputExpectedData)
26 boost::ignore_unused(memoryManager);
27 auto input = MakeTensor<T, NumDims>(inputTensorInfo, inputData);
29 LayerTestResult<T, NumDims> ret(outputTensorInfo);
30 ret.outputExpected = MakeTensor<T, NumDims>(outputTensorInfo, outputExpectedData);
32 std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo);
33 std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo);
35 armnn::ReshapeQueueDescriptor data;
36 armnn::WorkloadInfo info;
37 AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
38 AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
40 std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateReshape(data, info);
42 inputHandle->Allocate();
43 outputHandle->Allocate();
45 CopyDataToITensorHandle(inputHandle.get(), input.origin());
49 CopyDataFromITensorHandle(ret.output.origin(), outputHandle.get());
54 } // anonymous namespace
56 template<armnn::DataType ArmnnType, typename T>
57 LayerTestResult<T, 4> SimpleReshapeTest(
58 armnn::IWorkloadFactory& workloadFactory,
59 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
61 armnn::TensorInfo inputTensorInfo;
62 armnn::TensorInfo outputTensorInfo;
64 unsigned int inputShape[] = { 2, 2, 3, 3 };
65 unsigned int outputShape[] = { 2, 2, 9, 1 };
67 inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType);
68 inputTensorInfo.SetQuantizationScale(1.0f);
69 outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType);
70 outputTensorInfo.SetQuantizationScale(1.0f);
72 auto input = ConvertToDataType<ArmnnType>(
92 auto outputExpected = ConvertToDataType<ArmnnType>(
94 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
96 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f,
98 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f,
100 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f,
104 return SimpleReshapeTestImpl<T, 4>(
105 workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected);
108 template<armnn::DataType ArmnnType, typename T>
109 LayerTestResult<T, 5> Reshape5dTest(
110 armnn::IWorkloadFactory& workloadFactory,
111 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
113 armnn::TensorInfo inputTensorInfo;
114 armnn::TensorInfo outputTensorInfo;
116 unsigned int inputShape[] = { 2, 2, 8, 1, 1 };
117 unsigned int outputShape[] = { 2, 2, 2, 2, 2 };
119 inputTensorInfo = armnn::TensorInfo(5, inputShape, ArmnnType);
120 inputTensorInfo.SetQuantizationScale(1.0f);
121 outputTensorInfo = armnn::TensorInfo(5, outputShape, ArmnnType);
122 outputTensorInfo.SetQuantizationScale(1.0f);
124 auto input = ConvertToDataType<ArmnnType>(
126 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f,
127 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f,
129 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f,
130 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f,
134 auto outputExpected = ConvertToDataType<ArmnnType>(
166 return SimpleReshapeTestImpl<T, 5>(
167 workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected);
171 // Explicit template specializations
174 template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4>
175 SimpleReshapeTest<armnn::DataType::Float32>(
176 armnn::IWorkloadFactory& workloadFactory,
177 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager);
179 template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmU8>, 4>
180 SimpleReshapeTest<armnn::DataType::QAsymmU8>(
181 armnn::IWorkloadFactory& workloadFactory,
182 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager);
184 template LayerTestResult<armnn::ResolveType<armnn::DataType::QSymmS16>, 4>
185 SimpleReshapeTest<armnn::DataType::QSymmS16>(
186 armnn::IWorkloadFactory& workloadFactory,
187 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager);
189 template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 5>
190 Reshape5dTest<armnn::DataType::Float32>(
191 armnn::IWorkloadFactory& workloadFactory,
192 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager);
194 template LayerTestResult<armnn::ResolveType<armnn::DataType::QAsymmU8>, 5>
195 Reshape5dTest<armnn::DataType::QAsymmU8>(
196 armnn::IWorkloadFactory& workloadFactory,
197 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager);
199 template LayerTestResult<armnn::ResolveType<armnn::DataType::QSymmS16>, 5>
200 Reshape5dTest<armnn::DataType::QSymmS16>(
201 armnn::IWorkloadFactory& workloadFactory,
202 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager);