1 // Copyright (c) 2019 Intel Corporation
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include <gtest/gtest.h>
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>
27 #include <tests/test_utils/test_utils.h>
29 using namespace cldnn;
30 using namespace ::tests;
32 TEST(shuffle_channels_fp32_gpu, d1_15_2_2_ax1_g5) {
35 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 15, 2, 2 } });
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
49 topology.add(input_layout("Input0", input0.get_layout()));
51 shuffle_channels("shuffle_channels", "Input0", group, axis)
54 network network(engine, topology);
56 network.set_input_data("Input0", input0);
58 auto outputs = network.execute();
60 auto output = outputs.at("shuffle_channels").get_memory();
61 auto output_ptr = output.pointer<float>();
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
69 for (size_t i = 0; i < expected_results.size(); ++i) {
70 EXPECT_EQ(expected_results[i], output_ptr[i]);
75 TEST(shuffle_channels_fp32_gpu, d1_15_2_2_axm3_g5) {
78 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 15, 2, 2 } });
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
92 topology.add(input_layout("Input0", input0.get_layout()));
94 shuffle_channels("shuffle_channels", "Input0", group, axis)
97 network network(engine, topology);
99 network.set_input_data("Input0", input0);
101 auto outputs = network.execute();
103 auto output = outputs.at("shuffle_channels").get_memory();
104 auto output_ptr = output.pointer<float>();
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
112 for (size_t i = 0; i < expected_results.size(); ++i) {
113 EXPECT_EQ(expected_results[i], output_ptr[i]);
117 TEST(shuffle_channels_fp32_gpu, d15_2_2_ax0_g5) {
120 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 15, 2, 1, 2 } });
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
134 topology.add(input_layout("Input0", input0.get_layout()));
136 shuffle_channels("shuffle_channels", "Input0", group, axis)
139 network network(engine, topology);
141 network.set_input_data("Input0", input0);
143 auto outputs = network.execute();
145 auto output = outputs.at("shuffle_channels").get_memory();
146 auto output_ptr = output.pointer<float>();
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
154 for (size_t i = 0; i < expected_results.size(); ++i) {
155 EXPECT_EQ(expected_results[i], output_ptr[i]);
159 TEST(shuffle_channels_fp32_gpu, d15_2_2_axm4_g5) {
162 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 15, 2, 1, 2 } });
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
176 topology.add(input_layout("Input0", input0.get_layout()));
178 shuffle_channels("shuffle_channels", "Input0", group, axis)
181 network network(engine, topology);
183 network.set_input_data("Input0", input0);
185 auto outputs = network.execute();
187 auto output = outputs.at("shuffle_channels").get_memory();
188 auto output_ptr = output.pointer<float>();
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
196 for (size_t i = 0; i < expected_results.size(); ++i) {
197 EXPECT_EQ(expected_results[i], output_ptr[i]);
201 TEST(shuffle_channels_fp32_gpu, d2_2_6_axm2_g3) {
204 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 2, 1, 6 } });
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
215 topology.add(input_layout("Input0", input0.get_layout()));
217 shuffle_channels("shuffle_channels", "Input0", group, axis)
220 network network(engine, topology);
222 network.set_input_data("Input0", input0);
224 auto outputs = network.execute();
226 auto output = outputs.at("shuffle_channels").get_memory();
227 auto output_ptr = output.pointer<float>();
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
234 for (size_t i = 0; i < expected_results.size(); ++i) {
235 EXPECT_EQ(expected_results[i], output_ptr[i]);
239 TEST(shuffle_channels_fp32_gpu, d2_6_2_axm3_g3) {
242 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 6, 1, 2 } });
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
253 topology.add(input_layout("Input0", input0.get_layout()));
255 shuffle_channels("shuffle_channels", "Input0", group, axis)
258 network network(engine, topology);
260 network.set_input_data("Input0", input0);
262 auto outputs = network.execute();
264 auto output = outputs.at("shuffle_channels").get_memory();
265 auto output_ptr = output.pointer<float>();
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
272 for (size_t i = 0; i < expected_results.size(); ++i) {
273 EXPECT_EQ(expected_results[i], output_ptr[i]);
277 TEST(shuffle_channels_fp32_gpu, d2_2_6_axm2_g2) {
280 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 2, 1, 6 } });
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
291 topology.add(input_layout("Input0", input0.get_layout()));
293 shuffle_channels("shuffle_channels", "Input0", group, axis)
296 network network(engine, topology);
298 network.set_input_data("Input0", input0);
300 auto outputs = network.execute();
302 auto output = outputs.at("shuffle_channels").get_memory();
303 auto output_ptr = output.pointer<float>();
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
310 for (size_t i = 0; i < expected_results.size(); ++i) {
311 EXPECT_EQ(expected_results[i], output_ptr[i]);
315 TEST(shuffle_channels_fp32_gpu, d2_6_2_axm3_g2) {
318 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 6, 1, 2 } });
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
329 topology.add(input_layout("Input0", input0.get_layout()));
331 shuffle_channels("shuffle_channels", "Input0", group, axis)
334 network network(engine, topology);
336 network.set_input_data("Input0", input0);
338 auto outputs = network.execute();
340 auto output = outputs.at("shuffle_channels").get_memory();
341 auto output_ptr = output.pointer<float>();
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
348 for (size_t i = 0; i < expected_results.size(); ++i) {
349 EXPECT_EQ(expected_results[i], output_ptr[i]);
353 TEST(shuffle_channels_fp32_gpu, d6_axm0_g2) {
356 auto input0 = memory::allocate(engine, { data_types::f32, format::bfyx, { 6, 1, 1, 1 } });
361 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f
365 topology.add(input_layout("Input0", input0.get_layout()));
367 shuffle_channels("shuffle_channels", "Input0", group, axis)
370 network network(engine, topology);
372 network.set_input_data("Input0", input0);
374 auto outputs = network.execute();
376 auto output = outputs.at("shuffle_channels").get_memory();
377 auto output_ptr = output.pointer<float>();
379 std::vector<float> expected_results = {
380 0.f, 3.f, 1.f, 4.f, 2.f, 5.f
383 for (size_t i = 0; i < expected_results.size(); ++i) {
384 EXPECT_EQ(expected_results[i], output_ptr[i]);