Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / tests / test_cases / shuffle_channels_test.cpp
1 // Copyright (c) 2019 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include <gtest/gtest.h>
19
20 #include <api/CPP/input_layout.hpp>
21 #include <api/CPP/memory.hpp>
22 #include <api/CPP/shuffle_channels.hpp>
23 #include <api/CPP/topology.hpp>
24 #include <api/CPP/network.hpp>
25
26 #include <cstddef>
27 #include <tests/test_utils/test_utils.h>
28
29 using namespace cldnn;
30 using namespace ::tests;
31
32 TEST(shuffle_channels_fp32_gpu, d1_15_2_2_ax1_g5) {
33     engine engine;
34
35     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 15, 2, 2 } });
36     int32_t axis = 1;
37     int32_t group = 5;
38
39     set_values(input0, {
40             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
41             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
42             20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f,
43             30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
44             40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, 48.0f, 49.0f,
45             50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, 57.0f, 58.0f, 59.0f
46     });
47
48     topology topology;
49     topology.add(input_layout("Input0", input0.get_layout()));
50     topology.add(
51             shuffle_channels("shuffle_channels", "Input0", group, axis)
52     );
53
54     network network(engine, topology);
55
56     network.set_input_data("Input0", input0);
57
58     auto outputs = network.execute();
59
60     auto output = outputs.at("shuffle_channels").get_memory();
61     auto output_ptr = output.pointer<float>();
62
63     std::vector<float> expected_results = {
64             0.f, 1.f, 2.f, 3.f, 12.f, 13.f, 14.f, 15.f, 24.f, 25.f, 26.f, 27.f, 36.f, 37.f, 38.f, 39.f, 48.f, 49.f, 50.f, 51.f,
65             4.f, 5.f, 6.f, 7.f, 16.f, 17.f, 18.f, 19.f, 28.f, 29.f, 30.f, 31.f, 40.f, 41.f, 42.f, 43.f, 52.f, 53.f, 54.f, 55.f,
66             8.f, 9.f, 10.f, 11.f, 20.f, 21.f, 22.f, 23.f, 32.f, 33.f, 34.f, 35.f, 44.f, 45.f, 46.f, 47.f, 56.f, 57.f, 58.f, 59.f
67     };
68
69     for (size_t i = 0; i < expected_results.size(); ++i) {
70         EXPECT_EQ(expected_results[i], output_ptr[i]);
71     }
72 }
73
74
75 TEST(shuffle_channels_fp32_gpu, d1_15_2_2_axm3_g5) {
76     engine engine;
77
78     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 15, 2, 2 } });
79     int32_t axis = -3;
80     int32_t group = 5;
81
82     set_values(input0, {
83             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
84             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
85             20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f,
86             30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
87             40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, 48.0f, 49.0f,
88             50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, 57.0f, 58.0f, 59.0f
89     });
90
91     topology topology;
92     topology.add(input_layout("Input0", input0.get_layout()));
93     topology.add(
94             shuffle_channels("shuffle_channels", "Input0", group, axis)
95     );
96
97     network network(engine, topology);
98
99     network.set_input_data("Input0", input0);
100
101     auto outputs = network.execute();
102
103     auto output = outputs.at("shuffle_channels").get_memory();
104     auto output_ptr = output.pointer<float>();
105
106     std::vector<float> expected_results = {
107             0.f, 1.f, 2.f, 3.f, 12.f, 13.f, 14.f, 15.f, 24.f, 25.f, 26.f, 27.f, 36.f, 37.f, 38.f, 39.f, 48.f, 49.f, 50.f, 51.f,
108             4.f, 5.f, 6.f, 7.f, 16.f, 17.f, 18.f, 19.f, 28.f, 29.f, 30.f, 31.f, 40.f, 41.f, 42.f, 43.f, 52.f, 53.f, 54.f, 55.f,
109             8.f, 9.f, 10.f, 11.f, 20.f, 21.f, 22.f, 23.f, 32.f, 33.f, 34.f, 35.f, 44.f, 45.f, 46.f, 47.f, 56.f, 57.f, 58.f, 59.f
110     };
111
112     for (size_t i = 0; i < expected_results.size(); ++i) {
113         EXPECT_EQ(expected_results[i], output_ptr[i]);
114     }
115 }
116
117 TEST(shuffle_channels_fp32_gpu, d15_2_2_ax0_g5) {
118     engine engine;
119
120     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 15, 2, 1, 2 } });
121     int32_t axis = 0;
122     int32_t group = 5;
123
124     set_values(input0, {
125             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
126             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
127             20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f,
128             30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
129             40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, 48.0f, 49.0f,
130             50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, 57.0f, 58.0f, 59.0f
131     });
132
133     topology topology;
134     topology.add(input_layout("Input0", input0.get_layout()));
135     topology.add(
136             shuffle_channels("shuffle_channels", "Input0", group, axis)
137     );
138
139     network network(engine, topology);
140
141     network.set_input_data("Input0", input0);
142
143     auto outputs = network.execute();
144
145     auto output = outputs.at("shuffle_channels").get_memory();
146     auto output_ptr = output.pointer<float>();
147
148     std::vector<float> expected_results = {
149             0.f, 1.f, 2.f, 3.f, 12.f, 13.f, 14.f, 15.f, 24.f, 25.f, 26.f, 27.f, 36.f, 37.f, 38.f, 39.f, 48.f, 49.f, 50.f, 51.f,
150             4.f, 5.f, 6.f, 7.f, 16.f, 17.f, 18.f, 19.f, 28.f, 29.f, 30.f, 31.f, 40.f, 41.f, 42.f, 43.f, 52.f, 53.f, 54.f, 55.f,
151             8.f, 9.f, 10.f, 11.f, 20.f, 21.f, 22.f, 23.f, 32.f, 33.f, 34.f, 35.f, 44.f, 45.f, 46.f, 47.f, 56.f, 57.f, 58.f, 59.f
152     };
153
154     for (size_t i = 0; i < expected_results.size(); ++i) {
155         EXPECT_EQ(expected_results[i], output_ptr[i]);
156     }
157 }
158
159 TEST(shuffle_channels_fp32_gpu, d15_2_2_axm4_g5) {
160     engine engine;
161
162     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 15, 2, 1, 2 } });
163     int32_t axis = -4;
164     int32_t group = 5;
165
166     set_values(input0, {
167             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
168             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
169             20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f,
170             30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
171             40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, 48.0f, 49.0f,
172             50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, 57.0f, 58.0f, 59.0f
173     });
174
175     topology topology;
176     topology.add(input_layout("Input0", input0.get_layout()));
177     topology.add(
178             shuffle_channels("shuffle_channels", "Input0", group, axis)
179     );
180
181     network network(engine, topology);
182
183     network.set_input_data("Input0", input0);
184
185     auto outputs = network.execute();
186
187     auto output = outputs.at("shuffle_channels").get_memory();
188     auto output_ptr = output.pointer<float>();
189
190     std::vector<float> expected_results = {
191             0.f, 1.f, 2.f, 3.f, 12.f, 13.f, 14.f, 15.f, 24.f, 25.f, 26.f, 27.f, 36.f, 37.f, 38.f, 39.f, 48.f, 49.f, 50.f, 51.f,
192             4.f, 5.f, 6.f, 7.f, 16.f, 17.f, 18.f, 19.f, 28.f, 29.f, 30.f, 31.f, 40.f, 41.f, 42.f, 43.f, 52.f, 53.f, 54.f, 55.f,
193             8.f, 9.f, 10.f, 11.f, 20.f, 21.f, 22.f, 23.f, 32.f, 33.f, 34.f, 35.f, 44.f, 45.f, 46.f, 47.f, 56.f, 57.f, 58.f, 59.f
194     };
195
196     for (size_t i = 0; i < expected_results.size(); ++i) {
197         EXPECT_EQ(expected_results[i], output_ptr[i]);
198     }
199 }
200
201 TEST(shuffle_channels_fp32_gpu, d2_2_6_axm2_g3) {
202     engine engine;
203
204     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 2, 1, 6 } });
205     int32_t axis = -2;
206     int32_t group = 3;
207
208     set_values(input0, {
209             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
210             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
211             20.0f, 21.0f, 22.0f, 23.0f
212     });
213
214     topology topology;
215     topology.add(input_layout("Input0", input0.get_layout()));
216     topology.add(
217             shuffle_channels("shuffle_channels", "Input0", group, axis)
218     );
219
220     network network(engine, topology);
221
222     network.set_input_data("Input0", input0);
223
224     auto outputs = network.execute();
225
226     auto output = outputs.at("shuffle_channels").get_memory();
227     auto output_ptr = output.pointer<float>();
228
229     std::vector<float> expected_results = {
230             0.f, 2.f, 4.f, 1.f, 3.f, 5.f, 6.f, 8.f, 10.f, 7.f, 9.f, 11.f,
231             12.f, 14.f, 16.f, 13.f, 15.f, 17.f, 18.f, 20.f, 22.f, 19.f, 21.f, 23.f
232     };
233
234     for (size_t i = 0; i < expected_results.size(); ++i) {
235         EXPECT_EQ(expected_results[i], output_ptr[i]);
236     }
237 }
238
239 TEST(shuffle_channels_fp32_gpu, d2_6_2_axm3_g3) {
240     engine engine;
241
242     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 6, 1, 2 } });
243     int32_t axis = -3;
244     int32_t group = 3;
245
246     set_values(input0, {
247             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
248             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
249             20.0f, 21.0f, 22.0f, 23.0f
250     });
251
252     topology topology;
253     topology.add(input_layout("Input0", input0.get_layout()));
254     topology.add(
255             shuffle_channels("shuffle_channels", "Input0", group, axis)
256     );
257
258     network network(engine, topology);
259
260     network.set_input_data("Input0", input0);
261
262     auto outputs = network.execute();
263
264     auto output = outputs.at("shuffle_channels").get_memory();
265     auto output_ptr = output.pointer<float>();
266
267     std::vector<float> expected_results = {
268             0.f, 1.f, 4.f, 5.f, 8.f, 9.f, 2.f, 3.f, 6.f, 7.f, 10.f, 11.f,
269             12.f, 13.f, 16.f, 17.f, 20.f, 21.f, 14.f, 15.f, 18.f, 19.f, 22.f, 23.f
270     };
271
272     for (size_t i = 0; i < expected_results.size(); ++i) {
273         EXPECT_EQ(expected_results[i], output_ptr[i]);
274     }
275 }
276
277 TEST(shuffle_channels_fp32_gpu, d2_2_6_axm2_g2) {
278     engine engine;
279
280     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 2, 1, 6 } });
281     int32_t axis = -2;
282     int32_t group = 2;
283
284     set_values(input0, {
285             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
286             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
287             20.0f, 21.0f, 22.0f, 23.0f
288     });
289
290     topology topology;
291     topology.add(input_layout("Input0", input0.get_layout()));
292     topology.add(
293             shuffle_channels("shuffle_channels", "Input0", group, axis)
294     );
295
296     network network(engine, topology);
297
298     network.set_input_data("Input0", input0);
299
300     auto outputs = network.execute();
301
302     auto output = outputs.at("shuffle_channels").get_memory();
303     auto output_ptr = output.pointer<float>();
304
305     std::vector<float> expected_results = {
306             0.f, 3.f, 1.f, 4.f, 2.f, 5.f, 6.f, 9.f, 7.f, 10.f, 8.f, 11.f,
307             12.f, 15.f, 13.f, 16.f, 14.f, 17.f, 18.f, 21.f, 19.f, 22.f, 20.f, 23.f
308     };
309
310     for (size_t i = 0; i < expected_results.size(); ++i) {
311         EXPECT_EQ(expected_results[i], output_ptr[i]);
312     }
313 }
314
315 TEST(shuffle_channels_fp32_gpu, d2_6_2_axm3_g2) {
316     engine engine;
317
318     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 6, 1, 2 } });
319     int32_t axis = -3;
320     int32_t group = 2;
321
322     set_values(input0, {
323             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
324             10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
325             20.0f, 21.0f, 22.0f, 23.0f
326     });
327
328     topology topology;
329     topology.add(input_layout("Input0", input0.get_layout()));
330     topology.add(
331             shuffle_channels("shuffle_channels", "Input0", group, axis)
332     );
333
334     network network(engine, topology);
335
336     network.set_input_data("Input0", input0);
337
338     auto outputs = network.execute();
339
340     auto output = outputs.at("shuffle_channels").get_memory();
341     auto output_ptr = output.pointer<float>();
342
343     std::vector<float> expected_results = {
344             0.f, 1.f, 6.f, 7.f, 2.f, 3.f, 8.f, 9.f, 4.f, 5.f, 10.f, 11.f,
345             12.f, 13.f, 18.f, 19.f, 14.f, 15.f, 20.f, 21.f, 16.f, 17.f, 22.f, 23.f
346     };
347
348     for (size_t i = 0; i < expected_results.size(); ++i) {
349         EXPECT_EQ(expected_results[i], output_ptr[i]);
350     }
351 }
352
353 TEST(shuffle_channels_fp32_gpu, d6_axm0_g2) {
354     engine engine;
355
356     auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 6, 1, 1, 1 } });
357     int32_t axis = 0;
358     int32_t group = 2;
359
360     set_values(input0, {
361             0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f
362     });
363
364     topology topology;
365     topology.add(input_layout("Input0", input0.get_layout()));
366     topology.add(
367             shuffle_channels("shuffle_channels", "Input0", group, axis)
368     );
369
370     network network(engine, topology);
371
372     network.set_input_data("Input0", input0);
373
374     auto outputs = network.execute();
375
376     auto output = outputs.at("shuffle_channels").get_memory();
377     auto output_ptr = output.pointer<float>();
378
379     std::vector<float> expected_results = {
380             0.f, 3.f, 1.f, 4.f, 2.f, 5.f
381     };
382
383     for (size_t i = 0; i < expected_results.size(); ++i) {
384         EXPECT_EQ(expected_results[i], output_ptr[i]);
385     }
386 }