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