Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / scale_grad_input.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 #include "scale_grad_input_inst.h"
18 #include "primitive_type_base.h"
19 #include "error_handler.h"
20 #include "json_object.h"
21
22 namespace cldnn
23 {
24     primitive_type_id scale_grad_input_type_id()
25     {
26         static primitive_type_base<scale_grad_input> instance;
27         return &instance;
28     }
29
30     layout scale_grad_input_inst::calc_output_layout(scale_grad_input_node const& node)
31     {
32         assert((bool)node.get_primitive()->output_data_type == false
33                && "Output data type forcing is not supported for "
34                   "scale_grad_input_node!");
35         auto result = node.input().get_non_padded_output_layout();
36
37         auto scale_in_sizes = node.scale_in().get_non_padded_output_layout().size;
38         auto input_sizes = result.size;
39
40         auto scale_in_x_size = scale_in_sizes.spatial[0];
41         auto scale_in_y_size = scale_in_sizes.spatial[1];
42
43         auto input_x_size = input_sizes.spatial[0];
44         auto input_y_size = input_sizes.spatial[1];
45
46         if (scale_in_x_size != 1)
47         {
48             CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale x size", scale_in_x_size, "input x size", input_x_size, "");
49         }
50         if (scale_in_y_size != 1)
51         {
52             CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale y size", scale_in_y_size, "input y size", input_y_size, "");
53         }
54
55         return result;
56     }
57
58     std::string scale_grad_input_inst::to_string(scale_grad_input_node const& node)
59     {
60         auto desc = node.get_primitive();
61         auto node_info = node.desc_to_json();
62         auto& input = node.input();
63         auto& scale_input = node.scale_in();
64
65         std::stringstream primitive_description;
66
67         json_composite scale_grad_input_info;
68         scale_grad_input_info.add("input", input.id());
69         scale_grad_input_info.add("scale input", scale_input.id());
70
71         node_info->add("scale_grad_input info", scale_grad_input_info);
72         node_info->dump(primitive_description);
73
74         return primitive_description.str();
75     }
76
77     scale_grad_input_inst::typed_primitive_inst(network_impl& network, scale_grad_input_node const& node)
78         :parent(network, node)
79     {
80         auto scale_input_layout = node.scale_in().get_output_layout();
81         auto scale_input_batch_size = scale_input_layout.size.batch[0];
82         auto scale_input_feature_size = scale_input_layout.size.feature[0];
83
84         auto input_layout = node.input().get_output_layout();
85         auto input_batch_size = input_layout.size.batch[0];
86         auto input_feature_size = input_layout.size.feature[0];
87
88         if (scale_input_batch_size != 1)
89         {
90             CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale batch size", scale_input_batch_size, "input batch size", input_batch_size, "");
91         }
92
93         if (scale_input_feature_size != 1)
94         {
95             CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale feature size", scale_input_feature_size, "input feature size", input_feature_size, "");
96         }
97     }
98 }