blob: 5a4990f7481ee6b6fe583697e355b14ab9544f9b [file] [log] [blame]
Narumol Prangnawarat0be43382019-05-27 11:29:59 +01001//
Mike Kellya9c32672023-12-04 17:23:09 +00002// Copyright © 2019-2021,2023 Arm Ltd and Contributors. All rights reserved.
Narumol Prangnawarat0be43382019-05-27 11:29:59 +01003// SPDX-License-Identifier: MIT
4//
5#pragma once
6
7#include <ResolveType.hpp>
8
9#include <armnn/INetwork.hpp>
10
Matthew Sloyan171214c2020-09-09 09:07:37 +010011#include <armnn/utility/NumericCast.hpp>
12
Sadik Armagana097d2a2021-11-24 15:47:28 +000013#include <CommonTestUtils.hpp>
Narumol Prangnawarat0be43382019-05-27 11:29:59 +010014
Sadik Armagan1625efc2021-06-10 18:24:34 +010015#include <doctest/doctest.h>
Narumol Prangnawarat0be43382019-05-27 11:29:59 +010016
17#include <vector>
18
19namespace
20{
21
22template<typename armnn::DataType DataType>
23INetworkPtr CreateSplitterNetwork(const TensorShape& inputShape,
24 const std::vector<TensorShape>& outputShapes,
25 unsigned int splitAxis,
26 unsigned int numSplit,
27 const float qScale = 1.0f,
28 const int32_t qOffset = 0)
29{
30 using namespace armnn;
31 // Builds up the structure of the network.
32 INetworkPtr net(INetwork::Create());
33
Cathal Corbett5b8093c2021-10-22 11:12:07 +010034 TensorInfo inputTensorInfo(inputShape, DataType, qScale, qOffset, true);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +010035
36 std::vector<unsigned int> splitterDimSizes(inputShape.GetNumDimensions());
37
38 // Add current input shape to splitterDimSizes
39 for (unsigned int i = 0; i < inputShape.GetNumDimensions(); ++i)
40 {
41 splitterDimSizes[i] = inputTensorInfo.GetShape()[i];
42 }
43
44 if (splitterDimSizes[splitAxis] % numSplit != 0)
45 {
46 throw ParseException("Number of splits must evenly divide the dimension");
47 }
48 splitterDimSizes[splitAxis] /= numSplit;
49
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +010050 SplitterDescriptor splitDesc(numSplit, inputShape.GetNumDimensions());
Kevin May1bea6be2023-12-12 11:18:46 +000051 splitDesc.SetAxis(static_cast<int32_t>(splitAxis));
Narumol Prangnawarat0be43382019-05-27 11:29:59 +010052 for (unsigned int g = 0; g < numSplit; ++g)
53 {
54 // Set the size of the views.
55 for (unsigned int dimIdx = 0; dimIdx < splitterDimSizes.size(); ++dimIdx)
56 {
57 splitDesc.SetViewSize(g, dimIdx, splitterDimSizes[dimIdx]);
58 }
59 splitDesc.SetViewOriginCoord(g, splitAxis, splitterDimSizes[splitAxis] * g);
60 }
61
62 IConnectableLayer* splitter = net->AddSplitterLayer(splitDesc, "splitter");
63 IConnectableLayer* input = net->AddInputLayer(0, "input");
64 Connect(input, splitter, inputTensorInfo, 0, 0);
65
66 for (unsigned int i = 0; i < outputShapes.size(); ++i)
67 {
68 TensorInfo outputTensorInfo(outputShapes[i], DataType, qScale, qOffset);
Matthew Sloyan171214c2020-09-09 09:07:37 +010069 IConnectableLayer* output = net->AddOutputLayer(armnn::numeric_cast<LayerBindingId>(i));
Narumol Prangnawarat0be43382019-05-27 11:29:59 +010070 Connect(splitter, output, outputTensorInfo, i, 0);
71 }
72
73 return net;
74}
75
76template<armnn::DataType ArmnnType>
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +010077void Splitter1dEndToEnd(const std::vector<BackendId>& backends)
78{
79 using namespace armnn;
80 using T = ResolveType<ArmnnType>;
81
82 unsigned int splitAxis = 0;
83 unsigned int numSplit = 2;
84 const TensorShape& inputShape = { 4 };
85 const std::vector<TensorShape> outputShapes{{ 2 }, { 2 }};
86
87 // Builds up the structure of the network
88 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
89
Sadik Armagan1625efc2021-06-10 18:24:34 +010090 CHECK(net);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +010091
92 // Creates structures for input & output.
93 std::vector<T> inputData{ 1, 2, 3, 4 };
94
95 std::vector<T> expectedOutput0{ 1, 2 };
96 std::vector<T> expectedOutput1{ 3, 4 };
97
98 std::map<int, std::vector<T>> inputTensorData = { { 0, inputData } };
99 std::map<int, std::vector<T>> expectedOutputData = { { 0, expectedOutput0 }, {1, expectedOutput1} };
100
Mike Kellya9c32672023-12-04 17:23:09 +0000101 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100102}
103
104template<armnn::DataType ArmnnType>
Kevin May1bea6be2023-12-12 11:18:46 +0000105void Splitter1dEndToEndFloat16(const std::vector<BackendId>& backends)
106{
107 using namespace armnn;
108 using namespace half_float::literal;
109 using Half = half_float::half;
110
111 unsigned int splitAxis = 0;
112 unsigned int numSplit = 2;
113 const TensorShape& inputShape = { 4 };
114 const std::vector<TensorShape> outputShapes{{ 2 }, { 2 }};
115
116 // Builds up the structure of the network
117 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
118
119 CHECK(net);
120
121 // Creates structures for input & output.
122 std::vector<Half> inputData{ 1._h, 2._h, 3._h, 4._h };
123
124 std::vector<Half> expectedOutput0{ 1._h, 2._h };
125 std::vector<Half> expectedOutput1{ 3._h, 4._h };
126
127 std::map<int, std::vector<Half>> inputTensorData = { { 0, inputData } };
128 std::map<int, std::vector<Half>> expectedOutputData = { { 0, expectedOutput0 }, {1, expectedOutput1} };
129
130 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
131}
132
133template<armnn::DataType ArmnnType>
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100134void Splitter2dDim0EndToEnd(const std::vector<BackendId>& backends)
135{
136 using namespace armnn;
137 using T = ResolveType<ArmnnType>;
138
139 unsigned int splitAxis = 0;
140 unsigned int numSplit = 2;
141 const TensorShape& inputShape = { 4, 3 };
142 const std::vector<TensorShape> outputShapes{{ 2, 3 }, { 2, 3 }};
143
144 // Builds up the structure of the network
145 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
146
Sadik Armagan1625efc2021-06-10 18:24:34 +0100147 CHECK(net);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100148
149 // Creates structures for input & output.
150 std::vector<T> inputData{
151 1, 2,
152 3, 4,
153 5, 6,
154 7, 8,
155 9, 10,
156 11, 12
157 };
158
159 std::vector<T> expectedOutput0{ 1, 2, 3, 4, 5, 6 };
160 std::vector<T> expectedOutput1{ 7, 8, 9, 10, 11, 12 };
161
162 std::map<int, std::vector<T>> inputTensorData = { { 0, inputData } };
163 std::map<int, std::vector<T>> expectedOutputData = { { 0, expectedOutput0 }, {1, expectedOutput1} };
164
Mike Kellya9c32672023-12-04 17:23:09 +0000165 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100166}
167
168template<armnn::DataType ArmnnType>
169void Splitter2dDim1EndToEnd(const std::vector<BackendId>& backends)
170{
171 using namespace armnn;
172 using T = ResolveType<ArmnnType>;
173
174 unsigned int splitAxis = 1;
175 unsigned int numSplit = 3;
176 const TensorShape& inputShape = { 4, 3 };
177 const std::vector<TensorShape> outputShapes{{ 4, 1 }, { 4, 1 }, { 4, 1 }};
178
179 // Builds up the structure of the network
180 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
181
Sadik Armagan1625efc2021-06-10 18:24:34 +0100182 CHECK(net);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100183
184 // Creates structures for input & output.
185 std::vector<T> inputData{
186 1, 2,
187 3, 4,
188 5, 6,
189 7, 8,
190 9, 10,
191 11, 12
192 };
193
194 std::vector<T> expectedOutput0{ 1, 4, 7, 10 };
195 std::vector<T> expectedOutput1{ 2, 5, 8, 11 };
196 std::vector<T> expectedOutput2{ 3, 6, 9, 12 };
197
198 std::map<int, std::vector<T>> inputTensorData = { { 0, inputData } };
199 std::map<int, std::vector<T>> expectedOutputData = { { 0, expectedOutput0 },
200 { 1, expectedOutput1 },
201 { 2, expectedOutput2 } };
202
Mike Kellya9c32672023-12-04 17:23:09 +0000203 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100204}
205
206template<armnn::DataType ArmnnType>
207void Splitter3dDim0EndToEnd(const std::vector<BackendId>& backends)
208{
209 using namespace armnn;
210 using T = ResolveType<ArmnnType>;
211
212 unsigned int splitAxis = 0;
213 unsigned int numSplit = 2;
214 const TensorShape& inputShape = { 2, 4, 3 };
215 const std::vector<TensorShape> outputShapes{{ 1, 4, 3 }, { 1, 4, 3 }};
216
217 // Builds up the structure of the network
218 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
219
Sadik Armagan1625efc2021-06-10 18:24:34 +0100220 CHECK(net);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100221
222 // Creates structures for input & output.
223 std::vector<T> inputData{
224 1, 2, 3,
225 4, 5, 6,
226 7, 8, 9,
227 10, 11, 12,
228 13, 14, 15,
229 16, 17, 18,
230 19, 20, 21,
231 22, 23, 24
232 };
233
234 std::vector<T> expectedOutput0{
235 1, 2, 3,
236 4, 5, 6,
237 7, 8, 9,
238 10, 11, 12
239 };
240 std::vector<T> expectedOutput1{
241 13, 14, 15,
242 16, 17, 18,
243 19, 20, 21,
244 22, 23, 24
245 };
246
247 std::map<int, std::vector<T>> inputTensorData = { { 0, inputData } };
248 std::map<int, std::vector<T>> expectedOutputData = { { 0, expectedOutput0 },
249 { 1, expectedOutput1 } };
250
Mike Kellya9c32672023-12-04 17:23:09 +0000251 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100252}
253
254template<armnn::DataType ArmnnType>
255void Splitter3dDim1EndToEnd(const std::vector<BackendId>& backends)
256{
257 using namespace armnn;
258 using T = ResolveType<ArmnnType>;
259
260 unsigned int splitAxis = 1;
261 unsigned int numSplit = 2;
262 const TensorShape& inputShape = { 2, 4, 3 };
263 const std::vector<TensorShape> outputShapes{{ 2, 2, 3 }, { 2, 2, 3 }};
264
265 // Builds up the structure of the network
266 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
267
Sadik Armagan1625efc2021-06-10 18:24:34 +0100268 CHECK(net);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100269
270 // Creates structures for input & output.
271 std::vector<T> inputData{
272 1, 2, 3,
273 4, 5, 6,
274 7, 8, 9,
275 10, 11, 12,
276 13, 14, 15,
277 16, 17, 18,
278 19, 20, 21,
279 22, 23, 24
280 };
281
282 std::vector<T> expectedOutput0{
283 1, 2, 3,
284 4, 5, 6,
285 13, 14, 15,
286 16, 17, 18
287 };
288 std::vector<T> expectedOutput1{
289 7, 8, 9,
290 10, 11, 12,
291 19, 20, 21,
292 22, 23, 24
293 };
294
295 std::map<int, std::vector<T>> inputTensorData = { { 0, inputData } };
296 std::map<int, std::vector<T>> expectedOutputData = { { 0, expectedOutput0 },
297 { 1, expectedOutput1 } };
298
Mike Kellya9c32672023-12-04 17:23:09 +0000299 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100300}
301
302template<armnn::DataType ArmnnType>
Kevin May1bea6be2023-12-12 11:18:46 +0000303void Splitter3dDim1EndToEndFloat16(const std::vector<BackendId>& backends)
304{
305 using namespace armnn;
306 using namespace half_float::literal;
307 using Half = half_float::half;
308
309 unsigned int splitAxis = 1;
310 unsigned int numSplit = 2;
311 const TensorShape& inputShape = { 2, 4, 3 };
312 const std::vector<TensorShape> outputShapes{{ 2, 2, 3 }, { 2, 2, 3 }};
313
314 // Builds up the structure of the network
315 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
316
317 CHECK(net);
318
319 // Creates structures for input & output.
320 std::vector<Half> inputData{
321 1._h, 2._h, 3._h,
322 4._h, 5._h, 6._h,
323 7._h, 8._h, 9._h,
324 10._h, 11._h, 12._h,
325 13._h, 14._h, 15._h,
326 16._h, 17._h, 18._h,
327 19._h, 20._h, 21._h,
328 22._h, 23._h, 24._h
329 };
330
331 std::vector<Half> expectedOutput0{
332 1._h, 2._h, 3._h,
333 4._h, 5._h, 6._h,
334 13._h, 14._h, 15._h,
335 16._h, 17._h, 18._h
336 };
337 std::vector<Half> expectedOutput1{
338 7._h, 8._h, 9._h,
339 10._h, 11._h, 12._h,
340 19._h, 20._h, 21._h,
341 22._h, 23._h, 24._h
342 };
343
344 std::map<int, std::vector<Half>> inputTensorData = { { 0, inputData } };
345 std::map<int, std::vector<Half>> expectedOutputData = { { 0, expectedOutput0 },
346 { 1, expectedOutput1 } };
347
348 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
349}
350
351template<armnn::DataType ArmnnType>
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100352void Splitter3dDim2EndToEnd(const std::vector<BackendId>& backends)
353{
354 using namespace armnn;
355 using T = ResolveType<ArmnnType>;
356
357 unsigned int splitAxis = 2;
358 unsigned int numSplit = 3;
359 const TensorShape& inputShape = { 2, 4, 3 };
360 const std::vector<TensorShape> outputShapes{{ 2, 4, 1 }, { 2, 4, 1 }, { 2, 4, 1 }};
361
362 // Builds up the structure of the network
363 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
364
Sadik Armagan1625efc2021-06-10 18:24:34 +0100365 CHECK(net);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100366
367 // Creates structures for input & output.
368 std::vector<T> inputData{
369 1, 2, 3,
370 4, 5, 6,
371 7, 8, 9,
372 10, 11, 12,
373 13, 14, 15,
374 16, 17, 18,
375 19, 20, 21,
376 22, 23, 24
377 };
378
379 std::vector<T> expectedOutput0{ 1, 4, 7, 10, 13, 16, 19, 22 };
380 std::vector<T> expectedOutput1{ 2, 5, 8, 11, 14, 17, 20, 23 };
381 std::vector<T> expectedOutput2{ 3, 6, 9, 12, 15, 18, 21, 24 };
382
383 std::map<int, std::vector<T>> inputTensorData = { { 0, inputData } };
384 std::map<int, std::vector<T>> expectedOutputData = { { 0, expectedOutput0 },
385 { 1, expectedOutput1 },
386 { 2, expectedOutput2 } };
387
Mike Kellya9c32672023-12-04 17:23:09 +0000388 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100389}
390
391template<armnn::DataType ArmnnType>
392void Splitter4dDim0EndToEnd(const std::vector<BackendId>& backends)
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100393{
394 using namespace armnn;
395 using T = ResolveType<ArmnnType>;
396
397 unsigned int splitAxis = 0;
398 unsigned int numSplit = 2;
399 const TensorShape& inputShape = { 4, 3, 2, 2 };
400 const std::vector<TensorShape> outputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }};
401
402 // Builds up the structure of the network
403 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
404
Sadik Armagan1625efc2021-06-10 18:24:34 +0100405 CHECK(net);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100406
407 // Creates structures for input & output.
408 std::vector<T> inputData{
409 1, 2,
410 3, 4,
411 5, 6,
412 7, 8,
413 9, 10,
414 11, 12,
415 13, 14,
416 15, 16,
417 17, 18,
418 19, 20,
419 21, 22,
420 23, 24,
421 25, 26,
422 27, 28,
423 29, 30,
424 31, 32,
425 33, 34,
426 35, 36,
427 37, 38,
428 39, 40,
429 41, 42,
430 43, 44,
431 45, 46,
432 47, 48
433 };
434
435 std::vector<T> expectedOutput0{
436 1, 2,
437 3, 4,
438 5, 6,
439 7, 8,
440 9, 10,
441 11, 12,
442 13, 14,
443 15, 16,
444 17, 18,
445 19, 20,
446 21, 22,
447 23, 24
448 };
449
450 std::vector<T> expectedOutput1{
451 25, 26,
452 27, 28,
453 29, 30,
454 31, 32,
455 33, 34,
456 35, 36,
457 37, 38,
458 39, 40,
459 41, 42,
460 43, 44,
461 45, 46,
462 47, 48
463 };
464
465 std::map<int, std::vector<T>> inputTensorData = {{ 0,inputData }};
466 std::map<int, std::vector<T>> expectedOutputData = {{ 0, expectedOutput0 }, { 1, expectedOutput1 }};
467
Mike Kellya9c32672023-12-04 17:23:09 +0000468 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100469}
470
471template<armnn::DataType ArmnnType>
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100472void Splitter4dDim1EndToEnd(const std::vector<BackendId>& backends)
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100473{
474 using namespace armnn;
475 using T = ResolveType<ArmnnType>;
476
477 unsigned int splitAxis = 1;
478 unsigned int numSplit = 2;
479 const TensorShape& inputShape = { 2, 6, 2, 2 };
480 const std::vector<TensorShape> outputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }};
481
482 // Builds up the structure of the network
483 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
484
Sadik Armagan1625efc2021-06-10 18:24:34 +0100485 CHECK(net);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100486
487 // Creates structures for input & output.
488 std::vector<T> inputData{
489 1, 2,
490 3, 4,
491 5, 6,
492 7, 8,
493 9, 10,
494 11, 12,
495 13, 14,
496 15, 16,
497 17, 18,
498 19, 20,
499 21, 22,
500 23, 24,
501 25, 26,
502 27, 28,
503 29, 30,
504 31, 32,
505 33, 34,
506 35, 36,
507 37, 38,
508 39, 40,
509 41, 42,
510 43, 44,
511 45, 46,
512 47, 48
513 };
514
515 std::vector<T> expectedOutput0{
516 1, 2,
517 3, 4,
518 5, 6,
519 7, 8,
520 9, 10,
521 11, 12,
522 25, 26,
523 27, 28,
524 29, 30,
525 31, 32,
526 33, 34,
527 35, 36
528 };
529
530 std::vector<T> expectedOutput1{
531 13, 14,
532 15, 16,
533 17, 18,
534 19, 20,
535 21, 22,
536 23, 24,
537 37, 38,
538 39, 40,
539 41, 42,
540 43, 44,
541 45, 46,
542 47, 48
543 };
544
545 std::map<int, std::vector<T>> inputTensorData = {{ 0,inputData }};
546 std::map<int, std::vector<T>> expectedOutputData = {{ 0, expectedOutput0 }, { 1, expectedOutput1 }};
547
Mike Kellya9c32672023-12-04 17:23:09 +0000548 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100549}
550
551template<armnn::DataType ArmnnType>
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100552void Splitter4dDim2EndToEnd(const std::vector<BackendId>& backends)
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100553{
554 using namespace armnn;
555 using T = ResolveType<ArmnnType>;
556
557 unsigned int splitAxis = 2;
558 unsigned int numSplit = 2;
559 const TensorShape& inputShape = { 2, 3, 4, 2 };
560 const std::vector<TensorShape> outputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }};
561
562 // Builds up the structure of the network
563 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
564
Sadik Armagan1625efc2021-06-10 18:24:34 +0100565 CHECK(net);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100566
567 // Creates structures for input & output.
568 std::vector<T> inputData{
569 1, 2,
570 3, 4,
571 5, 6,
572 7, 8,
573 9, 10,
574 11, 12,
575 13, 14,
576 15, 16,
577 17, 18,
578 19, 20,
579 21, 22,
580 23, 24,
581 25, 26,
582 27, 28,
583 29, 30,
584 31, 32,
585 33, 34,
586 35, 36,
587 37, 38,
588 39, 40,
589 41, 42,
590 43, 44,
591 45, 46,
592 47, 48
593 };
594
595 std::vector<T> expectedOutput0{
596 1, 2,
597 3, 4,
598 9, 10,
599 11, 12,
600 17, 18,
601 19, 20,
602 25, 26,
603 27, 28,
604 33, 34,
605 35, 36,
606 41, 42,
607 43, 44
608 };
609
610 std::vector<T> expectedOutput1{
611 5, 6,
612 7, 8,
613 13, 14,
614 15, 16,
615 21, 22,
616 23, 24,
617 29, 30,
618 31, 32,
619 37, 38,
620 39, 40,
621 45, 46,
622 47, 48
623 };
624
625 std::map<int, std::vector<T>> inputTensorData = {{ 0,inputData }};
626 std::map<int, std::vector<T>> expectedOutputData = {{ 0, expectedOutput0 }, { 1, expectedOutput1 }};
627
Mike Kellya9c32672023-12-04 17:23:09 +0000628 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100629}
630
Kevin May1bea6be2023-12-12 11:18:46 +0000631template<armnn::DataType ArmnnType>
632void Splitter4dDim2EndToEndFloat16(const std::vector<BackendId>& backends)
633{
634 using namespace armnn;
635 using namespace half_float::literal;
636 using Half = half_float::half;
637
638 unsigned int splitAxis = 2;
639 unsigned int numSplit = 2;
640 const TensorShape& inputShape = { 2, 3, 4, 2 };
641 const std::vector<TensorShape> outputShapes{{ 2, 3, 2, 2 }, { 2, 3, 2, 2 }};
642
643 // Builds up the structure of the network
644 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
645
646 CHECK(net);
647
648 // Creates structures for input & output.
649 std::vector<Half> inputData{
650 1._h, 2._h,
651 3._h, 4._h,
652 5._h, 6._h,
653 7._h, 8._h,
654 9._h, 10._h,
655 11._h, 12._h,
656 13._h, 14._h,
657 15._h, 16._h,
658 17._h, 18._h,
659 19._h, 20._h,
660 21._h, 22._h,
661 23._h, 24._h,
662 25._h, 26._h,
663 27._h, 28._h,
664 29._h, 30._h,
665 31._h, 32._h,
666 33._h, 34._h,
667 35._h, 36._h,
668 37._h, 38._h,
669 39._h, 40._h,
670 41._h, 42._h,
671 43._h, 44._h,
672 45._h, 46._h,
673 47._h, 48._h
674 };
675
676 std::vector<Half> expectedOutput0{
677 1._h, 2._h,
678 3._h, 4._h,
679 9._h, 10._h,
680 11._h, 12._h,
681 17._h, 18._h,
682 19._h, 20._h,
683 25._h, 26._h,
684 27._h, 28._h,
685 33._h, 34._h,
686 35._h, 36._h,
687 41._h, 42._h,
688 43._h, 44._h
689 };
690
691 std::vector<Half> expectedOutput1{
692 5._h, 6._h,
693 7._h, 8._h,
694 13._h, 14._h,
695 15._h, 16._h,
696 21._h, 22._h,
697 23._h, 24._h,
698 29._h, 30._h,
699 31._h, 32._h,
700 37._h, 38._h,
701 39._h, 40._h,
702 45._h, 46._h,
703 47._h, 48._h
704 };
705
706 std::map<int, std::vector<Half>> inputTensorData = {{ 0,inputData }};
707 std::map<int, std::vector<Half>> expectedOutputData = {{ 0, expectedOutput0 }, { 1, expectedOutput1 }};
708
709 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
710}
711
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100712template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
Narumol Prangnawarat0f072ab2019-05-29 14:12:46 +0100713void Splitter4dDim3EndToEnd(const std::vector<BackendId>& backends)
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100714{
715 using namespace armnn;
716
717 unsigned int splitAxis = 3;
718 unsigned int numSplit = 2;
719 const TensorShape& inputShape = { 2, 3, 4, 2 };
720 const std::vector<TensorShape> outputShapes{{ 2, 3, 4, 1 }, { 2, 3, 4, 1 }};
721
722 // Builds up the structure of the network
723 INetworkPtr net = CreateSplitterNetwork<ArmnnType>(inputShape, outputShapes, splitAxis, numSplit);
724
Sadik Armagan1625efc2021-06-10 18:24:34 +0100725 CHECK(net);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100726
727 // Creates structures for input & output.
728 std::vector<T> inputData{
729 1, 2,
730 3, 4,
731 5, 6,
732 7, 8,
733 9, 10,
734 11, 12,
735 13, 14,
736 15, 16,
737 17, 18,
738 19, 20,
739 21, 22,
740 23, 24,
741 25, 26,
742 27, 28,
743 29, 30,
744 31, 32,
745 33, 34,
746 35, 36,
747 37, 38,
748 39, 40,
749 41, 42,
750 43, 44,
751 45, 46,
752 47, 48
753 };
754
755 std::vector<T> expectedOutput0{
756 1, 3, 5, 7,
757 9, 11, 13, 15,
758 17, 19, 21, 23,
759 25, 27, 29, 31,
760 33, 35, 37, 39,
761 41, 43, 45, 47
762 };
763
764 std::vector<T> expectedOutput1{
765 2, 4, 6, 8,
766 10, 12, 14, 16,
767 18, 20, 22, 24,
768 26, 28, 30, 32,
769 34, 36, 38, 40,
770 42, 44, 46, 48
771 };
772
773 std::map<int, std::vector<T>> inputTensorData = {{ 0,inputData }};
774 std::map<int, std::vector<T>> expectedOutputData = {{ 0, expectedOutput0 }, { 1, expectedOutput1 }};
775
Mike Kellya9c32672023-12-04 17:23:09 +0000776 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(net), inputTensorData, expectedOutputData, backends);
Narumol Prangnawarat0be43382019-05-27 11:29:59 +0100777}
778
779} // anonymous namespace