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 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 8 | #include <QuantizeHelper.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 9 | #include <ResolveType.hpp> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 10 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | #include <armnn/ArmNN.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
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>( |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 83 | armnnUtils::QuantizedVector<T>({ |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 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, |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 104 | }, |
| 105 | qScale, qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 106 | )); |
| 107 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 108 | // Channel 0 of the original input. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 109 | ret1.outputExpected = MakeTensor<T, 3>(outputTensorInfo1, std::vector<T>( |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 110 | armnnUtils::QuantizedVector<T>({ |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 111 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, |
| 112 | 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
| 113 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, |
| 114 | 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
| 115 | 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, |
| 116 | 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 117 | }, |
| 118 | qScale, qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 119 | )); |
| 120 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 121 | // Channel 1 & 2 of the original input. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 122 | ret2.outputExpected = MakeTensor<T, 3>(outputTensorInfo2, std::vector<T>( |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 123 | armnnUtils::QuantizedVector<T>({ |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 124 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 125 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 126 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 127 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 128 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 129 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 130 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 131 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 132 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 133 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 134 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 135 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 136 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 137 | }, |
| 138 | qScale, qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 139 | )); |
| 140 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 141 | // 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] | 142 | ret3.outputExpected = MakeTensor<T, 3>(outputTensorInfo3, std::vector<T>( |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 143 | armnnUtils::QuantizedVector<T>({ |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 144 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 145 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 146 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 147 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 148 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 149 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 150 | }, |
| 151 | qScale, qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 152 | )); |
| 153 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 154 | // Channel 1 of return 2. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 155 | ret4.outputExpected = MakeTensor<T, 3>(outputTensorInfo4, std::vector<T>( |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 156 | armnnUtils::QuantizedVector<T>({ |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 157 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 158 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 159 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 160 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 161 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 162 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 163 | }, |
| 164 | qScale, qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 165 | )); |
| 166 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 167 | // 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] | 168 | // 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] | 169 | // note that under the hood the compute engine reverses these i.e. its coordinate system is x, y, channels. |
| 170 | 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] | 171 | armnn::SplitterQueueDescriptor::ViewOrigin window1(wOrigin1); |
| 172 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 173 | 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] | 174 | armnn::SplitterQueueDescriptor::ViewOrigin window2(wOrigin2); |
| 175 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 176 | 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] | 177 | armnn::SplitterQueueDescriptor::ViewOrigin window3(wOrigin3); |
| 178 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 179 | 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] | 180 | armnn::SplitterQueueDescriptor::ViewOrigin window4(wOrigin4); |
| 181 | |
| 182 | bool subTensorsSupported = workloadFactory.SupportsSubTensors(); |
| 183 | |
| 184 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 185 | |
| 186 | std::unique_ptr<armnn::ITensorHandle> outputHandle1 = |
| 187 | subTensorsSupported ? |
| 188 | workloadFactory.CreateSubTensorHandle(*inputHandle, outputTensorInfo1.GetShape(), wOrigin1.data()) : |
| 189 | workloadFactory.CreateTensorHandle(outputTensorInfo1); |
| 190 | |
| 191 | std::unique_ptr<armnn::ITensorHandle> outputHandle2 = |
| 192 | subTensorsSupported ? |
| 193 | workloadFactory.CreateSubTensorHandle(*inputHandle, outputTensorInfo2.GetShape(), wOrigin2.data()) : |
| 194 | workloadFactory.CreateTensorHandle(outputTensorInfo2); |
| 195 | |
| 196 | std::unique_ptr<armnn::ITensorHandle> outputHandle3 = |
| 197 | subTensorsSupported ? |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 198 | workloadFactory.CreateSubTensorHandle(*outputHandle2, outputTensorInfo3.GetShape(), wOrigin3.data()) : |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 199 | workloadFactory.CreateTensorHandle(outputTensorInfo3); |
| 200 | |
| 201 | std::unique_ptr<armnn::ITensorHandle> outputHandle4 = |
| 202 | subTensorsSupported ? |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 203 | workloadFactory.CreateSubTensorHandle(*outputHandle2, outputTensorInfo4.GetShape(), wOrigin4.data()) : |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 204 | workloadFactory.CreateTensorHandle(outputTensorInfo4); |
| 205 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 206 | // Do the first split |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 207 | armnn::SplitterQueueDescriptor data; |
| 208 | armnn::WorkloadInfo info; |
| 209 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 210 | AddOutputToWorkload(data, info, outputTensorInfo1, outputHandle1.get()); |
| 211 | AddOutputToWorkload(data, info, outputTensorInfo2, outputHandle2.get()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 212 | |
| 213 | data.m_ViewOrigins.push_back(window1); |
| 214 | data.m_ViewOrigins.push_back(window2); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 215 | |
| 216 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSplitter(data, info); |
| 217 | |
| 218 | inputHandle->Allocate(); |
| 219 | outputHandle1->Allocate(); |
| 220 | outputHandle2->Allocate(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 221 | |
| 222 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0]); |
| 223 | |
| 224 | workload->Execute(); |
| 225 | |
| 226 | CopyDataFromITensorHandle(&ret1.output[0][0][0], outputHandle1.get()); |
| 227 | CopyDataFromITensorHandle(&ret2.output[0][0][0], outputHandle2.get()); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 228 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 229 | // Do the second split. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 230 | armnn::SplitterQueueDescriptor data2; |
| 231 | armnn::WorkloadInfo info2; |
| 232 | AddInputToWorkload(data2, info2, outputTensorInfo2, outputHandle2.get()); |
| 233 | AddOutputToWorkload(data2, info2, outputTensorInfo3, outputHandle3.get()); |
| 234 | AddOutputToWorkload(data2, info2, outputTensorInfo4, outputHandle4.get()); |
| 235 | |
| 236 | data2.m_ViewOrigins.push_back(window3); |
| 237 | data2.m_ViewOrigins.push_back(window4); |
| 238 | |
| 239 | std::unique_ptr<armnn::IWorkload> workload2 = workloadFactory.CreateSplitter(data2, info2); |
| 240 | |
| 241 | outputHandle3->Allocate(); |
| 242 | outputHandle4->Allocate(); |
| 243 | |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 244 | ExecuteWorkload(*workload2, memoryManager); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 245 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 246 | CopyDataFromITensorHandle(&ret3.output[0][0][0], outputHandle3.get()); |
| 247 | CopyDataFromITensorHandle(&ret4.output[0][0][0], outputHandle4.get()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 248 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 249 | std::vector<LayerTestResult<T,3>> ret = {ret1, ret2, ret3, ret4,}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 250 | |
| 251 | return ret; |
| 252 | } |
| 253 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 254 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 255 | LayerTestResult<T, 3> CopyViaSplitterTestImpl( |
| 256 | armnn::IWorkloadFactory& workloadFactory, |
| 257 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 258 | float qScale, int32_t qOffset) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 259 | { |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 260 | const armnn::TensorInfo tensorInfo({ 3, 6, 5 }, ArmnnType, qScale, qOffset); |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 261 | auto input = MakeTensor<T, 3>( |
| 262 | tensorInfo, |
| 263 | armnnUtils::QuantizedVector<T>({ |
| 264 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, |
| 265 | 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, |
| 266 | 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, |
| 267 | 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, |
| 268 | 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, |
| 269 | 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 270 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 271 | 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, |
| 272 | 36.0f, 37.0f, 38.0f, 39.0f, 40.0f, |
| 273 | 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, |
| 274 | 46.0f, 47.0f, 48.0f, 49.0f, 50.0f, |
| 275 | 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, |
| 276 | 56.0f, 57.0f, 58.0f, 59.0f, 60.0f, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 277 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 278 | 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, |
| 279 | 66.0f, 67.0f, 68.0f, 69.0f, 70.0f, |
| 280 | 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, |
| 281 | 76.0f, 77.0f, 78.0f, 79.0f, 80.0f, |
| 282 | 81.0f, 82.0f, 83.0f, 84.0f, 85.0f, |
| 283 | 86.0f, 87.0f, 88.0f, 89.0f, 90.0f, |
| 284 | }, |
| 285 | qScale, qOffset)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 286 | |
| 287 | std::vector<unsigned int> origin = { 0, 0, 0 }; |
| 288 | armnn::SplitterQueueDescriptor::ViewOrigin window(origin); |
| 289 | |
| 290 | const bool subTensorsSupported = workloadFactory.SupportsSubTensors(); |
| 291 | |
| 292 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(tensorInfo); |
| 293 | |
| 294 | std::unique_ptr<armnn::ITensorHandle> outputHandle = |
| 295 | subTensorsSupported ? |
| 296 | workloadFactory.CreateSubTensorHandle(*inputHandle, tensorInfo.GetShape(), origin.data()) : |
| 297 | workloadFactory.CreateTensorHandle(tensorInfo); |
| 298 | |
| 299 | armnn::SplitterQueueDescriptor data; |
| 300 | armnn::WorkloadInfo info; |
| 301 | AddInputToWorkload(data, info, tensorInfo, inputHandle.get()); |
| 302 | AddOutputToWorkload(data, info, tensorInfo, outputHandle.get()); |
| 303 | |
| 304 | data.m_ViewOrigins.push_back(window); |
| 305 | |
| 306 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSplitter(data, info); |
| 307 | |
| 308 | inputHandle->Allocate(); |
| 309 | outputHandle->Allocate(); |
| 310 | |
| 311 | CopyDataToITensorHandle(inputHandle.get(), &input[0][0][0]); |
| 312 | |
| 313 | workload->Execute(); |
| 314 | |
| 315 | LayerTestResult<T, 3> ret(tensorInfo); |
| 316 | CopyDataFromITensorHandle(&ret.output[0][0][0], outputHandle.get()); |
| 317 | ret.outputExpected = input; |
| 318 | |
| 319 | return ret; |
| 320 | } |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 321 | |
| 322 | } // anonymous namespace |
| 323 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 324 | std::vector<LayerTestResult<float,3>> SplitterFloat32Test( |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 325 | armnn::IWorkloadFactory& workloadFactory, |
| 326 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 327 | { |
| 328 | return SplitterTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 329 | } |
| 330 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 331 | std::vector<LayerTestResult<armnn::Half,3>> SplitterFloat16Test( |
| 332 | armnn::IWorkloadFactory& workloadFactory, |
| 333 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 334 | { |
| 335 | return SplitterTestCommon<armnn::DataType::Float16>(workloadFactory, memoryManager); |
| 336 | } |
| 337 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 338 | std::vector<LayerTestResult<uint8_t,3>> SplitterUint8Test( |
| 339 | armnn::IWorkloadFactory& workloadFactory, |
| 340 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 341 | { |
| 342 | return SplitterTestCommon<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 343 | } |
| 344 | |
| 345 | std::vector<LayerTestResult<int16_t,3>> SplitterInt16Test( |
| 346 | armnn::IWorkloadFactory& workloadFactory, |
| 347 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 348 | { |
| 349 | return SplitterTestCommon<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, 1.0f, 0); |
| 350 | } |
| 351 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 352 | LayerTestResult<float, 3> CopyViaSplitterFloat32Test( |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 353 | armnn::IWorkloadFactory& workloadFactory, |
| 354 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 355 | { |
| 356 | return CopyViaSplitterTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0); |
| 357 | } |
| 358 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 359 | LayerTestResult<armnn::Half, 3> CopyViaSplitterFloat16Test( |
| 360 | armnn::IWorkloadFactory& workloadFactory, |
| 361 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 362 | { |
| 363 | return CopyViaSplitterTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, 0.0f, 0); |
| 364 | } |
| 365 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 366 | LayerTestResult<uint8_t, 3> CopyViaSplitterUint8Test( |
| 367 | armnn::IWorkloadFactory& workloadFactory, |
| 368 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 369 | { |
| 370 | return CopyViaSplitterTestImpl<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 371 | } |
| 372 | |
| 373 | LayerTestResult<int16_t, 3> CopyViaSplitterInt16Test( |
| 374 | armnn::IWorkloadFactory& workloadFactory, |
| 375 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 376 | { |
| 377 | return CopyViaSplitterTestImpl<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, 1.0f, 0); |
| 378 | } |