Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / depth_to_space.cpp
1 /*
2 // Copyright (c) 2019 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 "depth_to_space_inst.h"
18
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 depth_to_space_type_id()
26 {
27     static primitive_type_base<depth_to_space> instance;
28     return &instance;
29 }
30
31 layout depth_to_space_inst::calc_output_layout(depth_to_space_node const& node)
32 {
33     auto desc = node.get_primitive();
34
35     auto input_layout = node.input(0).get_output_layout();
36     auto input_format = input_layout.format;
37
38     const size_t block_size = desc->block_size;
39
40     if (block_size < 2)
41         CLDNN_ERROR_MESSAGE(node.id(), "Invalid depthToSpace block_size value (should equal at least two). Actual block size is" +
42             std::to_string(block_size));
43
44     if (input_layout.size.feature[0] % (block_size * block_size) != 0)
45         CLDNN_ERROR_MESSAGE(node.id(), "The depth of the input tensor must be divisible by squared block size. Actual block size is " +
46             std::to_string(block_size));
47
48     const size_t feature = input_layout.size.feature[0] / block_size / block_size;
49     const size_t y = input_layout.size.spatial[1] * block_size;
50     const size_t x = input_layout.size.spatial[0] * block_size;
51
52     return layout{input_layout.data_type, input_format, tensor(TensorValue(input_layout.size.batch[0]), TensorValue(feature), TensorValue(x), TensorValue(y))};
53 }
54
55 std::string depth_to_space_inst::to_string(depth_to_space_node const& node)
56 {
57     auto desc = node.get_primitive();
58     auto node_info = node.desc_to_json();
59     auto& input = node.input();
60
61     std::stringstream primitive_description;
62
63     json_composite depth_to_space_info;
64     depth_to_space_info.add("input id", input.id());
65     depth_to_space_info.add("block size", desc->block_size);
66
67     node_info->add("depth_to_space info", depth_to_space_info);
68     node_info->dump(primitive_description);
69
70     return primitive_description.str();
71 }
72
73 depth_to_space_inst::typed_primitive_inst(network_impl& network, depth_to_space_node const& node)
74     : parent(network, node)
75 {
76 }
77
78 }