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