Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / split.cpp
1 /*
2 // Copyright (c) 2016 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 #include "split_inst.h"
18 #include "primitive_type_base.h"
19 #include "memory_impl.h"
20 #include "error_handler.h"
21 #include "json_object.h"
22
23 namespace cldnn
24 {
25 primitive_type_id split_type_id()
26 {
27     static primitive_type_base<split> instance;
28     return &instance;
29 }
30
31 layout split_inst::calc_output_layout(split_node const& node)
32 {
33     assert((bool)node.get_primitive()->output_data_type == false
34            && "Output data type forcing is not supported for split_node!");
35     auto output_ids = node.get_primitive()->output_ids;
36     auto output_offsets = node.get_primitive()->output_offsets;
37     auto param_num = output_ids.size();
38     auto input_sizes = node.get_dependency(0).get_non_padded_output_layout().size;
39
40     //check if output_ids count equals output_offsets count
41     CLDNN_ERROR_NOT_EQUAL(node.id(), "Output_ids count", param_num, "output_offsets count", output_offsets.size(), "Output_ids count/ output_offsets count mismatch");
42
43     for (decltype(param_num) i = 0; i < param_num; i++)
44     {
45         if (i != param_num - 1)
46             //check if output offset sizes is less than next output offset sizes
47             CLDNN_ERROR_TENSOR_SIZES_GREATER_THAN(node.id(), "output_offsets", output_offsets[i], "next output_offsets", output_offsets[i + 1], "Output_offsets tensor/ next input output_offsets tensor mismatch");
48         else
49             //check if output offset sizes matches output offsets sizes
50             CLDNN_ERROR_TENSOR_SIZES_GREATER_THAN(node.id(), "Output_offsets", output_offsets[i], "input sizes", input_sizes, "Output_offsets tensor/ input tensor mismatch");
51
52         //check if offsets do not extend input sizes and if match the output sizes
53         CLDNN_ERROR_TENSOR_SIZES_LESS_THAN(node.id(), "Output_offsets", output_offsets[i], "0 value", { 0, 0, 0, 0 }, "Invalid output_offsets: dims cannot be less than 0");
54     }
55
56     return node.input().get_non_padded_output_layout();
57 }
58
59 std::string split_inst::to_string(split_node const& node)
60 {
61     auto desc           = node.get_primitive();
62     auto node_info      = node.desc_to_json();
63     auto output_ids     = desc->output_ids;
64     auto output_offsets = desc->output_offsets;
65     auto& input         = node.input();
66     
67     std::stringstream primitive_description;
68
69     json_composite split_info;
70     split_info.add("input id", input.id());
71     split_info.add("output ids count", output_ids.size());
72     split_info.add("offset count", output_offsets.size());
73     
74     node_info->add("split info", split_info);
75     node_info->dump(primitive_description);
76
77     return primitive_description.str();
78 }
79
80 split_inst::typed_primitive_inst(network_impl& network, split_node const& node)
81     :parent(network, node)
82 {
83     CLDNN_ERROR_MESSAGE(node.id(), "Split primitive instance should not be created!");
84 }
85
86 }