2 // Copyright (c) 2016 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 "scale_inst.h"
18 #include "primitive_type_base.h"
19 #include "error_handler.h"
20 #include "json_object.h"
24 primitive_type_id scale_type_id()
26 static primitive_type_base<scale> instance;
30 layout scale_inst::calc_output_layout(scale_node const& node)
32 assert((bool)node.get_primitive()->output_data_type == false
33 && "Output data type forcing is not supported for scale_node!");
34 auto result = node.input().get_non_padded_output_layout();
36 auto scale_sizes = node.scale_in().get_non_padded_output_layout().size;
37 auto input_sizes = result.size;
39 auto scale_x_size = scale_sizes.spatial[0];
40 auto scale_y_size = scale_sizes.spatial[1];
42 auto input_x_size = input_sizes.spatial[0];
43 auto input_y_size = input_sizes.spatial[1];
45 if (scale_x_size != 1)
47 CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale x size", scale_x_size, "input x size", input_x_size, "");
49 if (scale_y_size != 1)
51 CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale y size", scale_y_size, "input y size", input_y_size, "");
57 std::string scale_inst::to_string(scale_node const& node)
59 auto desc = node.get_primitive();
60 auto node_info = node.desc_to_json();
61 auto& input = node.input();
62 auto& scale_input = node.scale_in();
64 std::stringstream primitive_description;
66 json_composite scale_info;
67 scale_info.add("input", input.id());
68 scale_info.add("scale input", scale_input.id());
70 node_info->add("scale info", scale_info);
71 node_info->dump(primitive_description);
73 return primitive_description.str();
76 scale_inst::typed_primitive_inst(network_impl& network, scale_node const& node)
77 :parent(network, node)
79 auto scale_layout = node.scale_in().get_output_layout();
80 auto scale_format = scale_layout.format;
82 auto scale_batch_size = scale_layout.size.batch[0];
83 auto scale_feature_size = scale_layout.size.feature[0];
85 auto input_batch_size = node.input().get_output_layout().size.batch[0];
86 auto input_feature_size = node.input().get_output_layout().size.feature[0];
88 if(scale_batch_size != 1)
90 CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale batch size", scale_batch_size, "input batch size", input_batch_size, "");
93 if (scale_feature_size != 1)
95 CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale feature size", scale_feature_size, "input feature size", input_feature_size, "");
98 if (!argument.bias.empty())
100 auto bias_layout = node.bias().get_output_layout();
101 auto bias_format = bias_layout.format;
102 auto bias_raw_sizes = bias_layout.size.raw;
104 CLDNN_ERROR_NOT_PROPER_FORMAT(node.id(), "Scale format", scale_format.value, "bias format", bias_format);
106 for (size_t i = 0; i < bias_layout.size.raw.size(); ++i)
108 if (scale_layout.size.raw[i] != bias_raw_sizes[i])
109 CLDNN_ERROR_MESSAGE(node.id(), "Scale input size do not match bias size! Size index:" + std::to_string(i));