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