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