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 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 #include <gtest/gtest.h>
20 #include "api/CPP/memory.hpp"
21 #include <api/CPP/input_layout.hpp>
22 #include "api/CPP/softmax_loss_grad.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(softmax_loss_grad_f32_fw_gpu, basic1) {
34 const auto& engine = get_test_engine();
36 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ 2, 1, 4, 1 } });
37 auto labels = memory::allocate(engine, { data_types::f32, format::bfyx,{ 2, 1, 1, 1 } });
39 set_values(input, { 8.f, 0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 4.f });
40 set_values(labels, { 1.f, 3.f });
43 input_layout("input", input.get_layout()),
44 data("labels", labels),
45 softmax_loss_grad("softmax_loss_grad", "input", "labels")
48 network network(engine, topology);
49 network.set_input_data("input", input);
51 auto outputs = network.execute();
52 EXPECT_EQ(outputs.size(), size_t(1));
53 EXPECT_EQ(outputs.begin()->first, "softmax_loss_grad");
55 auto output_prim = outputs.begin()->second.get_memory();
57 auto output_ptr = output_prim.pointer<float>();
59 std::vector<float> expected_output_vec = { 8.f, -0.5f, 6.f, 9.f, 1.f, 3.f, 2.f, 3.f };
61 for (unsigned int i = 0; i < expected_output_vec.size(); i++)
63 EXPECT_FLOAT_EQ(expected_output_vec[i], output_ptr[i]);