telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include "QuantizeHelper.hpp" |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 8 | #include "WorkloadTestUtils.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include <armnn/ArmNN.hpp> |
| 11 | #include <armnn/Tensor.hpp> |
| 12 | #include <armnn/TypesUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 14 | #include <test/TensorHelpers.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 16 | #include <backendsCommon/CpuTensorHandle.hpp> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 17 | #include <backendsCommon/IBackendInternal.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 18 | #include <backendsCommon/WorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | |
| 20 | template<typename T> |
| 21 | LayerTestResult<T, 4> SimplePermuteTestImpl( |
| 22 | armnn::IWorkloadFactory& workloadFactory, |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 23 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | armnn::PermuteDescriptor descriptor, |
| 25 | armnn::TensorInfo inputTensorInfo, |
| 26 | armnn::TensorInfo outputTensorInfo, |
| 27 | const std::vector<T>& inputData, |
| 28 | const std::vector<T>& outputExpectedData) |
| 29 | { |
| 30 | auto input = MakeTensor<T, 4>(inputTensorInfo, inputData); |
| 31 | |
| 32 | LayerTestResult<T, 4> ret(outputTensorInfo); |
| 33 | ret.outputExpected = MakeTensor<T, 4>(outputTensorInfo, outputExpectedData); |
| 34 | |
| 35 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 36 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 37 | |
| 38 | armnn::PermuteQueueDescriptor data; |
| 39 | data.m_Parameters = descriptor; |
| 40 | armnn::WorkloadInfo info; |
| 41 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 42 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 43 | |
| 44 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePermute(data, info); |
| 45 | |
| 46 | inputHandle->Allocate(); |
| 47 | outputHandle->Allocate(); |
| 48 | |
| 49 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0][0]); |
| 50 | |
| 51 | workload->Execute(); |
| 52 | |
| 53 | CopyDataFromITensorHandle(&ret.output[0][0][0][0], outputHandle.get()); |
| 54 | |
| 55 | return ret; |
| 56 | } |
| 57 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 58 | LayerTestResult<float, 4> SimplePermuteFloat32TestCommon( |
| 59 | armnn::IWorkloadFactory& workloadFactory, |
| 60 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 61 | { |
| 62 | armnn::TensorInfo inputTensorInfo; |
| 63 | armnn::TensorInfo outputTensorInfo; |
| 64 | |
| 65 | unsigned int inputShape[] = { 1, 2, 2, 2 }; |
| 66 | unsigned int outputShape[] = { 1, 2, 2, 2 }; |
| 67 | |
| 68 | armnn::PermuteDescriptor descriptor; |
| 69 | descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; |
| 70 | |
| 71 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 72 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 73 | |
| 74 | std::vector<float> input = std::vector<float>( |
| 75 | { |
| 76 | 1.0f, 2.0f, |
| 77 | 3.0f, 4.0f, |
| 78 | |
| 79 | 5.0f, 6.0f, |
| 80 | 7.0f, 8.0f |
| 81 | }); |
| 82 | |
| 83 | std::vector<float> outputExpected = std::vector<float>( |
| 84 | { |
| 85 | 1.0f, 5.0f, 2.0f, 6.0f, |
| 86 | 3.0f, 7.0f, 4.0f, 8.0f |
| 87 | }); |
| 88 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 89 | return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, |
| 90 | descriptor, inputTensorInfo, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | outputTensorInfo, input, outputExpected); |
| 92 | } |
| 93 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 94 | LayerTestResult<uint8_t, 4> SimplePermuteUint8TestCommon( |
| 95 | armnn::IWorkloadFactory& workloadFactory, |
| 96 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 97 | { |
| 98 | armnn::TensorInfo inputTensorInfo; |
| 99 | armnn::TensorInfo outputTensorInfo; |
| 100 | |
| 101 | unsigned int inputShape[] = { 1, 2, 2, 2 }; |
| 102 | unsigned int outputShape[] = { 1, 2, 2, 2 }; |
| 103 | |
| 104 | armnn::PermuteDescriptor descriptor; |
| 105 | descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; |
| 106 | |
| 107 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::QuantisedAsymm8); |
| 108 | inputTensorInfo.SetQuantizationScale(1.0f); |
| 109 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::QuantisedAsymm8); |
| 110 | outputTensorInfo.SetQuantizationScale(1.0f); |
| 111 | |
| 112 | std::vector<uint8_t> input = std::vector<uint8_t>( |
| 113 | { |
| 114 | 1, 2, |
| 115 | 3, 4, |
| 116 | |
| 117 | 5, 6, |
| 118 | 7, 8 |
| 119 | }); |
| 120 | |
| 121 | std::vector<uint8_t> outputExpected = std::vector<uint8_t>( |
| 122 | { |
| 123 | 1, 5, 2, 6, |
| 124 | 3, 7, 4, 8 |
| 125 | }); |
| 126 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 127 | return SimplePermuteTestImpl<uint8_t>(workloadFactory, memoryManager, |
| 128 | descriptor, inputTensorInfo, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 129 | outputTensorInfo, input, outputExpected); |
| 130 | } |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 131 | |
| 132 | LayerTestResult<float, 4> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 133 | PermuteFloat32ValueSet1TestCommon( |
| 134 | armnn::IWorkloadFactory& workloadFactory, |
| 135 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 136 | { |
| 137 | armnn::TensorInfo inputTensorInfo; |
| 138 | armnn::TensorInfo outputTensorInfo; |
| 139 | |
| 140 | unsigned int inputShape[] = { 1, 2, 2, 3 }; |
| 141 | unsigned int outputShape[] = { 1, 3, 2, 2 }; |
| 142 | |
| 143 | armnn::PermuteDescriptor descriptor; |
| 144 | descriptor.m_DimMappings = {0U, 2U, 3U, 1U}; |
| 145 | |
| 146 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 147 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 148 | |
| 149 | std::vector<float> input = std::vector<float>( |
| 150 | { |
| 151 | 1.0f, 2.0f, 3.0f, |
| 152 | 11.0f, 12.0f, 13.0f, |
| 153 | 21.0f, 22.0f, 23.0f, |
| 154 | 31.0f, 32.0f, 33.0f, |
| 155 | }); |
| 156 | |
| 157 | std::vector<float> outputExpected = std::vector<float>( |
| 158 | { |
| 159 | 1.0f, 11.0f, 21.0f, 31.0f, |
| 160 | 2.0f, 12.0f, 22.0f, 32.0f, |
| 161 | 3.0f, 13.0f, 23.0f, 33.0f, |
| 162 | }); |
| 163 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 164 | return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, |
| 165 | descriptor, inputTensorInfo, |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 166 | outputTensorInfo, input, outputExpected); |
| 167 | } |
| 168 | |
| 169 | LayerTestResult<float, 4> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 170 | PermuteFloat32ValueSet2TestCommon( |
| 171 | armnn::IWorkloadFactory& workloadFactory, |
| 172 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 173 | { |
| 174 | armnn::TensorInfo inputTensorInfo; |
| 175 | armnn::TensorInfo outputTensorInfo; |
| 176 | |
| 177 | unsigned int inputShape[] = { 1, 3, 2, 2 }; |
| 178 | unsigned int outputShape[] = { 1, 2, 2, 3 }; |
| 179 | |
| 180 | armnn::PermuteDescriptor descriptor; |
| 181 | descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; |
| 182 | |
| 183 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 184 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 185 | |
| 186 | std::vector<float> input = std::vector<float>( |
| 187 | { |
| 188 | 1.0f, 11.0f, 21.0f, 31.0f, |
| 189 | 2.0f, 12.0f, 22.0f, 32.0f, |
| 190 | 3.0f, 13.0f, 23.0f, 33.0f, |
| 191 | }); |
| 192 | |
| 193 | std::vector<float> outputExpected = std::vector<float>( |
| 194 | { |
| 195 | 1.0f, 2.0f, 3.0f, |
| 196 | 11.0f, 12.0f, 13.0f, |
| 197 | 21.0f, 22.0f, 23.0f, |
| 198 | 31.0f, 32.0f, 33.0f, |
| 199 | }); |
| 200 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 201 | return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, |
| 202 | descriptor, inputTensorInfo, |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 203 | outputTensorInfo, input, outputExpected); |
| 204 | } |
| 205 | |
| 206 | LayerTestResult<float, 4> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 207 | PermuteFloat32ValueSet3TestCommon( |
| 208 | armnn::IWorkloadFactory& workloadFactory, |
| 209 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 210 | { |
| 211 | armnn::TensorInfo inputTensorInfo; |
| 212 | armnn::TensorInfo outputTensorInfo; |
| 213 | |
| 214 | unsigned int inputShape[] = { 1, 2, 3, 3 }; |
| 215 | unsigned int outputShape[] = { 1, 3, 2, 3 }; |
| 216 | |
| 217 | armnn::PermuteDescriptor descriptor; |
| 218 | descriptor.m_DimMappings = {0U, 2U, 3U, 1U}; |
| 219 | |
| 220 | inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32); |
| 221 | outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32); |
| 222 | |
| 223 | std::vector<float> input = std::vector<float>( |
| 224 | { |
| 225 | 1.0f, 2.0f, 3.0f, |
| 226 | 11.0f, 12.0f, 13.0f, |
| 227 | 21.0f, 22.0f, 23.0f, |
| 228 | 31.0f, 32.0f, 33.0f, |
| 229 | 41.0f, 42.0f, 43.0f, |
| 230 | 51.0f, 52.0f, 53.0f, |
| 231 | }); |
| 232 | |
| 233 | std::vector<float> outputExpected = std::vector<float>( |
| 234 | { |
| 235 | 1.0f, 11.0f, 21.0f, 31.0f, 41.0f, 51.0f, |
| 236 | 2.0f, 12.0f, 22.0f, 32.0f, 42.0f, 52.0f, |
| 237 | 3.0f, 13.0f, 23.0f, 33.0f, 43.0f, 53.0f, |
| 238 | }); |
| 239 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 240 | return SimplePermuteTestImpl<float>(workloadFactory, memoryManager, |
| 241 | descriptor, inputTensorInfo, |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 242 | outputTensorInfo, input, outputExpected); |
| 243 | } |