Publishing 2019 R3 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / tests / test_cases / reduce_gpu_test.cpp
1 /*
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include <gtest/gtest.h>
19 #include <api/input_layout.hpp>
20 #include "api/reduce.hpp"
21 #include <api/topology.hpp>
22 #include <api/network.hpp>
23 #include <api/engine.hpp>
24 #include "test_utils/test_utils.h"
25 #include <api/data.hpp>
26 #include "test_utils/float16.h"
27
28 using namespace cldnn;
29 using namespace tests;
30
31 TEST(reduce_gpu, common_bfyx) {
32     const auto& engine = get_test_engine();
33     auto input = memory::allocate(engine, {data_types::f32, format::bfyx, {1, 1, 1, 1}});
34
35     set_values(input, {1.0f});
36
37     topology topology;
38     topology.add(input_layout("input", input.get_layout()));
39     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_b}, 0));
40
41     network network(engine, topology);
42
43     network.set_input_data("input", input);
44
45     auto outputs = network.execute();
46
47     EXPECT_EQ(outputs.size(), size_t(1));
48     EXPECT_EQ(outputs.begin()->first, "reduce");
49
50     auto output = outputs.at("reduce").get_memory();
51
52     std::vector<float> ref_data = {1.0f};
53
54     auto output_ptr = output.pointer<float>();
55
56     for (size_t i = 0; i < ref_data.size(); ++i) {
57         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
58     }
59 }
60
61 TEST(reduce_gpu, common_bfyx_keepdims) {
62     const auto& engine = get_test_engine();
63     auto input = memory::allocate(engine, {data_types::f32, format::bfyx, {1, 3, 4, 1}});
64
65     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f});
66
67     topology topology;
68     topology.add(input_layout("input", input.get_layout()));
69     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_x, cldnn::reduce::along_y}, 1));
70
71     network network(engine, topology);
72
73     network.set_input_data("input", input);
74
75     auto outputs = network.execute();
76
77     EXPECT_EQ(outputs.size(), size_t(1));
78     EXPECT_EQ(outputs.begin()->first, "reduce");
79
80     auto output = outputs.at("reduce").get_memory();
81
82     std::vector<float> ref_data = {6.0f, 22.0f, 38.0f};
83
84     auto output_ptr = output.pointer<float>();
85
86     for (size_t i = 0; i < ref_data.size(); ++i) {
87         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
88     }
89 }
90
91 TEST(reduce_gpu, regr_bfyx_keepdims) {
92     const auto& engine = get_test_engine();
93     auto input = memory::allocate(engine, { data_types::f32, format::bfyx, {1, 3, 2, 2} });
94
95     set_values(input, { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f });
96
97     topology topology;
98     topology.add(input_layout("input", input.get_layout()));
99     topology.add(reduce("reduce", "input", reduce_mode::sum, { cldnn::reduce::along_b, cldnn::reduce::along_x }, 1));
100
101     network network(engine, topology);
102
103     network.set_input_data("input", input);
104
105     auto outputs = network.execute();
106
107     EXPECT_EQ(outputs.size(), size_t(1));
108     EXPECT_EQ(outputs.begin()->first, "reduce");
109
110     auto output = outputs.at("reduce").get_memory();
111
112     std::vector<float> ref_data = { 1.0f, 5.0f, 9.0f, 13.0f, 17.0f, 21.0f };
113
114     auto output_ptr = output.pointer<float>();
115
116     for (size_t i = 0; i < ref_data.size(); ++i) {
117         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
118     }
119 }
120
121 TEST(reduce_gpu, common_bfzyx) {
122     const auto& engine = get_test_engine();
123     auto input = memory::allocate(engine, {data_types::f32, format::bfzyx, {1, 1, 1, 1, 1}});
124
125     set_values(input, {1.0f});
126
127     topology topology;
128     topology.add(input_layout("input", input.get_layout()));
129     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_b}, 0));
130
131     network network(engine, topology);
132
133     network.set_input_data("input", input);
134
135     auto outputs = network.execute();
136
137     EXPECT_EQ(outputs.size(), size_t(1));
138     EXPECT_EQ(outputs.begin()->first, "reduce");
139
140     auto output = outputs.at("reduce").get_memory();
141
142     std::vector<float> ref_data = {1.0f};
143
144     auto output_ptr = output.pointer<float>();
145
146     for (size_t i = 0; i < ref_data.size(); ++i) {
147         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
148     }
149 }
150
151 TEST(reduce_gpu, common_bfzyx_keepdims) {
152     const auto& engine = get_test_engine();
153     auto input = memory::allocate(engine, {data_types::f32, format::bfzyx, {1, 1, 1, 1, 1}});
154
155     set_values(input, {1.0f});
156
157     topology topology;
158     topology.add(input_layout("input", input.get_layout()));
159     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_b}, 1));
160
161     network network(engine, topology);
162
163     network.set_input_data("input", input);
164
165     auto outputs = network.execute();
166
167     EXPECT_EQ(outputs.size(), size_t(1));
168     EXPECT_EQ(outputs.begin()->first, "reduce");
169
170     auto output = outputs.at("reduce").get_memory();
171
172     std::vector<float> ref_data = {1.0f};
173
174     auto output_ptr = output.pointer<float>();
175
176     for (size_t i = 0; i < ref_data.size(); ++i) {
177         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
178     }
179 }
180
181 TEST(reduce_gpu, common_bfwzyx) {
182     const auto& engine = get_test_engine();
183     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, tensor(format::bfwzyx, {1, 3, 4, 1, 1, 1})});
184
185     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f});
186
187     topology topology;
188     topology.add(input_layout("input", input.get_layout()));
189     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_w, cldnn::reduce::along_z, cldnn::reduce::along_y, cldnn::reduce::along_x}, 0));
190
191     network network(engine, topology);
192
193     network.set_input_data("input", input);
194
195     auto outputs = network.execute();
196
197     EXPECT_EQ(outputs.size(), size_t(1));
198     EXPECT_EQ(outputs.begin()->first, "reduce");
199
200     auto output = outputs.at("reduce").get_memory();
201
202     std::vector<float> ref_data = {6.0f, 22.0f, 38.0f};
203
204     auto output_ptr = output.pointer<float>();
205
206     for (size_t i = 0; i < ref_data.size(); ++i) {
207         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
208     }
209 }
210
211 TEST(reduce_gpu, common_bfwzyx_keepdims) {
212     const auto& engine = get_test_engine();
213     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, tensor(format::bfwzyx, {1, 3, 4, 1, 1, 1})});
214
215     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f});
216
217     topology topology;
218     topology.add(input_layout("input", input.get_layout()));
219     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_f, cldnn::reduce::along_w, cldnn::reduce::along_z}, 1));
220
221     network network(engine, topology);
222
223     network.set_input_data("input", input);
224
225     auto outputs = network.execute();
226
227     EXPECT_EQ(outputs.size(), size_t(1));
228     EXPECT_EQ(outputs.begin()->first, "reduce");
229
230     auto output = outputs.at("reduce").get_memory();
231
232     std::vector<float> ref_data = {66.0f};
233
234     auto output_ptr = output.pointer<float>();
235
236     for (size_t i = 0; i < ref_data.size(); ++i) {
237         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
238     }
239 }
240
241 TEST(reduce_gpu, common_bfwzyx_max_keepdims) {
242     const auto& engine = get_test_engine();
243     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 4, 1, 1, 1}});
244
245     set_values(input, {0.0f,  1.0f,  2.0f,  3.0f,  4.0f,  5.0f,  6.0f,  7.0f,  8.0f,  9.0f,  10.0f, 11.0f,
246                        12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f});
247
248     topology topology;
249     topology.add(input_layout("input", input.get_layout()));
250     topology.add(reduce("reduce", "input", reduce_mode::max, {cldnn::reduce::along_b, cldnn::reduce::along_f}, 1));
251
252     network network(engine, topology);
253
254     network.set_input_data("input", input);
255
256     auto outputs = network.execute();
257
258     EXPECT_EQ(outputs.size(), size_t(1));
259     EXPECT_EQ(outputs.begin()->first, "reduce");
260
261     auto output = outputs.at("reduce").get_memory();
262
263     std::vector<float> ref_data = {20.0f, 21.0f, 22.0f, 23.0f};
264
265     auto output_ptr = output.pointer<float>();
266
267     for (size_t i = 0; i < ref_data.size(); ++i) {
268         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
269     }
270 }
271
272 TEST(reduce_gpu, common_bfwzyx_min) {
273     const auto& engine = get_test_engine();
274     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
275
276     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
277
278     topology topology;
279     topology.add(input_layout("input", input.get_layout()));
280     topology.add(reduce("reduce", "input", reduce_mode::min, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
281
282     network network(engine, topology);
283
284     network.set_input_data("input", input);
285
286     auto outputs = network.execute();
287
288     EXPECT_EQ(outputs.size(), size_t(1));
289     EXPECT_EQ(outputs.begin()->first, "reduce");
290
291     auto output = outputs.at("reduce").get_memory();
292
293     std::vector<float> ref_data = {0.0f, 3.0f};
294
295     auto output_ptr = output.pointer<float>();
296
297     for (size_t i = 0; i < ref_data.size(); ++i) {
298         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
299     }
300 }
301
302 TEST(reduce_gpu, common_bfwzyx_min_keepdims) {
303     const auto& engine = get_test_engine();
304     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
305
306     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
307
308     topology topology;
309     topology.add(input_layout("input", input.get_layout()));
310     topology.add(reduce("reduce", "input", reduce_mode::min, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
311
312     network network(engine, topology);
313
314     network.set_input_data("input", input);
315
316     auto outputs = network.execute();
317
318     EXPECT_EQ(outputs.size(), size_t(1));
319     EXPECT_EQ(outputs.begin()->first, "reduce");
320
321     auto output = outputs.at("reduce").get_memory();
322
323     std::vector<float> ref_data = {0.0f, 3.0f};
324
325     auto output_ptr = output.pointer<float>();
326
327     for (size_t i = 0; i < ref_data.size(); ++i) {
328         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
329     }
330 }
331
332 TEST(reduce_gpu, common_bfwzyx_mean) {
333     const auto& engine = get_test_engine();
334     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
335
336     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
337
338     topology topology;
339     topology.add(input_layout("input", input.get_layout()));
340     topology.add(reduce("reduce", "input", reduce_mode::mean, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
341
342     network network(engine, topology);
343
344     network.set_input_data("input", input);
345
346     auto outputs = network.execute();
347
348     EXPECT_EQ(outputs.size(), size_t(1));
349     EXPECT_EQ(outputs.begin()->first, "reduce");
350
351     auto output = outputs.at("reduce").get_memory();
352
353     std::vector<float> ref_data = {1.0f, 4.0f};
354
355     auto output_ptr = output.pointer<float>();
356
357     for (size_t i = 0; i < ref_data.size(); ++i) {
358         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
359     }
360 }
361
362 TEST(reduce_gpu, common_bfwzyx_mean_keepdims) {
363     const auto& engine = get_test_engine();
364     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
365
366     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
367
368     topology topology;
369     topology.add(input_layout("input", input.get_layout()));
370     topology.add(reduce("reduce", "input", reduce_mode::mean, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
371
372     network network(engine, topology);
373
374     network.set_input_data("input", input);
375
376     auto outputs = network.execute();
377
378     EXPECT_EQ(outputs.size(), size_t(1));
379     EXPECT_EQ(outputs.begin()->first, "reduce");
380
381     auto output = outputs.at("reduce").get_memory();
382
383     std::vector<float> ref_data = {1.0f, 4.0f};
384
385     auto output_ptr = output.pointer<float>();
386
387     for (size_t i = 0; i < ref_data.size(); ++i) {
388         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
389     }
390 }
391
392 TEST(reduce_gpu, common_bfwzyx_prod) {
393     const auto& engine = get_test_engine();
394     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
395
396     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
397
398     topology topology;
399     topology.add(input_layout("input", input.get_layout()));
400     topology.add(reduce("reduce", "input", reduce_mode::prod, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
401
402     network network(engine, topology);
403
404     network.set_input_data("input", input);
405
406     auto outputs = network.execute();
407
408     EXPECT_EQ(outputs.size(), size_t(1));
409     EXPECT_EQ(outputs.begin()->first, "reduce");
410
411     auto output = outputs.at("reduce").get_memory();
412
413     std::vector<float> ref_data = {0.0f, 60.0f};
414
415     auto output_ptr = output.pointer<float>();
416
417     for (size_t i = 0; i < ref_data.size(); ++i) {
418         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
419     }
420 }
421
422 TEST(reduce_gpu, common_bfwzyx_prod_keepdims) {
423     const auto& engine = get_test_engine();
424     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
425
426     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
427
428     topology topology;
429     topology.add(input_layout("input", input.get_layout()));
430     topology.add(reduce("reduce", "input", reduce_mode::prod, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
431
432     network network(engine, topology);
433
434     network.set_input_data("input", input);
435
436     auto outputs = network.execute();
437
438     EXPECT_EQ(outputs.size(), size_t(1));
439     EXPECT_EQ(outputs.begin()->first, "reduce");
440
441     auto output = outputs.at("reduce").get_memory();
442
443     std::vector<float> ref_data = {0.0f, 60.0f};
444
445     auto output_ptr = output.pointer<float>();
446
447     for (size_t i = 0; i < ref_data.size(); ++i) {
448         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
449     }
450 }
451
452 TEST(reduce_gpu, common_bfwzyx_sum_keepdims) {
453     const auto& engine = get_test_engine();
454     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 4, 1, 1, 1}});
455
456     set_values(input, {0.0f,  1.0f,  2.0f,  3.0f,  4.0f,  5.0f,  6.0f,  7.0f,  8.0f,  9.0f,  10.0f, 11.0f,
457                        12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f});
458
459     topology topology;
460     topology.add(input_layout("input", input.get_layout()));
461     topology.add(reduce("reduce", "input", reduce_mode::sum, {cldnn::reduce::along_b, cldnn::reduce::along_f}, 1));
462
463     network network(engine, topology);
464
465     network.set_input_data("input", input);
466
467     auto outputs = network.execute();
468
469     EXPECT_EQ(outputs.size(), size_t(1));
470     EXPECT_EQ(outputs.begin()->first, "reduce");
471
472     auto output = outputs.at("reduce").get_memory();
473
474     std::vector<float> ref_data = {60.0f, 66.0f, 72.0f, 78.0f};
475
476     auto output_ptr = output.pointer<float>();
477
478     for (size_t i = 0; i < ref_data.size(); ++i) {
479         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
480     }
481 }
482
483 TEST(reduce_gpu, common_bfwzyx_logical_and) {
484     const auto& engine = get_test_engine();
485     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
486
487     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
488
489     topology topology;
490     topology.add(input_layout("input", input.get_layout()));
491     topology.add(reduce("reduce", "input", reduce_mode::logical_and, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
492
493     network network(engine, topology);
494
495     network.set_input_data("input", input);
496
497     auto outputs = network.execute();
498
499     EXPECT_EQ(outputs.size(), size_t(1));
500     EXPECT_EQ(outputs.begin()->first, "reduce");
501
502     auto output = outputs.at("reduce").get_memory();
503
504     std::vector<char> ref_data = {0, 1};
505
506     auto output_ptr = output.pointer<char>();
507
508     for (size_t i = 0; i < ref_data.size(); ++i) {
509         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
510     }
511 }
512
513 TEST(reduce_gpu, common_bfwzyx_logical_and_keepdims) {
514     const auto& engine = get_test_engine();
515     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
516
517     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
518
519     topology topology;
520     topology.add(input_layout("input", input.get_layout()));
521     topology.add(reduce("reduce", "input", reduce_mode::logical_and, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
522
523     network network(engine, topology);
524
525     network.set_input_data("input", input);
526
527     auto outputs = network.execute();
528
529     EXPECT_EQ(outputs.size(), size_t(1));
530     EXPECT_EQ(outputs.begin()->first, "reduce");
531
532     auto output = outputs.at("reduce").get_memory();
533
534     std::vector<char> ref_data = {0, 1};
535
536     auto output_ptr = output.pointer<char>();
537
538     for (size_t i = 0; i < ref_data.size(); ++i) {
539         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
540     }
541 }
542
543 TEST(reduce_gpu, common_bfwzyx_logical_or) {
544     const auto& engine = get_test_engine();
545     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
546
547     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
548
549     topology topology;
550     topology.add(input_layout("input", input.get_layout()));
551     topology.add(reduce("reduce", "input", reduce_mode::logical_or, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
552
553     network network(engine, topology);
554
555     network.set_input_data("input", input);
556
557     auto outputs = network.execute();
558
559     EXPECT_EQ(outputs.size(), size_t(1));
560     EXPECT_EQ(outputs.begin()->first, "reduce");
561
562     auto output = outputs.at("reduce").get_memory();
563
564     std::vector<char> ref_data = {1, 1};
565
566     auto output_ptr = output.pointer<char>();
567
568     for (size_t i = 0; i < ref_data.size(); ++i) {
569         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
570     }
571 }
572
573 TEST(reduce_gpu, common_bfwzyx_logical_or_keepdims) {
574     const auto& engine = get_test_engine();
575     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
576
577     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
578
579     topology topology;
580     topology.add(input_layout("input", input.get_layout()));
581     topology.add(reduce("reduce", "input", reduce_mode::logical_or, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
582
583     network network(engine, topology);
584
585     network.set_input_data("input", input);
586
587     auto outputs = network.execute();
588
589     EXPECT_EQ(outputs.size(), size_t(1));
590     EXPECT_EQ(outputs.begin()->first, "reduce");
591
592     auto output = outputs.at("reduce").get_memory();
593
594     std::vector<char> ref_data = {1, 1};
595
596     auto output_ptr = output.pointer<char>();
597
598     for (size_t i = 0; i < ref_data.size(); ++i) {
599         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
600     }
601 }
602
603 TEST(reduce_gpu, common_bfwzyx_sum_square) {
604     const auto& engine = get_test_engine();
605     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
606
607     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
608
609     topology topology;
610     topology.add(input_layout("input", input.get_layout()));
611     topology.add(reduce("reduce", "input", reduce_mode::sum_square, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
612
613     network network(engine, topology);
614
615     network.set_input_data("input", input);
616
617     auto outputs = network.execute();
618
619     EXPECT_EQ(outputs.size(), size_t(1));
620     EXPECT_EQ(outputs.begin()->first, "reduce");
621
622     auto output = outputs.at("reduce").get_memory();
623
624     std::vector<float> ref_data = {5.0f, 50.0f};
625
626     auto output_ptr = output.pointer<float>();
627
628     for (size_t i = 0; i < ref_data.size(); ++i) {
629         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
630     }
631 }
632
633 TEST(reduce_gpu, common_bfwzyx_sum_square_keepdims) {
634     const auto& engine = get_test_engine();
635     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
636
637     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
638
639     topology topology;
640     topology.add(input_layout("input", input.get_layout()));
641     topology.add(reduce("reduce", "input", reduce_mode::sum_square, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
642
643     network network(engine, topology);
644
645     network.set_input_data("input", input);
646
647     auto outputs = network.execute();
648
649     EXPECT_EQ(outputs.size(), size_t(1));
650     EXPECT_EQ(outputs.begin()->first, "reduce");
651
652     auto output = outputs.at("reduce").get_memory();
653
654     std::vector<float> ref_data = {5.0f, 50.0f};
655
656     auto output_ptr = output.pointer<float>();
657
658     for (size_t i = 0; i < ref_data.size(); ++i) {
659         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
660     }
661 }
662
663 TEST(reduce_gpu, common_bfwzyx_l1) {
664     const auto& engine = get_test_engine();
665     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
666
667     set_values(input, {0.0f, 1.0f, -2.0f, 3.0f, 4.0f, -5.0f});
668
669     topology topology;
670     topology.add(input_layout("input", input.get_layout()));
671     topology.add(reduce("reduce", "input", reduce_mode::l1, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
672
673     network network(engine, topology);
674
675     network.set_input_data("input", input);
676
677     auto outputs = network.execute();
678
679     EXPECT_EQ(outputs.size(), size_t(1));
680     EXPECT_EQ(outputs.begin()->first, "reduce");
681
682     auto output = outputs.at("reduce").get_memory();
683
684     std::vector<float> ref_data = {3.0f, 12.0f};
685
686     auto output_ptr = output.pointer<float>();
687
688     for (size_t i = 0; i < ref_data.size(); ++i) {
689         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
690     }
691 }
692
693 TEST(reduce_gpu, common_bfwzyx_l1_keepdims) {
694     const auto& engine = get_test_engine();
695     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
696
697     set_values(input, {0.0f, 1.0f, -2.0f, 3.0f, 4.0f, -5.0f});
698
699     topology topology;
700     topology.add(input_layout("input", input.get_layout()));
701     topology.add(reduce("reduce", "input", reduce_mode::l1, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
702
703     network network(engine, topology);
704
705     network.set_input_data("input", input);
706
707     auto outputs = network.execute();
708
709     EXPECT_EQ(outputs.size(), size_t(1));
710     EXPECT_EQ(outputs.begin()->first, "reduce");
711
712     auto output = outputs.at("reduce").get_memory();
713
714     std::vector<float> ref_data = {3.0f, 12.0f};
715
716     auto output_ptr = output.pointer<float>();
717
718     for (size_t i = 0; i < ref_data.size(); ++i) {
719         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
720     }
721 }
722
723 TEST(reduce_gpu, common_bfwzyx_l2) {
724     const auto& engine = get_test_engine();
725     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
726
727     set_values(input, {0.0f, 1.0f, -2.0f, 3.0f, 4.0f, -5.0f});
728
729     topology topology;
730     topology.add(input_layout("input", input.get_layout()));
731     topology.add(reduce("reduce", "input", reduce_mode::l2, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
732
733     network network(engine, topology);
734
735     network.set_input_data("input", input);
736
737     auto outputs = network.execute();
738
739     EXPECT_EQ(outputs.size(), size_t(1));
740     EXPECT_EQ(outputs.begin()->first, "reduce");
741
742     auto output = outputs.at("reduce").get_memory();
743
744     std::vector<float> ref_data = {2.236067977f, 7.071067812f};
745
746     auto output_ptr = output.pointer<float>();
747
748     for (size_t i = 0; i < ref_data.size(); ++i) {
749         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
750     }
751 }
752
753 TEST(reduce_gpu, common_bfwzyx_l2_keepdims) {
754     const auto& engine = get_test_engine();
755     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
756
757     set_values(input, {0.0f, 1.0f, -2.0f, 3.0f, 4.0f, -5.0f});
758
759     topology topology;
760     topology.add(input_layout("input", input.get_layout()));
761     topology.add(reduce("reduce", "input", reduce_mode::l2, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
762
763     network network(engine, topology);
764
765     network.set_input_data("input", input);
766
767     auto outputs = network.execute();
768
769     EXPECT_EQ(outputs.size(), size_t(1));
770     EXPECT_EQ(outputs.begin()->first, "reduce");
771
772     auto output = outputs.at("reduce").get_memory();
773
774     std::vector<float> ref_data = {2.236067977f, 7.071067812f};
775
776     auto output_ptr = output.pointer<float>();
777
778     for (size_t i = 0; i < ref_data.size(); ++i) {
779         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
780     }
781 }
782
783 TEST(reduce_gpu, common_bfwzyx_log_sum) {
784     const auto& engine = get_test_engine();
785     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
786
787     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
788
789     topology topology;
790     topology.add(input_layout("input", input.get_layout()));
791     topology.add(reduce("reduce", "input", reduce_mode::log_sum, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
792
793     network network(engine, topology);
794
795     network.set_input_data("input", input);
796
797     auto outputs = network.execute();
798
799     EXPECT_EQ(outputs.size(), size_t(1));
800     EXPECT_EQ(outputs.begin()->first, "reduce");
801
802     auto output = outputs.at("reduce").get_memory();
803
804     std::vector<float> ref_data = {1.0986122887f, 2.4849066498f};
805
806     auto output_ptr = output.pointer<float>();
807
808     for (size_t i = 0; i < ref_data.size(); ++i) {
809         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
810     }
811 }
812
813 TEST(reduce_gpu, common_bfwzyx_log_sum_keepdims) {
814     const auto& engine = get_test_engine();
815     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
816
817     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
818
819     topology topology;
820     topology.add(input_layout("input", input.get_layout()));
821     topology.add(reduce("reduce", "input", reduce_mode::log_sum, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
822
823     network network(engine, topology);
824
825     network.set_input_data("input", input);
826
827     auto outputs = network.execute();
828
829     EXPECT_EQ(outputs.size(), size_t(1));
830     EXPECT_EQ(outputs.begin()->first, "reduce");
831
832     auto output = outputs.at("reduce").get_memory();
833
834     std::vector<float> ref_data = {1.0986122887f, 2.4849066498f};
835
836     auto output_ptr = output.pointer<float>();
837
838     for (size_t i = 0; i < ref_data.size(); ++i) {
839         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
840     }
841 }
842
843 TEST(reduce_gpu, common_bfwzyx_log_sum_exp) {
844     const auto& engine = get_test_engine();
845     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
846
847     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
848
849     topology topology;
850     topology.add(input_layout("input", input.get_layout()));
851     topology.add(reduce("reduce", "input", reduce_mode::log_sum_exp, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 0));
852
853     network network(engine, topology);
854
855     network.set_input_data("input", input);
856
857     auto outputs = network.execute();
858
859     EXPECT_EQ(outputs.size(), size_t(1));
860     EXPECT_EQ(outputs.begin()->first, "reduce");
861
862     auto output = outputs.at("reduce").get_memory();
863
864     std::vector<float> ref_data = {2.407605964f, 5.407605964f};
865
866     auto output_ptr = output.pointer<float>();
867
868     for (size_t i = 0; i < ref_data.size(); ++i) {
869         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
870     }
871 }
872
873 TEST(reduce_gpu, common_bfwzyx_log_sum_exp_keepdims) {
874     const auto& engine = get_test_engine();
875     auto input = memory::allocate(engine, {data_types::f32, format::bfwzyx, {2, 3, 1, 1, 1, 1}});
876
877     set_values(input, {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f});
878
879     topology topology;
880     topology.add(input_layout("input", input.get_layout()));
881     topology.add(reduce("reduce", "input", reduce_mode::log_sum_exp, {cldnn::reduce::along_f, cldnn::reduce::along_w}, 1));
882
883     network network(engine, topology);
884
885     network.set_input_data("input", input);
886
887     auto outputs = network.execute();
888
889     EXPECT_EQ(outputs.size(), size_t(1));
890     EXPECT_EQ(outputs.begin()->first, "reduce");
891
892     auto output = outputs.at("reduce").get_memory();
893
894     std::vector<float> ref_data = {2.407605964f, 5.407605964f};
895
896     auto output_ptr = output.pointer<float>();
897
898     for (size_t i = 0; i < ref_data.size(); ++i) {
899         EXPECT_TRUE(are_equal(ref_data[i], output_ptr[i]));
900     }
901 }