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 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include <gtest/gtest.h>
19 #include "api/CPP/memory.hpp"
20 #include <api/CPP/input_layout.hpp>
21 #include "api/CPP/upsampling.hpp"
22 #include <api/CPP/topology.hpp>
23 #include <api/CPP/network.hpp>
24 #include <api/CPP/engine.hpp>
25 #include "test_utils/test_utils.h"
26 #include <api/CPP/reorder.hpp>
27 #include <api/CPP/data.hpp>
29 using namespace cldnn;
30 using namespace tests;
32 TEST(upsampling_gpu, basic_in2x3x2x2_nearest) {
35 // Sample Type: Nearest
38 // f0: b0: 1 2 -10 b1: 0 0 -11
39 // f0: b0: 3 4 -14 b1: 0.5 -0.5 -15
40 // f1: b0: 5 6 -12 b1: 1.5 5.2 -13
41 // f1: b0: 7 8 -16 b1: 12 9 -17
44 const auto& engine = get_test_engine();
46 auto input = memory::allocate(engine, { data_types::f32, format::bfyx, { 2, 2, 3, 2 } });
51 topology.add(input_layout("input", input.get_layout()));
52 topology.add(upsampling("upsampling", "input", scale, 0, upsampling_sample_type::nearest));
65 network network(engine, topology);
67 network.set_input_data("input", input);
69 auto outputs = network.execute();
71 auto output = outputs.at("upsampling").get_memory();
72 auto output_ptr = output.pointer<float>();
75 1.f, 1.f, 2.f, 2.f, -10.f, -10.f,
76 1.f, 1.f, 2.f, 2.f, -10.f, -10.f,
77 3.f, 3.f, 4.f, 4.f, -14.f, -14.f,
78 3.f, 3.f, 4.f, 4.f, -14.f, -14.f,
79 5.f, 5.f, 6.f, 6.f, -12.f, -12.f,
80 5.f, 5.f, 6.f, 6.f, -12.f, -12.f,
81 7.f, 7.f, 8.f, 8.f, -16.f, -16.f,
82 7.f, 7.f, 8.f, 8.f, -16.f, -16.f,
83 0.f, 0.f, 0.f, 0.f, -11.f, -11.f,
84 0.f, 0.f, 0.f, 0.f, -11.f, -11.f,
85 0.5f,0.5f, -0.5f, -0.5f, -15.f, -15.f,
86 0.5f,0.5f, -0.5f, -0.5f, -15.f, -15.f,
87 1.5f,1.5f, 5.2f, 5.2f, -13.f, -13.f,
88 1.5f,1.5f, 5.2f, 5.2f, -13.f, -13.f,
89 12.f,12.f, 9.f, 9.f, -17.f, -17.f,
90 12.f,12.f, 9.f, 9.f, -17.f, -17.f,
93 for (int i = 0; i < 2; ++i) { //B
94 for (int j = 0; j < 2; ++j) { //F
95 for (int k = 0; k < 4; ++k) { //Y
96 for (int l = 0; l < 6; ++l) { //X
97 auto linear_id = l + k * 6 + j * 4 * 6 + i * 2 * 4 * 6;
98 EXPECT_TRUE(are_equal(answers[linear_id], output_ptr[linear_id]));
105 TEST(upsampling_gpu, basic_in2x3x2x2_bilinear) {
108 // Sample Type: Nearest
115 const auto& engine = get_test_engine();
117 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 2, 2 } });
122 topology.add(input_layout("input", input.get_layout()));
123 topology.add(upsampling("upsampling", "input", scale, 1, upsampling_sample_type::bilinear));
130 network network(engine, topology);
132 network.set_input_data("input", input);
134 auto outputs = network.execute();
136 auto output = outputs.at("upsampling").get_memory();
137 auto output_ptr = output.pointer<float>();
139 float answers[16] = {
140 0.5625f, 0.9375f, 1.3125f, 1.125f,
141 1.125f, 1.75f, 2.25f, 1.875f,
142 1.875f, 2.75f, 3.25f, 2.625f,
143 1.6875f, 2.4375f, 2.8125f, 2.25f,
146 for (int k = 0; k < 4; ++k) { //Y
147 for (int l = 0; l < 4; ++l) { //X
148 auto linear_id = l + k * 4;
149 EXPECT_NEAR(answers[linear_id], output_ptr[linear_id], 1e-05F);