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/depth_to_space.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(depth_to_space_fp16_gpu, d1411_bs2) {
36 // Input values in fp16
40 auto input1 = memory::allocate(engine, { data_types::f16, format::bfyx, { 1, 4, 1, 1 } });
41 size_t block_size = 2;
44 FLOAT16(0.0f), FLOAT16(1.0f),
45 FLOAT16(2.0f), FLOAT16(3.0f)
49 topology.add(input_layout("Input0", input1.get_layout()));
51 depth_to_space("depth_to_space", "Input0", block_size)
54 network network(engine, topology);
56 network.set_input_data("Input0", input1);
58 auto outputs = network.execute();
60 auto output = outputs.at("depth_to_space").get_memory();
61 auto output_ptr = output.pointer<uint16_t>();
63 std::vector<float> expected_results = {
67 for (size_t i = 0; i < expected_results.size(); ++i) {
68 EXPECT_EQ(expected_results[i], float16_to_float32(output_ptr[i]));
72 TEST(depth_to_space_fp16_gpu, d1421_bs2) {
76 // Input values in fp16
80 auto input1 = memory::allocate(engine, { data_types::f16, format::bfyx, { 1, 4, 1, 2 } });
81 size_t block_size = 2;
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)
91 topology.add(input_layout("Input0", input1.get_layout()));
93 depth_to_space("depth_to_space", "Input0", block_size)
96 network network(engine, topology);
98 network.set_input_data("Input0", input1);
100 auto outputs = network.execute();
102 auto output = outputs.at("depth_to_space").get_memory();
103 auto output_ptr = output.pointer<uint16_t>();
105 std::vector<float> expected_results = {
106 0.0f, 2.0f, 4.0f, 6.0f, 1.0f, 3.0f, 5.0f, 7.0f
109 for (size_t i = 0; i < expected_results.size(); ++i) {
110 EXPECT_EQ(expected_results[i], float16_to_float32(output_ptr[i]));
114 TEST(depth_to_space_fp16_gpu, d1933_bs3) {
118 // Input values in fp16
122 auto input1 = memory::allocate(engine, { data_types::f16, format::bfyx, { 1, 9, 3, 3 } });
123 size_t block_size = 3;
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),
146 topology.add(input_layout("Input0", input1.get_layout()));
148 depth_to_space("depth_to_space", "Input0", block_size)
151 network network(engine, topology);
153 network.set_input_data("Input0", input1);
155 auto outputs = network.execute();
157 auto output = outputs.at("depth_to_space").get_memory();
158 auto output_ptr = output.pointer<uint16_t>();
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,
172 for (size_t i = 0; i < expected_results.size(); ++i) {
173 EXPECT_EQ(expected_results[i], float16_to_float32(output_ptr[i]));
177 TEST(depth_to_space_fp32_gpu, d1411_bs2) {
181 // Input values in fp32
185 auto input1 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 4, 1, 1 } });
186 size_t block_size = 2;
193 topology.add(input_layout("Input0", input1.get_layout()));
195 depth_to_space("depth_to_space", "Input0", block_size)
198 network network(engine, topology);
200 network.set_input_data("Input0", input1);
202 auto outputs = network.execute();
204 auto output = outputs.at("depth_to_space").get_memory();
205 auto output_ptr = output.pointer<float>();
207 std::vector<float> expected_results = {
211 for (size_t i = 0; i < expected_results.size(); ++i) {
212 EXPECT_EQ(expected_results[i], output_ptr[i]);
216 TEST(depth_to_space_fp32_gpu, d1421_bs2) {
220 // Input values in fp32
224 auto input1 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 4, 1, 2 } });
225 size_t block_size = 2;
228 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f
232 topology.add(input_layout("Input0", input1.get_layout()));
234 depth_to_space("depth_to_space", "Input0", block_size)
237 network network(engine, topology);
239 network.set_input_data("Input0", input1);
241 auto outputs = network.execute();
243 auto output = outputs.at("depth_to_space").get_memory();
244 auto output_ptr = output.pointer<float>();
246 std::vector<float> expected_results = {
247 0.f, 2.f, 4.f, 6.f, 1.f, 3.f, 5.f, 7.f
250 for (size_t i = 0; i < expected_results.size(); ++i) {
251 EXPECT_EQ(expected_results[i], output_ptr[i]);
255 TEST(depth_to_space_fp32_gpu, d1933_bs3) {
259 // Input values in fp32
263 auto input1 = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 9, 3, 3 } });
264 size_t block_size = 3;
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,
279 topology.add(input_layout("Input0", input1.get_layout()));
281 depth_to_space("depth_to_space", "Input0", block_size)
284 network network(engine, topology);
286 network.set_input_data("Input0", input1);
288 auto outputs = network.execute();
290 auto output = outputs.at("depth_to_space").get_memory();
291 auto output_ptr = output.pointer<float>();
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,
305 for (size_t i = 0; i < expected_results.size(); ++i) {
306 EXPECT_EQ(expected_results[i], output_ptr[i]);