Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 5 | |
| 6 | #include "StridedSliceTestImpl.hpp" |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 7 | |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 8 | #include <ResolveType.hpp> |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 9 | |
| 10 | #include <armnn/ArmNN.hpp> |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 11 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 12 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 13 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 14 | |
| 15 | #include <test/TensorHelpers.hpp> |
| 16 | |
| 17 | namespace |
| 18 | { |
| 19 | |
| 20 | template<typename T, std::size_t InDim, std::size_t OutDim> |
| 21 | LayerTestResult<T, OutDim> StridedSliceTestImpl( |
| 22 | armnn::IWorkloadFactory& workloadFactory, |
| 23 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 24 | armnn::TensorInfo& inputTensorInfo, |
| 25 | armnn::TensorInfo& outputTensorInfo, |
| 26 | std::vector<float>& inputData, |
| 27 | std::vector<float>& outputExpectedData, |
| 28 | armnn::StridedSliceQueueDescriptor descriptor, |
| 29 | const float qScale = 1.0f, |
| 30 | const int32_t qOffset = 0) |
| 31 | { |
| 32 | if(armnn::IsQuantizedType<T>()) |
| 33 | { |
| 34 | inputTensorInfo.SetQuantizationScale(qScale); |
| 35 | inputTensorInfo.SetQuantizationOffset(qOffset); |
| 36 | |
| 37 | outputTensorInfo.SetQuantizationScale(qScale); |
| 38 | outputTensorInfo.SetQuantizationOffset(qOffset); |
| 39 | } |
| 40 | |
| 41 | boost::multi_array<T, InDim> input = |
| 42 | MakeTensor<T, InDim>(inputTensorInfo, QuantizedVector<T>(qScale, qOffset, inputData)); |
| 43 | |
| 44 | LayerTestResult<T, OutDim> ret(outputTensorInfo); |
| 45 | ret.outputExpected = |
| 46 | MakeTensor<T, OutDim>(outputTensorInfo, QuantizedVector<T>(qScale, qOffset, outputExpectedData)); |
| 47 | |
| 48 | std::unique_ptr<armnn::ITensorHandle> inputHandle = |
| 49 | workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 50 | |
| 51 | std::unique_ptr<armnn::ITensorHandle> outputHandle = |
| 52 | workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 53 | |
| 54 | armnn::WorkloadInfo info; |
| 55 | AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); |
| 56 | AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); |
| 57 | |
| 58 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateStridedSlice(descriptor, info); |
| 59 | |
| 60 | inputHandle->Allocate(); |
| 61 | outputHandle->Allocate(); |
| 62 | |
| 63 | CopyDataToITensorHandle(inputHandle.get(), input.data()); |
| 64 | |
| 65 | ExecuteWorkload(*workload, memoryManager); |
| 66 | |
| 67 | CopyDataFromITensorHandle(ret.output.data(), outputHandle.get()); |
| 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 72 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 73 | LayerTestResult<T, 4> StridedSlice4dTest( |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 74 | armnn::IWorkloadFactory& workloadFactory, |
| 75 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 76 | { |
| 77 | armnn::TensorInfo inputTensorInfo; |
| 78 | armnn::TensorInfo outputTensorInfo; |
| 79 | |
| 80 | unsigned int inputShape[] = {3, 2, 3, 1}; |
| 81 | unsigned int outputShape[] = {1, 2, 3, 1}; |
| 82 | |
| 83 | armnn::StridedSliceQueueDescriptor desc; |
| 84 | desc.m_Parameters.m_Begin = {1, 0, 0, 0}; |
| 85 | desc.m_Parameters.m_End = {2, 2, 3, 1}; |
| 86 | desc.m_Parameters.m_Stride = {1, 1, 1, 1}; |
| 87 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 88 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 89 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 90 | |
| 91 | std::vector<float> input = std::vector<float>( |
| 92 | { |
| 93 | 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, |
| 94 | |
| 95 | 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, |
| 96 | |
| 97 | 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f |
| 98 | }); |
| 99 | |
| 100 | std::vector<float> outputExpected = std::vector<float>( |
| 101 | { |
| 102 | 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f |
| 103 | }); |
| 104 | |
| 105 | return StridedSliceTestImpl<T, 4, 4>( |
| 106 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 107 | } |
| 108 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 109 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 110 | LayerTestResult<T, 4> StridedSlice4dReverseTest( |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 111 | armnn::IWorkloadFactory& workloadFactory, |
| 112 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 113 | { |
| 114 | armnn::TensorInfo inputTensorInfo; |
| 115 | armnn::TensorInfo outputTensorInfo; |
| 116 | |
| 117 | unsigned int inputShape[] = {3, 2, 3, 1}; |
| 118 | unsigned int outputShape[] = {1, 2, 3, 1}; |
| 119 | |
| 120 | armnn::StridedSliceQueueDescriptor desc; |
| 121 | desc.m_Parameters.m_Begin = {1, -1, 0, 0}; |
| 122 | desc.m_Parameters.m_End = {2, -3, 3, 1}; |
| 123 | desc.m_Parameters.m_Stride = {1, -1, 1, 1}; |
| 124 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 125 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 126 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 127 | |
| 128 | std::vector<float> input = std::vector<float>( |
| 129 | { |
| 130 | 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, |
| 131 | |
| 132 | 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, |
| 133 | |
| 134 | 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f |
| 135 | }); |
| 136 | |
| 137 | std::vector<float> outputExpected = std::vector<float>( |
| 138 | { |
| 139 | 4.0f, 4.0f, 4.0f, 3.0f, 3.0f, 3.0f |
| 140 | }); |
| 141 | |
| 142 | return StridedSliceTestImpl<T, 4, 4>( |
| 143 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 144 | } |
| 145 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 146 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 147 | LayerTestResult<T, 4> StridedSliceSimpleStrideTest( |
| 148 | armnn::IWorkloadFactory& workloadFactory, |
| 149 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 150 | { |
| 151 | armnn::TensorInfo inputTensorInfo; |
| 152 | armnn::TensorInfo outputTensorInfo; |
| 153 | |
| 154 | unsigned int inputShape[] = {3, 2, 3, 1}; |
| 155 | unsigned int outputShape[] = {2, 1, 2, 1}; |
| 156 | |
| 157 | armnn::StridedSliceQueueDescriptor desc; |
| 158 | desc.m_Parameters.m_Begin = {0, 0, 0, 0}; |
| 159 | desc.m_Parameters.m_End = {3, 2, 3, 1}; |
| 160 | desc.m_Parameters.m_Stride = {2, 2, 2, 1}; |
| 161 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 162 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 163 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 164 | |
| 165 | std::vector<float> input = std::vector<float>( |
| 166 | { |
| 167 | 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, |
| 168 | |
| 169 | 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, |
| 170 | |
| 171 | 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f |
| 172 | }); |
| 173 | |
| 174 | std::vector<float> outputExpected = std::vector<float>( |
| 175 | { |
| 176 | 1.0f, 1.0f, |
| 177 | |
| 178 | 5.0f, 5.0f |
| 179 | }); |
| 180 | |
| 181 | return StridedSliceTestImpl<T, 4, 4>( |
| 182 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 183 | } |
| 184 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 185 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 186 | LayerTestResult<T, 4> StridedSliceSimpleRangeMaskTest( |
| 187 | armnn::IWorkloadFactory& workloadFactory, |
| 188 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 189 | { |
| 190 | armnn::TensorInfo inputTensorInfo; |
| 191 | armnn::TensorInfo outputTensorInfo; |
| 192 | |
| 193 | unsigned int inputShape[] = {3, 2, 3, 1}; |
| 194 | unsigned int outputShape[] = {3, 2, 3, 1}; |
| 195 | |
| 196 | armnn::StridedSliceQueueDescriptor desc; |
| 197 | desc.m_Parameters.m_Begin = {1, 1, 1, 1}; |
| 198 | desc.m_Parameters.m_End = {1, 1, 1, 1}; |
| 199 | desc.m_Parameters.m_Stride = {1, 1, 1, 1}; |
| 200 | desc.m_Parameters.m_BeginMask = (1 << 4) - 1; |
| 201 | desc.m_Parameters.m_EndMask = (1 << 4) - 1; |
| 202 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 203 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 204 | outputTensorInfo = armnn::TensorInfo(4, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 205 | |
| 206 | std::vector<float> input = std::vector<float>( |
| 207 | { |
| 208 | 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, |
| 209 | |
| 210 | 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, |
| 211 | |
| 212 | 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f |
| 213 | }); |
| 214 | |
| 215 | std::vector<float> outputExpected = std::vector<float>( |
| 216 | { |
| 217 | 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, |
| 218 | |
| 219 | 3.0f, 3.0f, 3.0f, 4.0f, 4.0f, 4.0f, |
| 220 | |
| 221 | 5.0f, 5.0f, 5.0f, 6.0f, 6.0f, 6.0f |
| 222 | }); |
| 223 | |
| 224 | return StridedSliceTestImpl<T, 4, 4>( |
| 225 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 226 | } |
| 227 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 228 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 229 | LayerTestResult<T, 2> StridedSliceShrinkAxisMaskTest( |
| 230 | armnn::IWorkloadFactory& workloadFactory, |
| 231 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 232 | { |
| 233 | armnn::TensorInfo inputTensorInfo; |
| 234 | armnn::TensorInfo outputTensorInfo; |
| 235 | |
| 236 | unsigned int inputShape[] = {3, 2, 3, 1}; |
| 237 | unsigned int outputShape[] = {3, 1}; |
| 238 | |
| 239 | armnn::StridedSliceQueueDescriptor desc; |
| 240 | desc.m_Parameters.m_Begin = {0, 0, 1, 0}; |
| 241 | desc.m_Parameters.m_End = {1, 1, 1, 1}; |
| 242 | desc.m_Parameters.m_Stride = {1, 1, 1, 1}; |
| 243 | desc.m_Parameters.m_EndMask = (1 << 4) - 1; |
| 244 | desc.m_Parameters.m_ShrinkAxisMask = (1 << 1) | (1 << 2); |
| 245 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 246 | inputTensorInfo = armnn::TensorInfo(4, inputShape, ArmnnType); |
| 247 | outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 248 | |
| 249 | std::vector<float> input = std::vector<float>( |
| 250 | { |
| 251 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, |
| 252 | |
| 253 | 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, |
| 254 | |
| 255 | 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f |
| 256 | }); |
| 257 | |
| 258 | std::vector<float> outputExpected = std::vector<float>( |
| 259 | { |
| 260 | 2.0f, 8.0f, 14.0f |
| 261 | }); |
| 262 | |
| 263 | return StridedSliceTestImpl<T, 4, 2>( |
| 264 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 265 | } |
| 266 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 267 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 268 | LayerTestResult<T, 3> StridedSlice3dTest( |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 269 | armnn::IWorkloadFactory& workloadFactory, |
| 270 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 271 | { |
| 272 | armnn::TensorInfo inputTensorInfo; |
| 273 | armnn::TensorInfo outputTensorInfo; |
| 274 | |
| 275 | unsigned int inputShape[] = {3, 3, 3}; |
| 276 | unsigned int outputShape[] = {2, 2, 2}; |
| 277 | |
| 278 | armnn::StridedSliceQueueDescriptor desc; |
| 279 | desc.m_Parameters.m_Begin = {0, 0, 0}; |
| 280 | desc.m_Parameters.m_End = {1, 1, 1}; |
| 281 | desc.m_Parameters.m_Stride = {2, 2, 2}; |
| 282 | desc.m_Parameters.m_EndMask = (1 << 3) - 1; |
| 283 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 284 | inputTensorInfo = armnn::TensorInfo(3, inputShape, ArmnnType); |
| 285 | outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 286 | |
| 287 | std::vector<float> input = std::vector<float>( |
| 288 | { |
| 289 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, |
| 290 | |
| 291 | 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, |
| 292 | |
| 293 | 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f |
| 294 | }); |
| 295 | |
| 296 | std::vector<float> outputExpected = std::vector<float>( |
| 297 | { |
| 298 | 1.0f, 3.0f, 7.0f, 9.0f, |
| 299 | |
| 300 | 19.0f, 21.0f, 25.0f, 27.0f |
| 301 | }); |
| 302 | |
| 303 | return StridedSliceTestImpl<T, 3, 3>( |
| 304 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 305 | } |
| 306 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 307 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 308 | LayerTestResult<T, 3> StridedSlice3dReverseTest( |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 309 | armnn::IWorkloadFactory& workloadFactory, |
| 310 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 311 | { |
| 312 | armnn::TensorInfo inputTensorInfo; |
| 313 | armnn::TensorInfo outputTensorInfo; |
| 314 | |
| 315 | unsigned int inputShape[] = {3, 3, 3}; |
| 316 | unsigned int outputShape[] = {2, 2, 2}; |
| 317 | |
| 318 | armnn::StridedSliceQueueDescriptor desc; |
| 319 | desc.m_Parameters.m_Begin = {-1, -1, -1}; |
| 320 | desc.m_Parameters.m_End = {-4, -4, -4}; |
| 321 | desc.m_Parameters.m_Stride = {-2, -2, -2}; |
| 322 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 323 | inputTensorInfo = armnn::TensorInfo(3, inputShape, ArmnnType); |
| 324 | outputTensorInfo = armnn::TensorInfo(3, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 325 | |
| 326 | std::vector<float> input = std::vector<float>( |
| 327 | { |
| 328 | 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, |
| 329 | |
| 330 | 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, |
| 331 | |
| 332 | 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f |
| 333 | }); |
| 334 | |
| 335 | std::vector<float> outputExpected = std::vector<float>( |
| 336 | { |
| 337 | 27.0f, 25.0f, 21.0f, 19.0f, |
| 338 | |
| 339 | 9.0f, 7.0f, 3.0f, 1.0f |
| 340 | }); |
| 341 | |
| 342 | return StridedSliceTestImpl<T, 3, 3>( |
| 343 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 344 | } |
| 345 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 346 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 347 | LayerTestResult<T, 2> StridedSlice2dTest( |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 348 | armnn::IWorkloadFactory& workloadFactory, |
| 349 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 350 | { |
| 351 | armnn::TensorInfo inputTensorInfo; |
| 352 | armnn::TensorInfo outputTensorInfo; |
| 353 | |
| 354 | unsigned int inputShape[] = {3, 3}; |
| 355 | unsigned int outputShape[] = {2, 2}; |
| 356 | |
| 357 | armnn::StridedSliceQueueDescriptor desc; |
| 358 | desc.m_Parameters.m_Begin = {0, 0}; |
| 359 | desc.m_Parameters.m_End = {1, 1}; |
| 360 | desc.m_Parameters.m_Stride = {2, 2}; |
| 361 | desc.m_Parameters.m_EndMask = (1 << 2) - 1; |
| 362 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 363 | inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); |
| 364 | outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 365 | |
| 366 | std::vector<float> input = std::vector<float>( |
| 367 | { |
| 368 | 1.0f, 2.0f, 3.0f, |
| 369 | |
| 370 | 4.0f, 5.0f, 6.0f, |
| 371 | |
| 372 | 7.0f, 8.0f, 9.0f |
| 373 | }); |
| 374 | |
| 375 | std::vector<float> outputExpected = std::vector<float>( |
| 376 | { |
| 377 | 1.0f, 3.0f, |
| 378 | |
| 379 | 7.0f, 9.0f |
| 380 | }); |
| 381 | |
| 382 | return StridedSliceTestImpl<T, 2, 2>( |
| 383 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 384 | } |
| 385 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 386 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 387 | LayerTestResult<T, 2> StridedSlice2dReverseTest( |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 388 | armnn::IWorkloadFactory& workloadFactory, |
| 389 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 390 | { |
| 391 | armnn::TensorInfo inputTensorInfo; |
| 392 | armnn::TensorInfo outputTensorInfo; |
| 393 | |
| 394 | unsigned int inputShape[] = {3, 3}; |
| 395 | unsigned int outputShape[] = {2, 2}; |
| 396 | |
| 397 | armnn::StridedSliceQueueDescriptor desc; |
| 398 | desc.m_Parameters.m_Begin = {0, 0}; |
| 399 | desc.m_Parameters.m_End = {1, 1}; |
| 400 | desc.m_Parameters.m_Stride = {-2, -2}; |
| 401 | desc.m_Parameters.m_BeginMask = (1 << 2) - 1; |
| 402 | desc.m_Parameters.m_EndMask = (1 << 2) - 1; |
| 403 | |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 404 | inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType); |
| 405 | outputTensorInfo = armnn::TensorInfo(2, outputShape, ArmnnType); |
Nattapat Chaimanowong | 1216b58 | 2018-11-23 15:33:41 +0000 | [diff] [blame] | 406 | |
| 407 | std::vector<float> input = std::vector<float>( |
| 408 | { |
| 409 | 1.0f, 2.0f, 3.0f, |
| 410 | |
| 411 | 4.0f, 5.0f, 6.0f, |
| 412 | |
| 413 | 7.0f, 8.0f, 9.0f |
| 414 | }); |
| 415 | |
| 416 | std::vector<float> outputExpected = std::vector<float>( |
| 417 | { |
| 418 | 9.0f, 7.0f, |
| 419 | |
| 420 | 3.0f, 1.0f |
| 421 | }); |
| 422 | |
| 423 | return StridedSliceTestImpl<T, 2, 2>( |
| 424 | workloadFactory, memoryManager, inputTensorInfo, outputTensorInfo, input, outputExpected, desc); |
| 425 | } |
| 426 | |
| 427 | } // anonymous namespace |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 428 | |
| 429 | LayerTestResult<float, 4> StridedSlice4dFloat32Test( |
| 430 | armnn::IWorkloadFactory& workloadFactory, |
| 431 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 432 | { |
| 433 | return StridedSlice4dTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 434 | } |
| 435 | |
| 436 | LayerTestResult<float, 4> StridedSlice4dReverseFloat32Test( |
| 437 | armnn::IWorkloadFactory& workloadFactory, |
| 438 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 439 | { |
| 440 | return StridedSlice4dReverseTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 441 | } |
| 442 | |
| 443 | LayerTestResult<float, 4> StridedSliceSimpleStrideFloat32Test( |
| 444 | armnn::IWorkloadFactory& workloadFactory, |
| 445 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 446 | { |
| 447 | return StridedSliceSimpleStrideTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 448 | } |
| 449 | |
| 450 | LayerTestResult<float, 4> StridedSliceSimpleRangeMaskFloat32Test( |
| 451 | armnn::IWorkloadFactory& workloadFactory, |
| 452 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 453 | { |
| 454 | return StridedSliceSimpleRangeMaskTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 455 | } |
| 456 | |
| 457 | LayerTestResult<float, 2> StridedSliceShrinkAxisMaskFloat32Test( |
| 458 | armnn::IWorkloadFactory& workloadFactory, |
| 459 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 460 | { |
| 461 | return StridedSliceShrinkAxisMaskTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 462 | } |
| 463 | |
| 464 | LayerTestResult<float, 3> StridedSlice3dFloat32Test( |
| 465 | armnn::IWorkloadFactory& workloadFactory, |
| 466 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 467 | { |
| 468 | return StridedSlice3dTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 469 | } |
| 470 | |
| 471 | LayerTestResult<float, 3> StridedSlice3dReverseFloat32Test( |
| 472 | armnn::IWorkloadFactory& workloadFactory, |
| 473 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 474 | { |
| 475 | return StridedSlice3dReverseTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 476 | } |
| 477 | |
| 478 | LayerTestResult<float, 2> StridedSlice2dFloat32Test( |
| 479 | armnn::IWorkloadFactory& workloadFactory, |
| 480 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 481 | { |
| 482 | return StridedSlice2dTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 483 | } |
| 484 | |
| 485 | LayerTestResult<float, 2> StridedSlice2dReverseFloat32Test( |
| 486 | armnn::IWorkloadFactory& workloadFactory, |
| 487 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 488 | { |
| 489 | return StridedSlice2dReverseTest<armnn::DataType::Float32>(workloadFactory, memoryManager); |
| 490 | } |
| 491 | |
| 492 | LayerTestResult<uint8_t, 4> StridedSlice4dUint8Test( |
| 493 | armnn::IWorkloadFactory& workloadFactory, |
| 494 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 495 | { |
| 496 | return StridedSlice4dTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 497 | } |
| 498 | |
| 499 | LayerTestResult<uint8_t, 4> StridedSlice4dReverseUint8Test( |
| 500 | armnn::IWorkloadFactory& workloadFactory, |
| 501 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 502 | { |
| 503 | return StridedSlice4dReverseTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 504 | } |
| 505 | |
| 506 | LayerTestResult<uint8_t, 4> StridedSliceSimpleStrideUint8Test( |
| 507 | armnn::IWorkloadFactory& workloadFactory, |
| 508 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 509 | { |
| 510 | return StridedSliceSimpleStrideTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 511 | } |
| 512 | |
| 513 | LayerTestResult<uint8_t, 4> StridedSliceSimpleRangeMaskUint8Test( |
| 514 | armnn::IWorkloadFactory& workloadFactory, |
| 515 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 516 | { |
| 517 | return StridedSliceSimpleRangeMaskTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 518 | } |
| 519 | |
| 520 | LayerTestResult<uint8_t, 2> StridedSliceShrinkAxisMaskUint8Test( |
| 521 | armnn::IWorkloadFactory& workloadFactory, |
| 522 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 523 | { |
| 524 | return StridedSliceShrinkAxisMaskTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 525 | } |
| 526 | |
| 527 | LayerTestResult<uint8_t, 3> StridedSlice3dUint8Test( |
| 528 | armnn::IWorkloadFactory& workloadFactory, |
| 529 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 530 | { |
| 531 | return StridedSlice3dTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 532 | } |
| 533 | |
| 534 | LayerTestResult<uint8_t, 3> StridedSlice3dReverseUint8Test( |
| 535 | armnn::IWorkloadFactory& workloadFactory, |
| 536 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 537 | { |
| 538 | return StridedSlice3dReverseTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 539 | } |
| 540 | |
| 541 | LayerTestResult<uint8_t, 2> StridedSlice2dUint8Test( |
| 542 | armnn::IWorkloadFactory& workloadFactory, |
| 543 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 544 | { |
| 545 | return StridedSlice2dTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 546 | } |
| 547 | |
| 548 | LayerTestResult<uint8_t, 2> StridedSlice2dReverseUint8Test( |
| 549 | armnn::IWorkloadFactory& workloadFactory, |
| 550 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 551 | { |
| 552 | return StridedSlice2dReverseTest<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager); |
| 553 | } |
| 554 | |
| 555 | LayerTestResult<int16_t, 4> StridedSlice4dInt16Test( |
| 556 | armnn::IWorkloadFactory& workloadFactory, |
| 557 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 558 | { |
| 559 | return StridedSlice4dTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 560 | } |
| 561 | |
| 562 | LayerTestResult<int16_t, 4> StridedSlice4dReverseInt16Test( |
| 563 | armnn::IWorkloadFactory& workloadFactory, |
| 564 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 565 | { |
| 566 | return StridedSlice4dReverseTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 567 | } |
| 568 | |
| 569 | LayerTestResult<int16_t, 4> StridedSliceSimpleStrideInt16Test( |
| 570 | armnn::IWorkloadFactory& workloadFactory, |
| 571 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 572 | { |
| 573 | return StridedSliceSimpleStrideTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 574 | } |
| 575 | |
| 576 | LayerTestResult<int16_t, 4> StridedSliceSimpleRangeMaskInt16Test( |
| 577 | armnn::IWorkloadFactory& workloadFactory, |
| 578 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 579 | { |
| 580 | return StridedSliceSimpleRangeMaskTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 581 | } |
| 582 | |
| 583 | LayerTestResult<int16_t, 2> StridedSliceShrinkAxisMaskInt16Test( |
| 584 | armnn::IWorkloadFactory& workloadFactory, |
| 585 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 586 | { |
| 587 | return StridedSliceShrinkAxisMaskTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 588 | } |
| 589 | |
| 590 | LayerTestResult<int16_t, 3> StridedSlice3dInt16Test( |
| 591 | armnn::IWorkloadFactory& workloadFactory, |
| 592 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 593 | { |
| 594 | return StridedSlice3dTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 595 | } |
| 596 | |
| 597 | LayerTestResult<int16_t, 3> StridedSlice3dReverseInt16Test( |
| 598 | armnn::IWorkloadFactory& workloadFactory, |
| 599 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 600 | { |
| 601 | return StridedSlice3dReverseTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 602 | } |
| 603 | |
| 604 | LayerTestResult<int16_t, 2> StridedSlice2dInt16Test( |
| 605 | armnn::IWorkloadFactory& workloadFactory, |
| 606 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 607 | { |
| 608 | return StridedSlice2dTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 609 | } |
| 610 | |
| 611 | LayerTestResult<int16_t, 2> StridedSlice2dReverseInt16Test( |
| 612 | armnn::IWorkloadFactory& workloadFactory, |
| 613 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 614 | { |
| 615 | return StridedSlice2dReverseTest<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager); |
| 616 | } |