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 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 5 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 6 | #include "SplitterTestImpl.hpp" |
| 7 | |
| 8 | #include <ResolveType.hpp> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 9 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include <armnn/ArmNN.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 12 | #include <backendsCommon/test/QuantizeHelper.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 13 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 14 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 15 | |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 16 | #include <test/TensorHelpers.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 18 | namespace |
| 19 | { |
| 20 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 21 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 22 | std::vector<LayerTestResult<T,3>> SplitterTestCommon( |
| 23 | armnn::IWorkloadFactory& workloadFactory, |
| 24 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 25 | float qScale = 0.0f, |
| 26 | int32_t qOffset = 0) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 27 | { |
| 28 | unsigned int inputWidth = 5; |
| 29 | unsigned int inputHeight = 6; |
| 30 | unsigned int inputChannels = 3; |
| 31 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 32 | // NOTE: Compute Library imposes a restriction that the x and y dimension (input height and width) |
| 33 | // cannot be split. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 34 | // For the reasons for this, see first comment on https://jira.arm.com/browse/IVGCVSW-1239 |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 35 | // |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 36 | // This test has therefore been recast to split the channels, then split the resulting subtensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 38 | // To take channel 0 of original output |
| 39 | // and channel 0 and channel 1 of the split subtensor. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 40 | unsigned int outputWidth1 = inputWidth; |
| 41 | unsigned int outputHeight1 = inputHeight; |
| 42 | unsigned int outputChannels1 = 1; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 43 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | // To take channel 1 and 2 of the original output. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 45 | unsigned int outputWidth2 = inputWidth; |
| 46 | unsigned int outputHeight2 = inputHeight; |
| 47 | unsigned int outputChannels2 = 2; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | |
| 49 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 50 | // Define the tensor descriptors. |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 51 | armnn::TensorInfo inputTensorInfo({ inputChannels, inputHeight, inputWidth }, ArmnnType, qScale, qOffset); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 52 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 53 | // Outputs of the original split. |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 54 | armnn::TensorInfo outputTensorInfo1({ outputChannels1, outputHeight1, outputWidth1 }, ArmnnType, qScale, qOffset); |
| 55 | armnn::TensorInfo outputTensorInfo2({ outputChannels2, outputHeight2, outputWidth2 }, ArmnnType, qScale, qOffset); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 56 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 57 | // Outputs of the subsequent subtensor split. |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 58 | armnn::TensorInfo outputTensorInfo3({ outputChannels1, outputHeight1, outputWidth1 }, ArmnnType, qScale, qOffset); |
| 59 | armnn::TensorInfo outputTensorInfo4({ outputChannels1, outputHeight1, outputWidth1 }, ArmnnType, qScale, qOffset); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 60 | |
| 61 | // Set quantization parameters if the requested type is a quantized type. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | // The quantization doesn't really matter as the splitter operator doesn't dequantize/quantize. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 63 | if(armnn::IsQuantizedType<T>()) |
| 64 | { |
| 65 | inputTensorInfo.SetQuantizationScale(qScale); |
| 66 | inputTensorInfo.SetQuantizationOffset(qOffset); |
| 67 | outputTensorInfo1.SetQuantizationScale(qScale); |
| 68 | outputTensorInfo1.SetQuantizationOffset(qOffset); |
| 69 | outputTensorInfo2.SetQuantizationScale(qScale); |
| 70 | outputTensorInfo2.SetQuantizationOffset(qOffset); |
| 71 | outputTensorInfo3.SetQuantizationScale(qScale); |
| 72 | outputTensorInfo3.SetQuantizationOffset(qOffset); |
| 73 | outputTensorInfo4.SetQuantizationScale(qScale); |
| 74 | outputTensorInfo4.SetQuantizationOffset(qOffset); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | LayerTestResult<T,3> ret1(outputTensorInfo1); |
| 78 | LayerTestResult<T,3> ret2(outputTensorInfo2); |
| 79 | LayerTestResult<T,3> ret3(outputTensorInfo3); |
| 80 | LayerTestResult<T,3> ret4(outputTensorInfo4); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | |
| 82 | auto input = MakeTensor<T, 3>(inputTensorInfo, std::vector<T>( |
| 83 | QuantizedVector<T>(qScale, qOffset, { |
| 84 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, |
| 85 | 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
| 86 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, |
| 87 | 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
| 88 | 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, |
| 89 | 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, |
| 90 | |
| 91 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 92 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 93 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 94 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 95 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 96 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
| 97 | |
| 98 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 99 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 100 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 101 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 102 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 103 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
| 104 | }) |
| 105 | )); |
| 106 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 107 | // Channel 0 of the original input. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 108 | ret1.outputExpected = MakeTensor<T, 3>(outputTensorInfo1, std::vector<T>( |
| 109 | QuantizedVector<T>(qScale, qOffset, { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 110 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, |
| 111 | 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
| 112 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, |
| 113 | 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
| 114 | 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, |
| 115 | 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 116 | }) |
| 117 | )); |
| 118 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 119 | // Channel 1 & 2 of the original input. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 120 | ret2.outputExpected = MakeTensor<T, 3>(outputTensorInfo2, std::vector<T>( |
| 121 | QuantizedVector<T>(qScale, qOffset, { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 122 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 123 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 124 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 125 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 126 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 127 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 128 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 129 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 130 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 131 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 132 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 133 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 134 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 135 | }) |
| 136 | )); |
| 137 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 138 | // Channel 0 of return 2 (i.e. channels 1 and 2 of the original input). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 139 | ret3.outputExpected = MakeTensor<T, 3>(outputTensorInfo3, std::vector<T>( |
| 140 | QuantizedVector<T>(qScale, qOffset, { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 141 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 142 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 143 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 144 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 145 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 146 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 147 | }) |
| 148 | )); |
| 149 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 150 | // Channel 1 of return 2. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 151 | ret4.outputExpected = MakeTensor<T, 3>(outputTensorInfo4, std::vector<T>( |
| 152 | QuantizedVector<T>(qScale, qOffset, { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 153 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 154 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 155 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 156 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 157 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 158 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 159 | }) |
| 160 | )); |
| 161 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 162 | // NOTE: as a corollary of the splitting of x and y restriction the x and y values of the view origins |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 163 | // have to be zero, the co-ordinates are as per the tensor info above channels, height/y, width/x |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 164 | // note that under the hood the compute engine reverses these i.e. its coordinate system is x, y, channels. |
| 165 | std::vector<unsigned int> wOrigin1 = {0, 0, 0}; //Extent of the window is defined by size of output[0]. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 166 | armnn::SplitterQueueDescriptor::ViewOrigin window1(wOrigin1); |
| 167 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 168 | std::vector<unsigned int> wOrigin2 = {1, 0, 0}; //Extent of the window is defined by size of output[1]. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 169 | armnn::SplitterQueueDescriptor::ViewOrigin window2(wOrigin2); |
| 170 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 171 | std::vector<unsigned int> wOrigin3 = {0, 0, 0}; //Extent of the window is defined by size of output[2]. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 172 | armnn::SplitterQueueDescriptor::ViewOrigin window3(wOrigin3); |
| 173 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 174 | std::vector<unsigned int> wOrigin4 = {1, 0, 0}; //Extent of the window is defined by size of output[3]. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 175 | armnn::SplitterQueueDescriptor::ViewOrigin window4(wOrigin4); |
| 176 | |
| 177 | bool subTensorsSupported = workloadFactory.SupportsSubTensors(); |
| 178 | |
| 179 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 180 | |
| 181 | std::unique_ptr<armnn::ITensorHandle> outputHandle1 = |
| 182 | subTensorsSupported ? |
| 183 | workloadFactory.CreateSubTensorHandle(*inputHandle, outputTensorInfo1.GetShape(), wOrigin1.data()) : |
| 184 | workloadFactory.CreateTensorHandle(outputTensorInfo1); |
| 185 | |
| 186 | std::unique_ptr<armnn::ITensorHandle> outputHandle2 = |
| 187 | subTensorsSupported ? |
| 188 | workloadFactory.CreateSubTensorHandle(*inputHandle, outputTensorInfo2.GetShape(), wOrigin2.data()) : |
| 189 | workloadFactory.CreateTensorHandle(outputTensorInfo2); |
| 190 | |
| 191 | std::unique_ptr<armnn::ITensorHandle> outputHandle3 = |
| 192 | subTensorsSupported ? |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 193 | workloadFactory.CreateSubTensorHandle(*outputHandle2, outputTensorInfo3.GetShape(), wOrigin3.data()) : |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 194 | workloadFactory.CreateTensorHandle(outputTensorInfo3); |
| 195 | |
| 196 | std::unique_ptr<armnn::ITensorHandle> outputHandle4 = |
| 197 | subTensorsSupported ? |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 198 | workloadFactory.CreateSubTensorHandle(*outputHandle2, outputTensorInfo4.GetShape(), wOrigin4.data()) : |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 199 | workloadFactory.CreateTensorHandle(outputTensorInfo4); |
| 200 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 201 | // Do the first split |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 202 | armnn::SplitterQueueDescriptor data; |
| 203 | armnn::WorkloadInfo info; |
| 204 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 205 | AddOutputToWorkload(data, info, outputTensorInfo1, outputHandle1.get()); |
| 206 | AddOutputToWorkload(data, info, outputTensorInfo2, outputHandle2.get()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 207 | |
| 208 | data.m_ViewOrigins.push_back(window1); |
| 209 | data.m_ViewOrigins.push_back(window2); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 210 | |
| 211 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSplitter(data, info); |
| 212 | |
| 213 | inputHandle->Allocate(); |
| 214 | outputHandle1->Allocate(); |
| 215 | outputHandle2->Allocate(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 216 | |
| 217 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0]); |
| 218 | |
| 219 | workload->Execute(); |
| 220 | |
| 221 | CopyDataFromITensorHandle(&ret1.output[0][0][0], outputHandle1.get()); |
| 222 | CopyDataFromITensorHandle(&ret2.output[0][0][0], outputHandle2.get()); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 223 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 224 | // Do the second split. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 225 | armnn::SplitterQueueDescriptor data2; |
| 226 | armnn::WorkloadInfo info2; |
| 227 | AddInputToWorkload(data2, info2, outputTensorInfo2, outputHandle2.get()); |
| 228 | AddOutputToWorkload(data2, info2, outputTensorInfo3, outputHandle3.get()); |
| 229 | AddOutputToWorkload(data2, info2, outputTensorInfo4, outputHandle4.get()); |
| 230 | |
| 231 | data2.m_ViewOrigins.push_back(window3); |
| 232 | data2.m_ViewOrigins.push_back(window4); |
| 233 | |
| 234 | std::unique_ptr<armnn::IWorkload> workload2 = workloadFactory.CreateSplitter(data2, info2); |
| 235 | |
| 236 | outputHandle3->Allocate(); |
| 237 | outputHandle4->Allocate(); |
| 238 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 239 | ExecuteWorkload(*workload2, memoryManager); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 240 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 241 | CopyDataFromITensorHandle(&ret3.output[0][0][0], outputHandle3.get()); |
| 242 | CopyDataFromITensorHandle(&ret4.output[0][0][0], outputHandle4.get()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 243 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 244 | std::vector<LayerTestResult<T,3>> ret = {ret1, ret2, ret3, ret4,}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 245 | |
| 246 | return ret; |
| 247 | } |
| 248 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 249 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 250 | LayerTestResult<T, 3> CopyViaSplitterTestImpl( |
| 251 | armnn::IWorkloadFactory& workloadFactory, |
| 252 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 253 | float qScale, int32_t qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 254 | { |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 255 | const armnn::TensorInfo tensorInfo({ 3, 6, 5 }, ArmnnType, qScale, qOffset); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 256 | auto input = MakeTensor<T, 3>(tensorInfo, QuantizedVector<T>(qScale, qOffset, |
| 257 | { |
| 258 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, |
| 259 | 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
| 260 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, |
| 261 | 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
| 262 | 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, |
| 263 | 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, |
| 264 | |
| 265 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 266 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 267 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 268 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 269 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 270 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
| 271 | |
| 272 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 273 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 274 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 275 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 276 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 277 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
| 278 | })); |
| 279 | |
| 280 | std::vector<unsigned int> origin = { 0, 0, 0 }; |
| 281 | armnn::SplitterQueueDescriptor::ViewOrigin window(origin); |
| 282 | |
| 283 | const bool subTensorsSupported = workloadFactory.SupportsSubTensors(); |
| 284 | |
| 285 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(tensorInfo); |
| 286 | |
| 287 | std::unique_ptr<armnn::ITensorHandle> outputHandle = |
| 288 | subTensorsSupported ? |
| 289 | workloadFactory.CreateSubTensorHandle(*inputHandle, tensorInfo.GetShape(), origin.data()) : |
| 290 | workloadFactory.CreateTensorHandle(tensorInfo); |
| 291 | |
| 292 | armnn::SplitterQueueDescriptor data; |
| 293 | armnn::WorkloadInfo info; |
| 294 | AddInputToWorkload(data, info, tensorInfo, inputHandle.get()); |
| 295 | AddOutputToWorkload(data, info, tensorInfo, outputHandle.get()); |
| 296 | |
| 297 | data.m_ViewOrigins.push_back(window); |
| 298 | |
| 299 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSplitter(data, info); |
| 300 | |
| 301 | inputHandle->Allocate(); |
| 302 | outputHandle->Allocate(); |
| 303 | |
| 304 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0]); |
| 305 | |
| 306 | workload->Execute(); |
| 307 | |
| 308 | LayerTestResult<T, 3> ret(tensorInfo); |
| 309 | CopyDataFromITensorHandle(&ret.output[0][0][0], outputHandle.get()); |
| 310 | ret.outputExpected = input; |
| 311 | |
| 312 | return ret; |
| 313 | } |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 314 | |
| 315 | } // anonymous namespace |
| 316 | |
| 317 | std::vector<LayerTestResult<float,3>> SplitterFloatTest( |
| 318 | armnn::IWorkloadFactory& workloadFactory, |
| 319 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 320 | { |
| 321 | return SplitterTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 322 | } |
| 323 | |
| 324 | std::vector<LayerTestResult<uint8_t,3>> SplitterUint8Test( |
| 325 | armnn::IWorkloadFactory& workloadFactory, |
| 326 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 327 | { |
| 328 | return SplitterTestCommon<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 329 | } |
| 330 | |
| 331 | std::vector<LayerTestResult<int16_t,3>> SplitterInt16Test( |
| 332 | armnn::IWorkloadFactory& workloadFactory, |
| 333 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 334 | { |
| 335 | return SplitterTestCommon<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, 1.0f, 0); |
| 336 | } |
| 337 | |
| 338 | LayerTestResult<float, 3> CopyViaSplitterFloatTest( |
| 339 | armnn::IWorkloadFactory& workloadFactory, |
| 340 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 341 | { |
| 342 | return CopyViaSplitterTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0); |
| 343 | } |
| 344 | |
| 345 | LayerTestResult<uint8_t, 3> CopyViaSplitterUint8Test( |
| 346 | armnn::IWorkloadFactory& workloadFactory, |
| 347 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 348 | { |
| 349 | return CopyViaSplitterTestImpl<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 350 | } |
| 351 | |
| 352 | LayerTestResult<int16_t, 3> CopyViaSplitterInt16Test( |
| 353 | armnn::IWorkloadFactory& workloadFactory, |
| 354 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 355 | { |
| 356 | return CopyViaSplitterTestImpl<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, 1.0f, 0); |
| 357 | } |