2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 #include <gtest/gtest.h>
20 #include "api/CPP/memory.hpp"
21 #include <api/CPP/input_layout.hpp>
22 #include "api/CPP/deconvolution.hpp"
23 #include <api/CPP/data.hpp>
24 #include <api/CPP/topology.hpp>
25 #include <api/CPP/network.hpp>
26 #include <api/CPP/engine.hpp>
27 #include "test_utils/test_utils.h"
28 #include "test_utils/float16.h"
29 #include "api/CPP/reorder.hpp"
32 using namespace cldnn;
33 using namespace tests;
35 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x1_nopad) {
58 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
59 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
60 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
62 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
63 set_values(weights, { -2.0f, 0.5f, 3.5f, 1.5f });
64 set_values(biases, { 2.0f });
67 input_layout("input", input.get_layout()),
68 data("weights", weights),
69 data("biases", biases),
70 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1,1,1,1 })
73 network network(engine, topology);
74 network.set_input_data("input", input);
76 auto outputs = network.execute();
77 EXPECT_EQ(outputs.size(), size_t(1));
78 EXPECT_EQ(outputs.begin()->first, "deconv");
80 auto output_prim = outputs.begin()->second.get_memory();
82 auto output_ptr = output_prim.pointer<float>();
84 std::vector<float> expected_output_vec = {
90 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
92 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
97 TEST(deconvolution_f32_fw_gpu, no_bias_basic_wsiz2x2_in2x2x1x1_nopad) {
120 auto input = memory::allocate(engine, { data_types::f32, format::yxfb,{ 1, 1, 2, 2 } });
121 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb,{ 1, 1, 2, 2 } });
123 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
124 set_values(weights, { -2.0f, 0.5f, 3.5f, 1.5f });
127 input_layout("input", input.get_layout()),
128 data("weights", weights),
129 deconvolution("deconv", "input", { "weights" })
132 network network(engine, topology);
133 network.set_input_data("input", input);
135 auto outputs = network.execute();
136 EXPECT_EQ(outputs.size(), size_t(1));
137 EXPECT_EQ(outputs.begin()->first, "deconv");
139 auto output_prim = outputs.begin()->second.get_memory();
141 auto output_ptr = output_prim.pointer<float>();
143 std::vector<float> expected_output_vec = {
149 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
151 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
156 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x1_nopad_bfyx) { // Filter : 2x2
178 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
179 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 2, 2 } });
180 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
182 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
183 set_values(weights, { -2.0f, 0.5f, 3.5f, 1.5f });
184 set_values(biases, { 2.0f });
187 input_layout("input", input.get_layout()),
188 data("weights", weights),
189 data("biases", biases),
190 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1,1,1,1 })
193 network network(engine, topology);
194 network.set_input_data("input", input);
196 auto outputs = network.execute();
197 EXPECT_EQ(outputs.size(), size_t(1));
198 EXPECT_EQ(outputs.begin()->first, "deconv");
200 auto output_prim = outputs.begin()->second.get_memory();
202 auto output_ptr = output_prim.pointer<float>();
204 std::vector<float> expected_output_vec = {
210 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
212 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
216 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x1_pad1) {
238 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
239 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
240 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
242 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
243 set_values(weights, { -2.0f, 0.5f, 3.5f, 1.5f });
244 set_values(biases, { 2.0f });
247 input_layout("input", input.get_layout()),
248 data("weights", weights),
249 data("biases", biases),
250 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 1, 1 }, { 0, 0, -1, -1 })
253 network network(engine, topology);
254 network.set_input_data("input", input);
256 auto outputs = network.execute();
257 EXPECT_EQ(outputs.size(), size_t(1));
258 EXPECT_EQ(outputs.begin()->first, "deconv");
260 auto output_prim = outputs.begin()->second.get_memory();
262 auto output_ptr = output_prim.pointer<float>();
264 EXPECT_FLOAT_EQ(0.75f, output_ptr[0]);
267 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x1_stride2_nopad) {
289 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
290 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
291 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
293 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
294 set_values(weights, { -2.0f, 0.5f, 3.5f, 1.5f });
295 set_values(biases, { 1.0f });
298 input_layout("input", input.get_layout()),
299 data("weights", weights),
300 data("biases", biases),
301 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1,1,2,2 })
304 network network(engine, topology);
305 network.set_input_data("input", input);
307 auto outputs = network.execute();
308 EXPECT_EQ(outputs.size(), size_t(1));
309 EXPECT_EQ(outputs.begin()->first, "deconv");
311 auto output_prim = outputs.begin()->second.get_memory();
313 auto output_ptr = output_prim.pointer<float>();
315 std::vector<float> expected_output_vec = {
316 -15.f, 5.f, 0.f, 1.25f,
317 29.f, 13.f, 2.75f, 1.75,
318 -11.f, 4.f, -17.f, 5.5f,
319 22.f, 10.f, 32.5f, 14.5f
322 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
324 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
328 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x1_stride4_pad2) {
354 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
355 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 3, 3 } });
356 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
358 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
359 set_values(weights, { -2.0f, 0.5f, 1.f, 3.5f, 1.5f, 2.f, 3.f, 4.f, 5.f });
360 set_values(biases, { 0.0f });
363 input_layout("input", input.get_layout()),
364 data("weights", weights),
365 data("biases", biases),
366 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 4, 4 }, { 0, 0, -2, -2 })
369 network network(engine, topology);
370 network.set_input_data("input", input);
372 auto outputs = network.execute();
373 EXPECT_EQ(outputs.size(), size_t(1));
374 EXPECT_EQ(outputs.begin()->first, "deconv");
376 auto output_prim = outputs.begin()->second.get_memory();
378 auto output_ptr = output_prim.pointer<float>();
380 std::vector<float> expected_output_vec = {
386 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
388 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
392 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x2_stride2_pad1) {
416 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 2, 1, 2, 2 } });
417 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
418 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
420 set_values(input, { 8.f, 1.f, 0.5f, 3.f, 6.f, 2.f, 9.f, 4.f });
421 set_values(weights, { -2.f, 2.f, 7.f, -0.5f });
422 set_values(biases, { 1.0f });
425 input_layout("input", input.get_layout()),
426 data("weights", weights),
427 data("biases", biases),
428 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
431 network network(engine, topology);
432 network.set_input_data("input", input);
434 auto outputs = network.execute();
435 EXPECT_EQ(outputs.size(), size_t(1));
436 EXPECT_EQ(outputs.begin()->first, "deconv");
438 auto output_prim = outputs.begin()->second.get_memory();
440 auto output_ptr = output_prim.pointer<float>();
442 std::vector<float> expected_output_vec = {
443 -3.f, 0.5f, 4.5f, 22.f,
444 13.f, 5.f, -17.f, -7.f
447 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
449 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
453 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2x2_in2x2x1x1_stride2_pad1) {
481 auto input = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
482 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 2, 1, 2, 2 } });
483 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 2, 1 } });
485 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
486 set_values(weights, { -2.f, -2.f, 2.f, 2.f, 7.f, 7.f, -0.5f, -0.5f });
487 set_values(biases, { 1.0f, 5.0f });
490 input_layout("input", input.get_layout()),
491 data("weights", weights),
492 data("biases", biases),
493 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
496 network network(engine, topology);
497 network.set_input_data("input", input);
499 auto outputs = network.execute();
500 EXPECT_EQ(outputs.size(), size_t(1));
501 EXPECT_EQ(outputs.begin()->first, "deconv");
503 auto output_prim = outputs.begin()->second.get_memory();
505 auto output_ptr = output_prim.pointer<float>();
507 std::vector<float> expected_output_vec = {
508 -3.f, 1.f, 4.5f, 8.5f,
509 13.f, 17.f, -17.f, -13.f
512 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
514 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
518 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x2_bfyx_stride2_pad1) {
542 auto input = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 1, 2, 2 } });
543 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 2, 2 } });
544 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
546 set_values(input, { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f });
547 set_values(weights, { -2.f, 2.f, 7.f, -0.5f });
548 set_values(biases, { 1.0f });
551 input_layout("input", input.get_layout()),
552 data("weights", weights),
553 data("biases", biases),
554 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
557 network network(engine, topology);
558 network.set_input_data("input", input);
560 auto outputs = network.execute();
561 EXPECT_EQ(outputs.size(), size_t(1));
562 EXPECT_EQ(outputs.begin()->first, "deconv");
564 auto output_prim = outputs.begin()->second.get_memory();
566 auto output_ptr = output_prim.pointer<float>();
568 std::vector<float> expected_output_vec = {
569 -3.f, 4.5f, 13.f, -17.f,
573 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
575 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
579 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x2_bfyx_stride2_pad1_input_padding) {
585 // Input Padding : 2x1 (with reorder)
604 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 2, 1, 2, 2 } });
605 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
606 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 1, 1 } });
608 set_values(input, { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f });
609 set_values(weights, { -2.f, 2.f, 7.f, -0.5f });
610 set_values(biases, { 1.0f });
613 input_layout("input", input.get_layout()),
614 reorder("reorder", "input", input.get_layout().with_padding({ { 0, 0, 1, 2 }, 0 })),
615 data("weights", weights),
616 data("biases", biases),
617 deconvolution("deconv", "reorder", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
620 network network(engine, topology);
621 network.set_input_data("input", input);
623 auto outputs = network.execute();
624 EXPECT_EQ(outputs.size(), size_t(1));
625 EXPECT_EQ(outputs.begin()->first, "deconv");
627 auto output_prim = outputs.begin()->second.get_memory();
629 auto output_ptr = output_prim.pointer<float>();
631 std::vector<float> expected_output_vec = {
632 -3.f, 4.5f, 13.f, -17.f,
636 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
638 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
642 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2x2_in2x2x1x1_stride2_pad1_input_padding) {
648 // Input Padding : 2x1 (with reorder)
671 auto input = memory::allocate(engine, { data_types::f32, format::yxfb,{ 1, 1, 2, 2 } });
672 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb,{ 2, 1, 2, 2 } });
673 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 1 } });
675 set_values(input, { 8.f, 0.5f, 6.f, 9.f });
676 set_values(weights, { -2.f, -2.f, 2.f, 2.f, 7.f, 7.f, -0.5f, -0.5f });
677 set_values(biases, { 1.0f, 5.0f });
680 input_layout("input", input.get_layout()),
681 reorder("reorder", "input", input.get_layout().with_padding({ { 0, 0, 1, 2 }, 0 })),
682 data("weights", weights),
683 data("biases", biases),
684 deconvolution("deconv", "reorder", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
687 network network(engine, topology);
688 network.set_input_data("input", input);
690 auto outputs = network.execute();
691 EXPECT_EQ(outputs.size(), size_t(1));
692 EXPECT_EQ(outputs.begin()->first, "deconv");
694 auto output_prim = outputs.begin()->second.get_memory();
696 auto output_ptr = output_prim.pointer<float>();
698 std::vector<float> expected_output_vec = {
699 -3.f, 1.f, 4.5f, 8.5f,
700 13.f, 17.f, -17.f, -13.f
703 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
705 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
709 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in2x2x1x2_bfyx_yxfb_stride2_pad1) {
733 auto input = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 1, 2, 2 } });
734 auto weights = memory::allocate(engine, { data_types::f32, format::yxfb, { 1, 1, 2, 2 } });
735 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx, { 1, 1, 1, 1 } });
737 set_values(input, { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f });
738 set_values(weights, { -2.f, 2.f, 7.f, -0.5f });
739 set_values(biases, { 1.0f });
742 input_layout("input", input.get_layout()),
743 data("weights", weights),
744 data("biases", biases),
745 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
748 network network(engine, topology);
749 network.set_input_data("input", input);
751 auto outputs = network.execute();
752 EXPECT_EQ(outputs.size(), size_t(1));
753 EXPECT_EQ(outputs.begin()->first, "deconv");
755 auto output_prim = outputs.begin()->second.get_memory();
757 auto output_ptr = output_prim.pointer<float>();
759 std::vector<float> expected_output_vec = {
760 -3.f, 4.5f, 13.f, -17.f,
764 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
766 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
770 TEST(deconvolution_f16_fw_gpu, basic_wsiz2x2_in2x2x1x2_bfyx_yxfb_stride2_pad1) {
794 auto input = memory::allocate(engine, { data_types::f16, format::bfyx,{ 2, 1, 2, 2 } });
795 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
796 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 1, 1 } });
798 cldnn::build_options options;
799 options.set_option(cldnn::build_option::optimize_data(true));
801 set_values(input, { FLOAT16(8.f), FLOAT16(0.5f), FLOAT16(6.f), FLOAT16(9.f),
802 FLOAT16(1.f), FLOAT16(3.f), FLOAT16(2.f), FLOAT16(4.f) });
803 set_values(weights, { -2.f, 2.f, 7.f, -0.5f});
804 set_values(biases, { 1.0f });
807 input_layout("input", input.get_layout()),
808 data("weights", weights),
809 data("biases", biases),
810 deconvolution("deconv", "input", { "weights" }, { "biases" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
813 network network(engine, topology, options);
814 network.set_input_data("input", input);
816 auto outputs = network.execute();
817 EXPECT_EQ(outputs.size(), size_t(1));
818 EXPECT_EQ(outputs.begin()->first, "deconv");
820 auto output_prim = outputs.begin()->second.get_memory();
822 auto output_ptr = output_prim.pointer<uint16_t>();
824 std::vector<float> expected_output_vec = {
825 -3.f, 4.5f, 13.f, -17.f,
829 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
831 EXPECT_FLOAT_EQ(expected_output_vec[i], float16_to_float32(output_ptr[i]));
835 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in1x2x2x2_bfyx_stride2_pad1_split2) {
866 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 2, 2, 2 } });
867 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
868 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 1, 1 } });
869 auto weights2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
870 auto biases2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 1, 1 } });
872 set_values(input, { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f });
873 set_values(weights, { -2.f, 2.f, 7.f, -0.5f });
874 set_values(biases, { 1.0f });
875 set_values(weights2, { -4.f, 1.f, -9.f, -7.f });
876 set_values(biases2, { -1.0f });
879 input_layout("input", input.get_layout()),
880 data("weights", weights),
881 data("biases", biases),
882 data("weights2", weights2),
883 data("biases2", biases2),
884 deconvolution("deconv", "input", { "weights", "weights2" }, { "biases", "biases2" }, { 1, 1, 2, 2 }, { 0, 0, -1, -1 })
887 network network(engine, topology);
888 network.set_input_data("input", input);
890 auto outputs = network.execute();
891 EXPECT_EQ(outputs.size(), size_t(1));
892 EXPECT_EQ(outputs.begin()->first, "deconv");
894 auto output_prim = outputs.begin()->second.get_memory();
896 auto output_ptr = output_prim.pointer<float>();
898 std::vector<float> expected_output_vec = {
899 -3.f, 4.5f, 13.f, -17.f,
900 -8.f, -28.f, 1.f, -17.f
903 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
905 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
909 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in1x2x2x2_bfyx_stride2_pad1_split2_depthwise_sep_opt) {
910 // Test for depthwise separable optimization, there are 16 weights and biases (split 16)
911 // data is similar as in basic_wsiz2x2_in1x2x2x2_bfyx_stride2_pad1_split2
915 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 16, 2, 2 } });
917 { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
918 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
919 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
920 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
921 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
922 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
923 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
924 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f
927 topology topology(input_layout("input", input.get_layout()));
929 std::vector<primitive_id> weights_vec;
930 std::vector<primitive_id> bias_vec;
932 for (uint32_t i = 0; i < 8; i++)
934 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
935 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 1, 1 } });
936 auto weights2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
937 auto biases2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 1, 1 } });
939 set_values(weights, { -2.f, 2.f, 7.f, -0.5f });
940 set_values(biases, { 1.0f });
941 set_values(weights2, { -4.f, 1.f, -9.f, -7.f });
942 set_values(biases2, { -1.0f });
944 primitive_id weights_id = "weights_" + std::to_string(i);
945 primitive_id weights2_id = "weights2_" + std::to_string(i);
946 primitive_id bias_id = "biases_" + std::to_string(i);
947 primitive_id bias2_id = "biases2_" + std::to_string(i);
949 weights_vec.push_back(weights_id);
950 weights_vec.push_back(weights2_id);
951 bias_vec.push_back(bias_id);
952 bias_vec.push_back(bias2_id);
955 data(weights_id, weights),
956 data(bias_id, biases),
957 data(weights2_id, weights2),
958 data(bias2_id, biases2)
962 topology.add(deconvolution("deconv", "input", weights_vec, bias_vec, { 1, 1, 2, 2 }, { 0, 0, -1, -1 }));
964 network network(engine, topology);
965 network.set_input_data("input", input);
967 auto outputs = network.execute();
968 EXPECT_EQ(outputs.size(), size_t(1));
969 EXPECT_EQ(outputs.begin()->first, "deconv");
971 auto output_prim = outputs.begin()->second.get_memory();
973 auto output_ptr = output_prim.pointer<float>();
975 std::vector<float> expected_output_vec = {
976 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
977 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
978 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
979 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
980 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
981 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
982 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
983 -3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f,
986 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
988 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
992 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in1x2x2x2_bfyx_stride2_pad1_split2_depthwise_sep_opt_ofm2) {
993 // Test for depthwise separable optimization, there are 16 weights and biases (split 16)
994 // data is similar as in basic_wsiz2x2_in1x2x2x2_bfyx_stride2_pad1_split2
998 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 16, 2, 2 } });
1000 { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1001 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1002 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1003 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1004 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1005 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1006 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f,
1007 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f
1010 topology topology(input_layout("input", input.get_layout()));
1012 std::vector<primitive_id> weights_vec;
1013 std::vector<primitive_id> bias_vec;
1015 for (uint32_t i = 0; i < 8; i++)
1017 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 2, 1, 2, 2 } });
1018 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 1 } });
1019 auto weights2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 2, 1, 2, 2 } });
1020 auto biases2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 1 } });
1022 set_values(weights, { -2.f, 2.f, 7.f, -0.5f, -2.f, 2.f, 7.f, -0.5f });
1023 set_values(biases, { 1.0f, 1.0f });
1024 set_values(weights2, { -4.f, 1.f, -9.f, -7.f, -4.f, 1.f, -9.f, -7.f });
1025 set_values(biases2, { -1.0f, -1.0f });
1027 primitive_id weights_id = "weights_" + std::to_string(i);
1028 primitive_id weights2_id = "weights2_" + std::to_string(i);
1029 primitive_id bias_id = "biases_" + std::to_string(i);
1030 primitive_id bias2_id = "biases2_" + std::to_string(i);
1032 weights_vec.push_back(weights_id);
1033 weights_vec.push_back(weights2_id);
1034 bias_vec.push_back(bias_id);
1035 bias_vec.push_back(bias2_id);
1038 data(weights_id, weights),
1039 data(bias_id, biases),
1040 data(weights2_id, weights2),
1041 data(bias2_id, biases2)
1045 topology.add(deconvolution("deconv", "input", weights_vec, bias_vec, { 1, 1, 2, 2 }, { 0, 0, -1, -1 }));
1047 network network(engine, topology);
1048 network.set_input_data("input", input);
1050 auto outputs = network.execute();
1051 EXPECT_EQ(outputs.size(), size_t(1));
1052 EXPECT_EQ(outputs.begin()->first, "deconv");
1054 auto output_prim = outputs.begin()->second.get_memory();
1056 auto output_ptr = output_prim.pointer<float>();
1058 std::vector<float> expected_output_vec = {
1059 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1060 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1061 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1062 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1063 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1064 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1065 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1066 -3.f, 4.5f, 13.f, -17.f,-3.f, 4.5f, 13.f, -17.f, -8.f, -28.f, 1.f, -17.f, -8.f, -28.f, 1.f, -17.f,
1069 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
1071 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);
1075 TEST(deconvolution_f32_fw_gpu, basic_wsiz2x2_in1x6x1x1_bfyx_stride2_pad1_split2_ofm3) {
1114 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 4, 1, 1 } });
1115 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 3, 2, 1, 1 } });
1116 auto biases = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 3, 1 } });
1117 auto weights2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 3, 2, 1, 1 } });
1118 auto biases2 = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 3, 1 } });
1121 1.5f, 0.5f, 2.0f, -1.0f
1123 set_values(weights, { -2.0f, 1.0f, 1.0f, 3.0f, 0.5f, 8.0f });
1124 set_values(biases, { 1.0f, 5.0f, 3.0f });
1125 set_values(weights2, { 4.0f, -4.0f, 2.0f, 0.5f, -0.5f, 3.0f });
1126 set_values(biases2, { -1.0f, 2.5f, 2.0f });
1129 input_layout("input", input.get_layout()),
1130 data("weights", weights),
1131 data("biases", biases),
1132 data("weights2", weights2),
1133 data("biases2", biases2),
1134 deconvolution("deconv", "input", { "weights", "weights2" }, { "biases", "biases2" }, { 1, 1, 1, 1 }, { 0, 0, 0, 0 })
1137 network network(engine, topology);
1138 network.set_input_data("input", input);
1140 auto outputs = network.execute();
1141 EXPECT_EQ(outputs.size(), size_t(1));
1142 EXPECT_EQ(outputs.begin()->first, "deconv");
1144 auto output_prim = outputs.begin()->second.get_memory();
1146 auto output_ptr = output_prim.pointer<float>();
1148 std::vector<float> expected_output_vec = {
1149 -1.5f, 8.0f, 7.75f, 11.0f, 6.0f, -2.0f
1151 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
1153 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);