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/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>
31 using namespace cldnn;
32 using namespace tests;
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));
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 } });
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 });
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);
61 auto outputs = network.execute();
63 float epsilon = 1e-2f;
64 for (auto& it : outputs)
66 auto output = it.second.get_memory().pointer<float>();
67 EXPECT_NEAR(7.8f, output[0], epsilon);