Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / select.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 #include "select_inst.h"
19 #include "primitive_type_base.h"
20 #include "error_handler.h"
21 #include "json_object.h"
22
23 namespace cldnn
24 {
25 primitive_type_id select_type_id()
26 {
27     static primitive_type_base<select> instance;
28     return &instance;
29 }
30
31 layout select_inst::calc_output_layout(select_node const& node)
32 {
33     assert((bool)node.get_primitive()->output_data_type == false
34            && "Output data type forcing is not supported for select_node!");
35     return node.input().get_non_padded_output_layout();
36 }
37
38 std::string select_inst::to_string(select_node const& node)
39 {
40     auto node_info  = node.desc_to_json();
41     auto desc       = node.get_primitive();
42
43     std::stringstream primitive_description;
44
45     json_composite select_info;
46     for (size_t i = 0; i < node.inputs_count(); i++)
47     {
48         select_info.add("input_"+std::to_string(i), node.input(i).id());
49     }
50
51     node_info->add("select info", select_info);
52     node_info->dump(primitive_description);
53
54     return primitive_description.str();
55 }
56
57 select_inst::typed_primitive_inst(network_impl& network, select_node const& node)
58     :parent(network, node)
59 {
60         auto& deps = node.get_dependencies();
61
62         for (size_t i = 0; i < deps.size() - 1; i++)
63         {
64                 auto batch1 = deps[i]->get_output_layout().size.batch[0];
65                 auto batch2 = deps[i+1]->get_output_layout().size.batch[0];
66                 CLDNN_ERROR_NOT_EQUAL(node.id(), "Batch size input", batch1, "Batch size next input", batch2, "");
67
68                 auto feature1 = deps[i]->get_output_layout().size.feature[0];
69                 auto feature2 = deps[i+1]->get_output_layout().size.feature[0];
70                 CLDNN_ERROR_NOT_EQUAL(node.id(), "Feature size input", feature1, "Feature size next input", feature2, "");
71
72                 auto spatial1 = deps[i]->get_output_layout().size.spatial[0];
73                 auto spatial2 = deps[i + 1]->get_output_layout().size.spatial[0];               
74                 CLDNN_ERROR_NOT_EQUAL(node.id(), "Spatial size input", spatial1, "Spatial size next input", spatial2, "");
75
76                 auto format1 = deps[i]->get_output_layout().format;
77                 auto format2 = deps[i+1]->get_output_layout().format;
78                 CLDNN_ERROR_NOT_EQUAL(node.id(), "Format input", format1, "Format next input", format2, "");
79         }
80
81         auto data_type1 = deps[0]->get_output_layout().data_type;
82         auto data_type2 = deps[1]->get_output_layout().data_type;
83         CLDNN_ERROR_DATA_TYPES_MISMATCH(node.id(), "Data type input 1", data_type1, "Data type input 2", data_type2, "");
84 }
85 }