2 // Copyright (c) 2019 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 #include "depth_to_space_inst.h"
19 #include "primitive_type_base.h"
20 #include "error_handler.h"
21 #include "json_object.h"
25 primitive_type_id depth_to_space_type_id()
27 static primitive_type_base<depth_to_space> instance;
31 layout depth_to_space_inst::calc_output_layout(depth_to_space_node const& node)
33 auto desc = node.get_primitive();
35 auto input_layout = node.input(0).get_output_layout();
36 auto input_format = input_layout.format;
38 const size_t block_size = desc->block_size;
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));
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));
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;
52 return layout{input_layout.data_type, input_format, tensor(TensorValue(input_layout.size.batch[0]), TensorValue(feature), TensorValue(x), TensorValue(y))};
55 std::string depth_to_space_inst::to_string(depth_to_space_node const& node)
57 auto desc = node.get_primitive();
58 auto node_info = node.desc_to_json();
59 auto& input = node.input();
61 std::stringstream primitive_description;
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);
67 node_info->add("depth_to_space info", depth_to_space_info);
68 node_info->dump(primitive_description);
70 return primitive_description.str();
73 depth_to_space_inst::typed_primitive_inst(network_impl& network, depth_to_space_node const& node)
74 : parent(network, node)