blob: 802efc23f0353f686fc5340f423951d33a749ee9 [file] [log] [blame]
Kevin May93bbf002024-03-11 09:31:10 +00001//
2// Copyright © 2024 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ScatterNdTestHelper.hpp"
7
8#include <doctest/doctest.h>
9
10namespace armnnDelegate
11{
12
13template <typename T>
14void ScatterNd1DimTest(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
15{
16 // Set shapes
17 std::vector<int32_t> indicesShape = { 3, 1 };
18 std::vector<int32_t> updatesShape = { 3 };
19 std::vector<int32_t> shapeShape = { 1 };
20 std::vector<int32_t> expectedOutputShape = { 5 };
21
22 // Set Values
23 std::vector<int32_t> indicesValues = { 0, 1, 2 };
24 std::vector<T> updatesValues = { 1, 2, 3 };
25 std::vector<int32_t> shapeValue = { 5 };
26 std::vector<T> expectedOutputValues = { 1, 2, 3, 0, 0 };
27
28 ScatterNdTestImpl<T>(tensorType,
29 indicesShape,
30 indicesValues,
31 updatesShape,
32 updatesValues,
33 shapeShape,
34 shapeValue,
35 expectedOutputShape,
36 expectedOutputValues,
37 backends);
38}
39
40template <typename T>
41void ScatterNd2DimTest(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
42{
43 // Set shapes
44 std::vector<int32_t> indicesShape = { 3, 2 };
45 std::vector<int32_t> updatesShape = { 3 };
46 std::vector<int32_t> shapeShape = { 2 };
47 std::vector<int32_t> expectedOutputShape = { 3, 3 };
48
49 // Set Values
50 std::vector<int32_t> indicesValues = { 0, 0,
51 1, 1,
52 2, 2 };
53 std::vector<T> updatesValues = { 1, 2, 3 };
54 std::vector<int32_t> shapeValue = { 3, 3 };
55 std::vector<T> expectedOutputValues = { 1, 0, 0,
56 0, 2, 0,
57 0, 0, 3 };
58
59 ScatterNdTestImpl<T>(tensorType,
60 indicesShape,
61 indicesValues,
62 updatesShape,
63 updatesValues,
64 shapeShape,
65 shapeValue,
66 expectedOutputShape,
67 expectedOutputValues,
68 backends);
69}
70
71template <typename T>
72void ScatterNd2Dim1Outter1InnerTest(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
73{
74 // Set shapes
75 std::vector<int32_t> indicesShape = { 2, 1 };
76 std::vector<int32_t> updatesShape = { 2, 3 };
77 std::vector<int32_t> shapeShape = { 2 };
78 std::vector<int32_t> expectedOutputShape = { 3, 3 };
79
80 // Set Values
81 std::vector<int32_t> indicesValues = { 0, 1 };
82 std::vector<T> updatesValues = { 1, 1, 1,
83 1, 1, 1 };
84 std::vector<int32_t> shapeValue = { 3, 3 };
85 std::vector<T> expectedOutputValues = { 1, 1, 1,
86 1, 1, 1,
87 0, 0, 0 };
88
89 ScatterNdTestImpl<T>(tensorType,
90 indicesShape,
91 indicesValues,
92 updatesShape,
93 updatesValues,
94 shapeShape,
95 shapeValue,
96 expectedOutputShape,
97 expectedOutputValues,
98 backends);
99}
100
101template <typename T>
102void ScatterNd3DimTest(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
103{
104 // Set shapes
105 std::vector<int32_t> indicesShape = { 3, 3 };
106 std::vector<int32_t> updatesShape = { 3 };
107 std::vector<int32_t> shapeShape = { 3 };
108 std::vector<int32_t> expectedOutputShape = { 3, 3, 3 };
109
110 // Set Values
111 std::vector<int32_t> indicesValues = { 0, 0, 0,
112 1, 1, 1,
113 2, 2, 2 };
114 std::vector<T> updatesValues = { 1, 2, 3 };
115 std::vector<int32_t> shapeValue = { 3, 3, 3 };
116 std::vector<T> expectedOutputValues = { 1, 0, 0,
117 0, 0, 0,
118 0, 0, 0,
119
120 0, 0, 0,
121 0, 2, 0,
122 0, 0, 0,
123
124 0, 0, 0,
125 0, 0, 0,
126 0, 0, 3 };
127
128 ScatterNdTestImpl<T>(tensorType,
129 indicesShape,
130 indicesValues,
131 updatesShape,
132 updatesValues,
133 shapeShape,
134 shapeValue,
135 expectedOutputShape,
136 expectedOutputValues,
137 backends);
138}
139
140template <typename T>
141void ScatterNd3Dim1Outter2InnerTest(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
142{
143 // Set shapes
144 std::vector<int32_t> indicesShape = { 2, 1 };
145 std::vector<int32_t> updatesShape = { 2, 3, 3 };
146 std::vector<int32_t> shapeShape = { 3 };
147 std::vector<int32_t> expectedOutputShape = { 3, 3, 3 };
148
149 // Set Values
150 std::vector<int32_t> indicesValues = { 0, 1 };
151 std::vector<T> updatesValues = { 1, 1, 1,
152 1, 1, 1,
153 1, 1, 1,
154
155 2, 2, 2,
156 2, 2, 2,
157 2, 2, 2 };
158 std::vector<int32_t> shapeValue = { 3, 3, 3 };
159 std::vector<T> expectedOutputValues = { 1, 1, 1,
160 1, 1, 1,
161 1, 1, 1,
162
163 2, 2, 2,
164 2, 2, 2,
165 2, 2, 2,
166
167 0, 0, 0,
168 0, 0, 0,
169 0, 0, 0 };
170
171 ScatterNdTestImpl<T>(tensorType,
172 indicesShape,
173 indicesValues,
174 updatesShape,
175 updatesValues,
176 shapeShape,
177 shapeValue,
178 expectedOutputShape,
179 expectedOutputValues,
180 backends);
181}
182
183template <typename T>
184void ScatterNd3Dim2Outter1InnerTest(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
185{
186 // Set shapes
187 std::vector<int32_t> indicesShape = { 2, 2 };
188 std::vector<int32_t> updatesShape = { 2, 3 };
189 std::vector<int32_t> shapeShape = { 3 };
190 std::vector<int32_t> expectedOutputShape = { 3, 3, 3 };
191
192 // Set Values
193 std::vector<int32_t> indicesValues = { 0, 0,
194 1, 1 };
195 std::vector<T> updatesValues = { 1, 1, 1,
196 2, 2, 2 };
197 std::vector<int32_t> shapeValue = { 3, 3, 3 };
198 std::vector<T> expectedOutputValues = { 1, 1, 1,
199 0, 0, 0,
200 0, 0, 0,
201
202 0, 0, 0,
203 2, 2, 2,
204 0, 0, 0,
205
206 0, 0, 0,
207 0, 0, 0,
208 0, 0, 0 };
209
210 ScatterNdTestImpl<T>(tensorType,
211 indicesShape,
212 indicesValues,
213 updatesShape,
214 updatesValues,
215 shapeShape,
216 shapeValue,
217 expectedOutputShape,
218 expectedOutputValues,
219 backends);
220}
221
222template <typename T>
223void ScatterNdDim4(tflite::TensorType tensorType, const std::vector<armnn::BackendId>& backends = {})
224{
225 // Set shapes
226 std::vector<int32_t> indicesShape = { 3, 4 };
227 std::vector<int32_t> updatesShape = { 3 };
228 std::vector<int32_t> shapeShape = { 4 };
229 std::vector<int32_t> expectedOutputShape = { 2, 3, 3, 3 };
230
231 // Set Values
232 std::vector<int32_t> indicesValues = { 0, 0, 0, 0,
233 0, 1, 1, 1,
234 1, 1, 1, 1 };
235 std::vector<T> updatesValues = { 1, 2, 3 };
236 std::vector<int32_t> shapeValue = { 2, 3, 3, 3 };
237 std::vector<T> expectedOutputValues = { 1, 0, 0,
238 0, 0, 0,
239 0, 0, 0,
240
241 0, 0, 0,
242 0, 2, 0,
243 0, 0, 0,
244
245 0, 0, 0,
246 0, 0, 0,
247 0, 0, 0,
248
249 0, 0, 0,
250 0, 0, 0,
251 0, 0, 0,
252
253 0, 0, 0,
254 0, 3, 0,
255 0, 0, 0,
256
257 0, 0, 0,
258 0, 0, 0,
259 0, 0, 0 };
260
261 ScatterNdTestImpl<T>(tensorType,
262 indicesShape,
263 indicesValues,
264 updatesShape,
265 updatesValues,
266 shapeShape,
267 shapeValue,
268 expectedOutputShape,
269 expectedOutputValues,
270 backends);
271}
272
273TEST_SUITE("ScatterNdDelegateTests")
274{
275
276TEST_CASE ("ScatterNd_1Dim_FP32_Test")
277{
Teresa Charlin21bda142024-03-13 16:10:32 +0000278 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000279 ScatterNd1DimTest<float>(tflite::TensorType_FLOAT32, backends);
280}
281
282TEST_CASE ("ScatterNd_1Dim_INT32_Test")
283{
Teresa Charlin21bda142024-03-13 16:10:32 +0000284 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000285 ScatterNd1DimTest<int32_t>(tflite::TensorType_INT32, backends);
286}
287
288TEST_CASE ("ScatterNd_1Dim_INT8_Test")
289{
290 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
291 ScatterNd1DimTest<int8_t>(tflite::TensorType_INT8, backends);
292}
293
294TEST_CASE ("ScatterNd_1Dim_UINT8_Test")
295{
296 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
297 ScatterNd1DimTest<uint8_t>(tflite::TensorType_UINT8, backends);
298}
299
300TEST_CASE ("ScatterNd_2Dim_FP32_Test")
301{
Teresa Charlin21bda142024-03-13 16:10:32 +0000302 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000303 ScatterNd2DimTest<float>(tflite::TensorType_FLOAT32, backends);
304}
305
306TEST_CASE ("ScatterNd_2Dim_INT32_Test")
307{
Teresa Charlin21bda142024-03-13 16:10:32 +0000308 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000309 ScatterNd2DimTest<int32_t>(tflite::TensorType_INT32, backends);
310}
311
312TEST_CASE ("ScatterNd_2Dim_INT8_Test")
313{
314 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
315 ScatterNd2DimTest<int8_t>(tflite::TensorType_INT8, backends);
316}
317
318TEST_CASE ("ScatterNd_2Dim_UINT8_Test")
319{
320 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
321 ScatterNd2DimTest<uint8_t>(tflite::TensorType_UINT8, backends);
322}
323
324TEST_CASE ("ScatterNd_2Dim_1Outter_1Inner_FP32_Test")
325{
Teresa Charlin21bda142024-03-13 16:10:32 +0000326 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000327 ScatterNd2Dim1Outter1InnerTest<float>(tflite::TensorType_FLOAT32, backends);
328}
329
330TEST_CASE ("ScatterNd_2Dim_1Outter_1Inner_INT32_Test")
331{
Teresa Charlin21bda142024-03-13 16:10:32 +0000332 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000333 ScatterNd2Dim1Outter1InnerTest<int32_t>(tflite::TensorType_INT32, backends);
334}
335
336TEST_CASE ("ScatterNd_2Dim_1Outter_1Inner_INT8_Test")
337{
338 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
339 ScatterNd2Dim1Outter1InnerTest<int8_t>(tflite::TensorType_INT8, backends);
340}
341
342TEST_CASE ("ScatterNd_2Dim_1Outter_1Inner_UINT8_Test")
343{
344 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
345 ScatterNd2Dim1Outter1InnerTest<uint8_t>(tflite::TensorType_UINT8, backends);
346}
347
348TEST_CASE ("ScatterNd_3Dim_FP32_Test")
349{
Teresa Charlin21bda142024-03-13 16:10:32 +0000350 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000351 ScatterNd3DimTest<float>(tflite::TensorType_FLOAT32, backends);
352}
353
354TEST_CASE ("ScatterNd_3Dim_INT32_Test")
355{
Teresa Charlin21bda142024-03-13 16:10:32 +0000356 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000357 ScatterNd3DimTest<int32_t>(tflite::TensorType_INT32, backends);
358}
359
360TEST_CASE ("ScatterNd_3Dim_INT8_Test")
361{
362 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
363 ScatterNd3DimTest<int8_t>(tflite::TensorType_INT8, backends);
364}
365
366TEST_CASE ("ScatterNd_3Dim_UINT8_Test")
367{
368 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
369 ScatterNd3DimTest<uint8_t>(tflite::TensorType_UINT8, backends);
370}
371
372TEST_CASE ("ScatterNd_3Dim_1Outter_2Inner_FP32_Test")
373{
Teresa Charlin21bda142024-03-13 16:10:32 +0000374 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000375 ScatterNd3Dim1Outter2InnerTest<float>(tflite::TensorType_FLOAT32, backends);
376}
377
378TEST_CASE ("ScatterNd_3Dim_1Outter_2Inner_INT32_Test")
379{
Teresa Charlin21bda142024-03-13 16:10:32 +0000380 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000381 ScatterNd3Dim1Outter2InnerTest<int32_t>(tflite::TensorType_INT32, backends);
382}
383
384TEST_CASE ("ScatterNd_3Dim_1Outter_2Inner_INT8_Test")
385{
386 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
387 ScatterNd3Dim1Outter2InnerTest<int8_t>(tflite::TensorType_INT8, backends);
388}
389
390TEST_CASE ("ScatterNd_3Dim_1Outter_2Inner_UINT8_Test")
391{
392 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
393 ScatterNd3Dim1Outter2InnerTest<uint8_t>(tflite::TensorType_UINT8, backends);
394}
395
396TEST_CASE ("ScatterNd_3Dim_2Outter_1Inner_FP32_Test")
397{
Teresa Charlin21bda142024-03-13 16:10:32 +0000398 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000399 ScatterNd3Dim2Outter1InnerTest<float>(tflite::TensorType_FLOAT32, backends);
400}
401
402TEST_CASE ("ScatterNd_3Dim_2Outter_1Inner_INT32_Test")
403{
Teresa Charlin21bda142024-03-13 16:10:32 +0000404 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000405 ScatterNd3Dim2Outter1InnerTest<int32_t>(tflite::TensorType_INT32, backends);
406}
407
408TEST_CASE ("ScatterNd_3Dim_2Outter_1Inner_INT8_Test")
409{
410 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
411 ScatterNd3Dim2Outter1InnerTest<int8_t>(tflite::TensorType_INT8, backends);
412}
413
414TEST_CASE ("ScatterNd_3Dim_2Outter_1Inner_UINT8_Test")
415{
416 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
417 ScatterNd3Dim2Outter1InnerTest<uint8_t>(tflite::TensorType_UINT8, backends);
418}
419
420TEST_CASE ("ScatterNd_4Dim_FP32_Test")
421{
Teresa Charlin21bda142024-03-13 16:10:32 +0000422 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000423 ScatterNdDim4<float>(tflite::TensorType_FLOAT32, backends);
424}
425
426TEST_CASE ("ScatterNd_4Dim_INT32_Test")
427{
Teresa Charlin21bda142024-03-13 16:10:32 +0000428 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef, armnn::Compute::GpuAcc };
Kevin May93bbf002024-03-11 09:31:10 +0000429 ScatterNdDim4<int32_t>(tflite::TensorType_INT32, backends);
430}
431
432TEST_CASE ("ScatterNd_4Dim_INT8_Test")
433{
434 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
435 ScatterNdDim4<int8_t>(tflite::TensorType_INT8, backends);
436}
437
438TEST_CASE ("ScatterNd_4Dim_UINT8_Test")
439{
440 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
441 ScatterNdDim4<uint8_t>(tflite::TensorType_UINT8, backends);
442}
443
444} // TEST_SUITE("ScatterNdDelegateTests")
445
446} // namespace armnnDelegate