2 // Copyright (c) 2018 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 "activation_grad_inst.h"
18 #include "primitive_type_base.h"
19 #include "error_handler.h"
20 #include "json_object.h"
24 primitive_type_id activation_grad_type_id()
26 static primitive_type_base<activation_grad> instance;
30 layout activation_grad_inst::calc_output_layout(activation_grad_node const& node)
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();
38 std::string activation_grad_inst::to_string(activation_grad_node const& node)
40 auto node_info = node.desc_to_json();
41 auto desc = node.get_primitive();
43 std::stringstream primitive_description;
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);
51 node_info->add("activation_grad info", activation_grad_info);
52 node_info->dump(primitive_description);
54 return primitive_description.str();
57 activation_grad_inst::typed_primitive_inst(network_impl& network, activation_grad_node const& node)
58 : parent(network, node)
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();
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");
67 if (is_parameterized())
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];
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)!");
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!");