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 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 58 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 59 | LayerTestResult<T, 4> SimplePermuteTest( |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 60 | armnn::IWorkloadFactory& workloadFactory, |
| 61 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 62 | { |
| 63 | armnn::TensorInfo inputTensorInfo; |
| 64 | armnn::TensorInfo outputTensorInfo; |
| 65 | |
| 66 | unsigned int inputShape[] = { 1, 2, 2, 2 }; |
| 67 | unsigned int outputShape[] = { 1, 2, 2, 2 }; |
| 68 | |
| 69 | armnn::PermuteDescriptor descriptor; |
| 70 | descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; |
| 71 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 72 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 73 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 75 | // Set quantization parameters if the requested type is a quantized type. |
| 76 | if(armnn::IsQuantizedType<T>()) |
| 77 | { |
| 78 | inputTensorInfo.SetQuantizationScale(0.5f); |
| 79 | inputTensorInfo.SetQuantizationOffset(5); |
| 80 | outputTensorInfo.SetQuantizationScale(0.5f); |
| 81 | outputTensorInfo.SetQuantizationOffset(5); |
| 82 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 84 | std::vector<T> input = std::vector<T>( |
| 85 | { |
| 86 | 1, 2, |
| 87 | 3, 4, |
| 88 | 5, 6, |
| 89 | 7, 8 |
| 90 | }); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 92 | std::vector<T> outputExpected = std::vector<T>( |
| 93 | { |
| 94 | 1, 5, 2, 6, |
| 95 | 3, 7, 4, 8 |
| 96 | }); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 97 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 98 | return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, |
| 99 | descriptor, inputTensorInfo, |
| 100 | outputTensorInfo, input, outputExpected); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 103 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 104 | LayerTestResult<T, 4> PermuteValueSet1Test( |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 105 | armnn::IWorkloadFactory& workloadFactory, |
| 106 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 107 | { |
| 108 | armnn::TensorInfo inputTensorInfo; |
| 109 | armnn::TensorInfo outputTensorInfo; |
| 110 | |
| 111 | unsigned int inputShape[] = { 1, 2, 2, 3 }; |
| 112 | unsigned int outputShape[] = { 1, 3, 2, 2 }; |
| 113 | |
| 114 | armnn::PermuteDescriptor descriptor; |
| 115 | descriptor.m_DimMappings = {0U, 2U, 3U, 1U}; |
| 116 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 117 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 118 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 119 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 120 | // Set quantization parameters if the requested type is a quantized type. |
| 121 | if(armnn::IsQuantizedType<T>()) |
| 122 | { |
| 123 | inputTensorInfo.SetQuantizationScale(0.5f); |
| 124 | inputTensorInfo.SetQuantizationOffset(5); |
| 125 | outputTensorInfo.SetQuantizationScale(0.5f); |
| 126 | outputTensorInfo.SetQuantizationOffset(5); |
| 127 | } |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 128 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 129 | std::vector<T> input = std::vector<T>( |
| 130 | { |
| 131 | 1, 2, 3, |
| 132 | 11, 12, 13, |
| 133 | 21, 22, 23, |
| 134 | 31, 32, 33 |
| 135 | }); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 136 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 137 | std::vector<T> outputExpected = std::vector<T>( |
| 138 | { |
| 139 | 1, 11, 21, 31, |
| 140 | 2, 12, 22, 32, |
| 141 | 3, 13, 23, 33 |
| 142 | }); |
| 143 | |
| 144 | return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, |
| 145 | descriptor, inputTensorInfo, |
| 146 | outputTensorInfo, input, outputExpected); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 149 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 150 | LayerTestResult<T, 4> PermuteValueSet2Test( |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 151 | armnn::IWorkloadFactory& workloadFactory, |
| 152 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 153 | { |
| 154 | armnn::TensorInfo inputTensorInfo; |
| 155 | armnn::TensorInfo outputTensorInfo; |
| 156 | |
| 157 | unsigned int inputShape[] = { 1, 3, 2, 2 }; |
| 158 | unsigned int outputShape[] = { 1, 2, 2, 3 }; |
| 159 | |
| 160 | armnn::PermuteDescriptor descriptor; |
| 161 | descriptor.m_DimMappings = {0U, 3U, 1U, 2U}; |
| 162 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 163 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 164 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 165 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 166 | // Set quantization parameters if the requested type is a quantized type. |
| 167 | if(armnn::IsQuantizedType<T>()) |
| 168 | { |
| 169 | inputTensorInfo.SetQuantizationScale(0.5f); |
| 170 | inputTensorInfo.SetQuantizationOffset(5); |
| 171 | outputTensorInfo.SetQuantizationScale(0.5f); |
| 172 | outputTensorInfo.SetQuantizationOffset(5); |
| 173 | } |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 174 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 175 | std::vector<T> input = std::vector<T>( |
| 176 | { |
| 177 | 1, 11, 21, 31, |
| 178 | 2, 12, 22, 32, |
| 179 | 3, 13, 23, 33 |
| 180 | }); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 181 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 182 | std::vector<T> outputExpected = std::vector<T>( |
| 183 | { |
| 184 | 1, 2, 3, |
| 185 | 11, 12, 13, |
| 186 | 21, 22, 23, |
| 187 | 31, 32, 33, |
| 188 | }); |
| 189 | |
| 190 | return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, |
| 191 | descriptor, inputTensorInfo, |
| 192 | outputTensorInfo, input, outputExpected); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 193 | } |
| 194 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 195 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 196 | LayerTestResult<T, 4> PermuteValueSet3Test( |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 197 | armnn::IWorkloadFactory& workloadFactory, |
| 198 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 199 | { |
| 200 | armnn::TensorInfo inputTensorInfo; |
| 201 | armnn::TensorInfo outputTensorInfo; |
| 202 | |
| 203 | unsigned int inputShape[] = { 1, 2, 3, 3 }; |
| 204 | unsigned int outputShape[] = { 1, 3, 2, 3 }; |
| 205 | |
| 206 | armnn::PermuteDescriptor descriptor; |
| 207 | descriptor.m_DimMappings = {0U, 2U, 3U, 1U}; |
| 208 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 209 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 210 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 211 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 212 | // Set quantization parameters if the requested type is a quantized type. |
| 213 | if(armnn::IsQuantizedType<T>()) |
| 214 | { |
| 215 | inputTensorInfo.SetQuantizationScale(0.5f); |
| 216 | inputTensorInfo.SetQuantizationOffset(5); |
| 217 | outputTensorInfo.SetQuantizationScale(0.5f); |
| 218 | outputTensorInfo.SetQuantizationOffset(5); |
| 219 | } |
| 220 | |
| 221 | std::vector<T> input = std::vector<T>( |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 222 | { |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 223 | 1, 2, 3, |
| 224 | 11, 12, 13, |
| 225 | 21, 22, 23, |
| 226 | 31, 32, 33, |
| 227 | 41, 42, 43, |
| 228 | 51, 52, 53 |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 229 | }); |
| 230 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 231 | std::vector<T> outputExpected = std::vector<T>( |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 232 | { |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 233 | 1, 11, 21, 31, 41, 51, |
| 234 | 2, 12, 22, 32, 42, 52, |
| 235 | 3, 13, 23, 33, 43, 53 |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 236 | }); |
| 237 | |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 238 | return SimplePermuteTestImpl<T>(workloadFactory, memoryManager, |
| 239 | descriptor, inputTensorInfo, |
| 240 | outputTensorInfo, input, outputExpected); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 241 | } |