Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / activation_grad.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 "activation_grad_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 activation_grad_type_id()
25 {
26     static primitive_type_base<activation_grad> instance;
27     return &instance;
28 }
29
30 layout activation_grad_inst::calc_output_layout(activation_grad_node const& node)
31 {
32     assert((bool)node.get_primitive()->output_data_type == false
33            && "Output data type forcing is not supported for "
34               "activation_grad_node!");
35     return node.input().get_non_padded_output_layout();
36 }
37
38 std::string activation_grad_inst::to_string(activation_grad_node const& node)
39 {   
40     auto node_info = node.desc_to_json();
41     auto desc      = node.get_primitive();
42        
43     std::stringstream primitive_description;
44
45     json_composite activation_grad_info;
46     activation_grad_info.add("activation_grad_func", desc->activation_grad_func);
47     activation_grad_info.add("additional_params.a", desc->additional_params.a);
48     activation_grad_info.add("additional_params.b", desc->additional_params.b);
49     activation_grad_info.add("additional_params input", desc->additional_params_input);
50
51     node_info->add("activation_grad info", activation_grad_info);
52     node_info->dump(primitive_description);
53
54     return primitive_description.str();
55 }
56
57 activation_grad_inst::typed_primitive_inst(network_impl& network, activation_grad_node const& node)
58     : parent(network, node)
59 {
60     auto input_grad_arg  = node.input().get_output_layout();
61     auto input_arg = node.input_arg().get_output_layout();
62     auto output_arg = node.get_output_layout();
63     
64     CLDNN_ERROR_NOT_EQUAL(node.id(), "ReLU input_grad number", input_grad_arg.size.raw.size(), "ReLU input number", input_arg.size.raw.size(), "Relu input_grad/input num dismatch");
65     CLDNN_ERROR_NOT_EQUAL(node.id(), "ReLU input number", input_arg.size.raw.size(), "ReLU output number", output_arg.size.raw.size(), "Relu input/output num dismatch");
66
67     if (is_parameterized())
68     {
69         /// Slope input x dimension should be equal to input feature size (one slope per channel).
70         auto slope_input_size = node.slope_input().get_output_layout().size;
71         auto input_feature_size = node.input().get_output_layout().size.feature[0];
72
73         CLDNN_ERROR_LESS_THAN(node.id(), "Slope x size", slope_input_size.spatial[0], "input feature size", input_feature_size, "Dimensions mismatch between input and slope input in Activation layer(slope x size should be equal to input feature size)!");
74
75         // All other dimensions should be 1
76         CLDNN_ERROR_NOT_EQUAL(node.id(), "Slope input size count", slope_input_size.count(), "Slope input size x", slope_input_size.spatial[0], "Dimensions mismatch of slope input in Activation layer!");
77     }
78 }
79 }