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/fully_connected_grad_input.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"
29 using namespace cldnn;
30 using namespace tests;
32 TEST(fully_connected_grad_input_gpu, basic_bfyx) {
51 // -1.125 5.625 10.125
54 const auto& engine = get_test_engine();
56 auto input_grad = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 4, 1 } });
57 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 1, 1, 3, 1 } });
58 auto weights = memory::allocate(engine, { data_types::f32, format::bfyx,{ 4, 1, 3, 1 } });
60 set_values(input, { -0.5f, 2.0f, 0.5f });
61 set_values(input_grad, { 1.5f, 0.75f, -2.25f, 3.0f });
62 set_values(weights, { 1.5f, 1.0f, 0.5f, -1.0f, 0.0f, 0.5f, 0.5f, -0.5f, -2.0f, -0.5f, 1.0f, 1.5f });
65 input_layout("input_grad", input_grad.get_layout()),
67 data("weights", weights),
68 fully_connected_grad_input("fully_connected_grad_input", "input_grad", "input", { "weights" })
71 network network(engine, topology);
72 network.set_input_data("input_grad", input_grad);
74 auto outputs = network.execute();
75 EXPECT_EQ(outputs.size(), size_t(1));
76 EXPECT_EQ(outputs.begin()->first, "fully_connected_grad_input");
78 auto output_prim = outputs.begin()->second.get_memory();
80 auto output_ptr = output_prim.pointer<float>();
82 std::vector<float> expected_output_vec = {
83 -1.125f, 5.625f, 10.125f
86 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
88 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);