Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / tests / test_cases / propagate_constants_gpu_test.cpp
1 /*
2 // Copyright (c) 2018 Intel Corporation
3 //
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
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18
19 #include <gtest/gtest.h>
20 #include "api/CPP/memory.hpp"
21 #include <api/CPP/input_layout.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/concatenation.hpp>
27 #include <api/CPP/reorder.hpp>
28 #include <api/CPP/data.hpp>
29 #include <api/CPP/reshape.hpp>
30
31 using namespace cldnn;
32 using namespace tests;
33
34 //We expect additional reorder to be added in between "weights1" and "reshape1".
35 //This situation should be handled properly by propagate constants optimization phase
36 TEST(propagate_constants, copy_dependecies_from_nodes) {
37     const auto& engine = get_test_engine();
38     build_options build_opt;
39     build_opt.set_option(build_option::optimize_data(true));
40
41     auto input = memory::allocate(engine, { data_types::f16, format::yxfb,{ 1, 1, 2, 2 } });
42     auto weights1 = memory::allocate(engine, { data_types::f16, format::yxfb,{ 1, 1, 2, 1 } });
43     auto weights2 = memory::allocate(engine, { data_types::f32, format::byxf,{ 1, 1, 1, 2 } });
44
45     set_values(input, { FLOAT16(1.1f), FLOAT16(1.2f), FLOAT16(1.3f), FLOAT16(1.4f) });
46     set_values(weights1, { FLOAT16(2.1f), FLOAT16(3.1f) });
47     set_values(weights2, { 1.1f, 0.1f });
48
49     topology topology;
50     topology.add(input_layout("input", input.get_layout()));
51     topology.add(data("weights1", weights1));
52     topology.add(data("weights2", weights2));
53     topology.add(reshape("reshape1", "weights1", tensor(spatial(1, 2))));
54     topology.add(reorder("reorder2", "input", layout(data_types::f32, format::byxf, 4)));
55     topology.add(reorder("reorder1", "reshape1", layout(data_types::f32, format::byxf, 4)));
56     topology.add(concatenation("concat", { "reorder1", "weights2" }, concatenation::along_x));
57     topology.add(convolution("conv2", { "reorder2" }, { "concat" }));
58     network network(engine, topology, build_opt);
59     network.set_input_data("input", input);
60
61     auto outputs = network.execute();
62
63     float epsilon = 1e-2f;
64     for (auto& it : outputs)
65     {
66         auto output = it.second.get_memory().pointer<float>();
67         EXPECT_NEAR(7.8f, output[0], epsilon);
68     }
69 }