2 // Copyright (c) 2018 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/scale_grad_input.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"
29 using namespace cldnn;
30 using namespace tests;
32 TEST(scale_grad_input_gpu, basic_in2x3x2x2_scale_same_size) {
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 8 -17
44 // f0: b0: 0.1 0.2 0.25 b1: 0.3 0.4 0.5
45 // f0: b0: 0.6 0.7 0.75 b1: 0.8 0.9 1
46 // f1: b0: 1.1 1.2 1.25 b1: 1.3 1.4 1.5
47 // f1: b0: 1.6 1.7 1.75 b1: 1.8 1.9 2
49 const auto& engine = get_test_engine();
51 auto input = memory::allocate(engine, { data_types::f32, format::yxfb,{ 2, 2, 3, 2 } });
52 auto scale_input = memory::allocate(engine, { data_types::f32, format::yxfb,{ 2, 2, 3, 2 } });
55 topology.add(input_layout("input", input.get_layout()));
56 topology.add(input_layout("scale_input", scale_input.get_layout()));
57 topology.add(scale_grad_input("scale_grad", "input", "scale_input"));
59 std::vector<float> input_vec = { 1.f, 0.f, 5.f, 1.5f,
61 -10.f, -11.f, -12.f, -13.f,
64 -14.f, -15.f, -16.f, -17.f };
65 set_values(input, input_vec);
67 std::vector<float> scale_input_vec = {
68 0.1f, 0.3f, 1.1f, 1.3f,
69 0.2f, 0.4f, 1.2f, 1.4f,
70 0.25f, 0.5f, 1.25f, 1.5f,
71 0.6f, 0.8f, 1.6f, 1.8f,
72 0.7f, 0.9f, 1.7f, 1.9f,
73 0.75f, 1.f, 1.75f, 2.f
75 set_values(scale_input, scale_input_vec);
77 network network(engine, topology);
79 network.set_input_data("input", input);
80 network.set_input_data("scale_input", scale_input);
82 auto outputs = network.execute();
84 auto output = outputs.at("scale_grad").get_memory();
85 auto output_ptr = output.pointer<float>();
87 for (unsigned int i = 0; i < input_vec.size(); ++i) {
88 EXPECT_NEAR(output_ptr[i], input_vec[i] * scale_input_vec[i], 1e-05F);