Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / tests / test_cases / depth_to_space_gpu_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/depth_to_space.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(depth_to_space_fp16_gpu, d1411_bs2) {
33     //  Input  : 1x4x1x1
34     //  Block size : 2
35     //  Output : 1x1x2x2
36     //  Input values in fp16
37
38     engine engine;
39
40     auto input1 = memory::allocate(engine, { data_types::f16, format::bfyx, { 1, 4, 1, 1 } });
41     size_t block_size = 2;
42
43     set_values(input1, {
44         FLOAT16(0.0f), FLOAT16(1.0f),
45         FLOAT16(2.0f), FLOAT16(3.0f)
46     });
47
48     topology topology;
49     topology.add(input_layout("Input0", input1.get_layout()));
50     topology.add(
51         depth_to_space("depth_to_space", "Input0", block_size)
52     );
53
54     network network(engine, topology);
55
56     network.set_input_data("Input0", input1);
57
58     auto outputs = network.execute();
59
60     auto output = outputs.at("depth_to_space").get_memory();
61     auto output_ptr = output.pointer<uint16_t>();
62
63     std::vector<float> expected_results = {
64         0.f, 1.f, 2.f, 3.f
65     };
66
67     for (size_t i = 0; i < expected_results.size(); ++i) {
68         EXPECT_EQ(expected_results[i], float16_to_float32(output_ptr[i]));
69     }
70 }
71
72 TEST(depth_to_space_fp16_gpu, d1421_bs2) {
73     //  Input  : 1x4x2x1
74     //  Block size : 2
75     //  Output : 1x1x4x2
76     //  Input values in fp16
77
78     engine engine;
79
80     auto input1 = memory::allocate(engine, { data_types::f16, format::bfyx, { 1, 4, 1, 2 } });
81     size_t block_size = 2;
82
83     set_values(input1, {
84         FLOAT16(0.0f), FLOAT16(1.0f),
85         FLOAT16(2.0f), FLOAT16(3.0f),
86         FLOAT16(4.0f), FLOAT16(5.0f),
87         FLOAT16(6.0f), FLOAT16(7.0f)
88     });
89
90     topology topology;
91     topology.add(input_layout("Input0", input1.get_layout()));
92     topology.add(
93         depth_to_space("depth_to_space", "Input0", block_size)
94     );
95
96     network network(engine, topology);
97
98     network.set_input_data("Input0", input1);
99
100     auto outputs = network.execute();
101
102     auto output = outputs.at("depth_to_space").get_memory();
103     auto output_ptr = output.pointer<uint16_t>();
104
105     std::vector<float> expected_results = {
106         0.0f, 2.0f, 4.0f, 6.0f, 1.0f, 3.0f, 5.0f, 7.0f
107     };
108
109     for (size_t i = 0; i < expected_results.size(); ++i) {
110         EXPECT_EQ(expected_results[i], float16_to_float32(output_ptr[i]));
111     }
112 }
113
114 TEST(depth_to_space_fp16_gpu, d1933_bs3) {
115     //  Input  : 1x9x3x3
116     //  Block size : 3
117     //  Output : 1x1x9x9
118     //  Input values in fp16
119
120     engine engine;
121
122     auto input1 = memory::allocate(engine, { data_types::f16, format::bfyx, { 1, 9, 3, 3 } });
123     size_t block_size = 3;
124
125     set_values(input1, {
126         FLOAT16(0.0f), FLOAT16(1.0f), FLOAT16(2.0f), FLOAT16(3.0f), FLOAT16(4.0f),
127         FLOAT16(5.0f), FLOAT16(6.0f), FLOAT16(7.0f), FLOAT16(8.0f), FLOAT16(9.0f),
128         FLOAT16(10.0f), FLOAT16(11.0f), FLOAT16(12.0f), FLOAT16(13.0f), FLOAT16(14.0f),
129         FLOAT16(15.0f), FLOAT16(16.0f), FLOAT16(17.0f), FLOAT16(18.0f), FLOAT16(19.0f),
130         FLOAT16(20.0f), FLOAT16(21.0f), FLOAT16(22.0f), FLOAT16(23.0f), FLOAT16(24.0f),
131         FLOAT16(25.0f), FLOAT16(26.0f), FLOAT16(27.0f), FLOAT16(28.0f), FLOAT16(29.0f),
132         FLOAT16(30.0f), FLOAT16(31.0f), FLOAT16(32.0f), FLOAT16(33.0f), FLOAT16(34.0f),
133         FLOAT16(35.0f), FLOAT16(36.0f), FLOAT16(37.0f), FLOAT16(38.0f), FLOAT16(39.0f),
134         FLOAT16(40.0f), FLOAT16(41.0f), FLOAT16(42.0f), FLOAT16(43.0f), FLOAT16(44.0f),
135         FLOAT16(45.0f), FLOAT16(46.0f), FLOAT16(47.0f), FLOAT16(48.0f), FLOAT16(49.0f),
136         FLOAT16(50.0f), FLOAT16(51.0f), FLOAT16(52.0f), FLOAT16(53.0f), FLOAT16(54.0f),
137         FLOAT16(55.0f), FLOAT16(56.0f), FLOAT16(57.0f), FLOAT16(58.0f), FLOAT16(59.0f),
138         FLOAT16(60.0f), FLOAT16(61.0f), FLOAT16(62.0f), FLOAT16(63.0f), FLOAT16(64.0f),
139         FLOAT16(65.0f), FLOAT16(66.0f), FLOAT16(67.0f), FLOAT16(68.0f), FLOAT16(69.0f),
140         FLOAT16(70.0f), FLOAT16(71.0f), FLOAT16(72.0f), FLOAT16(73.0f), FLOAT16(74.0f),
141         FLOAT16(75.0f), FLOAT16(76.0f), FLOAT16(77.0f), FLOAT16(78.0f), FLOAT16(79.0f),
142         FLOAT16(80.0f)
143     });
144
145     topology topology;
146     topology.add(input_layout("Input0", input1.get_layout()));
147     topology.add(
148             depth_to_space("depth_to_space", "Input0", block_size)
149     );
150
151     network network(engine, topology);
152
153     network.set_input_data("Input0", input1);
154
155     auto outputs = network.execute();
156
157     auto output = outputs.at("depth_to_space").get_memory();
158     auto output_ptr = output.pointer<uint16_t>();
159
160     std::vector<float> expected_results = {
161         0.0f, 9.0f, 18.0f, 1.0f, 10.0f, 19.0f, 2.0f, 11.0f, 20.0f, 27.0f,
162         36.0f, 45.0f, 28.0f, 37.0f, 46.0f, 29.0f, 38.0f, 47.0f, 54.0f, 63.0f,
163         72.0f, 55.0f, 64.0f, 73.0f, 56.0f, 65.0f, 74.0f, 3.0f, 12.0f, 21.0f,
164         4.0f, 13.0f, 22.0f, 5.0f, 14.0f, 23.0f, 30.0f, 39.0f, 48.0f, 31.0f,
165         40.0f, 49.0f, 32.0f, 41.0f, 50.0f, 57.0f, 66.0f, 75.0f, 58.0f, 67.0f,
166         76.0f, 59.0f, 68.0f, 77.0f, 6.0f, 15.0f, 24.0f, 7.0f, 16.0f, 25.0f,
167         8.0f, 17.0f, 26.0f, 33.0f, 42.0f, 51.0f, 34.0f, 43.0f, 52.0f, 35.0f,
168         44.0f, 53.0f, 60.0f, 69.0f, 78.0f, 61.0f, 70.0f, 79.0f, 62.0f, 71.0f,
169         80.0f
170     };
171
172     for (size_t i = 0; i < expected_results.size(); ++i) {
173         EXPECT_EQ(expected_results[i], float16_to_float32(output_ptr[i]));
174     }
175 }
176
177 TEST(depth_to_space_fp32_gpu, d1411_bs2) {
178     //  Input  : 1x4x1x1
179     //  Block size : 2
180     //  Output : 1x1x2x2
181     //  Input values in fp32
182
183     engine engine;
184
185     auto input1 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 4, 1, 1 } });
186     size_t block_size = 2;
187
188     set_values(input1, {
189         0.f, 1.f, 2.f, 3.f
190     });
191
192     topology topology;
193     topology.add(input_layout("Input0", input1.get_layout()));
194     topology.add(
195         depth_to_space("depth_to_space", "Input0", block_size)
196     );
197
198     network network(engine, topology);
199
200     network.set_input_data("Input0", input1);
201
202     auto outputs = network.execute();
203
204     auto output = outputs.at("depth_to_space").get_memory();
205     auto output_ptr = output.pointer<float>();
206
207     std::vector<float> expected_results = {
208         0.f, 1.f, 2.f, 3.f
209     };
210
211     for (size_t i = 0; i < expected_results.size(); ++i) {
212         EXPECT_EQ(expected_results[i], output_ptr[i]);
213     }
214 }
215
216 TEST(depth_to_space_fp32_gpu, d1421_bs2) {
217     //  Input  : 1x4x2x1
218     //  Block size : 2
219     //  Output : 1x1x4x2
220     //  Input values in fp32
221
222     engine engine;
223
224     auto input1 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 4, 1, 2 } });
225     size_t block_size = 2;
226
227     set_values(input1, {
228         0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f
229     });
230
231     topology topology;
232     topology.add(input_layout("Input0", input1.get_layout()));
233     topology.add(
234         depth_to_space("depth_to_space", "Input0", block_size)
235     );
236
237     network network(engine, topology);
238
239     network.set_input_data("Input0", input1);
240
241     auto outputs = network.execute();
242
243     auto output = outputs.at("depth_to_space").get_memory();
244     auto output_ptr = output.pointer<float>();
245
246     std::vector<float> expected_results = {
247         0.f, 2.f, 4.f, 6.f, 1.f, 3.f, 5.f, 7.f
248     };
249
250     for (size_t i = 0; i < expected_results.size(); ++i) {
251         EXPECT_EQ(expected_results[i], output_ptr[i]);
252     }
253 }
254
255 TEST(depth_to_space_fp32_gpu, d1933_bs3) {
256     //  Input  : 1x9x3x3
257     //  Block size : 3
258     //  Output : 1x1x9x9
259     //  Input values in fp32
260
261     engine engine;
262
263     auto input1 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 9, 3, 3 } });
264     size_t block_size = 3;
265
266     set_values(input1, {
267         0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
268         10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f,
269         20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f, 29.0f,
270         30.0f, 31.0f, 32.0f, 33.0f, 34.0f, 35.0f, 36.0f, 37.0f, 38.0f, 39.0f,
271         40.0f, 41.0f, 42.0f, 43.0f, 44.0f, 45.0f, 46.0f, 47.0f, 48.0f, 49.0f,
272         50.0f, 51.0f, 52.0f, 53.0f, 54.0f, 55.0f, 56.0f, 57.0f, 58.0f, 59.0f,
273         60.0f, 61.0f, 62.0f, 63.0f, 64.0f, 65.0f, 66.0f, 67.0f, 68.0f, 69.0f,
274         70.0f, 71.0f, 72.0f, 73.0f, 74.0f, 75.0f, 76.0f, 77.0f, 78.0f, 79.0f,
275         80.0f
276     });
277
278     topology topology;
279     topology.add(input_layout("Input0", input1.get_layout()));
280     topology.add(
281         depth_to_space("depth_to_space", "Input0", block_size)
282     );
283
284     network network(engine, topology);
285
286     network.set_input_data("Input0", input1);
287
288     auto outputs = network.execute();
289
290     auto output = outputs.at("depth_to_space").get_memory();
291     auto output_ptr = output.pointer<float>();
292
293     std::vector<float> expected_results = {
294         0.0f, 9.0f, 18.0f, 1.0f, 10.0f, 19.0f, 2.0f, 11.0f, 20.0f, 27.0f,
295         36.0f, 45.0f, 28.0f, 37.0f, 46.0f, 29.0f, 38.0f, 47.0f, 54.0f, 63.0f,
296         72.0f, 55.0f, 64.0f, 73.0f, 56.0f, 65.0f, 74.0f, 3.0f, 12.0f, 21.0f,
297         4.0f, 13.0f, 22.0f, 5.0f, 14.0f, 23.0f, 30.0f, 39.0f, 48.0f, 31.0f,
298         40.0f, 49.0f, 32.0f, 41.0f, 50.0f, 57.0f, 66.0f, 75.0f, 58.0f, 67.0f,
299         76.0f, 59.0f, 68.0f, 77.0f, 6.0f, 15.0f, 24.0f, 7.0f, 16.0f, 25.0f,
300         8.0f, 17.0f, 26.0f, 33.0f, 42.0f, 51.0f, 34.0f, 43.0f, 52.0f, 35.0f,
301         44.0f, 53.0f, 60.0f, 69.0f, 78.0f, 61.0f, 70.0f, 79.0f, 62.0f, 71.0f,
302         80.0f
303     };
304
305     for (size_t i = 0; i < expected_results.size(); ++i) {
306         EXPECT_EQ(expected_results[i], output_ptr[i]);
307     }
308 }