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 ///////////////////////////////////////////////////////////////////////////////////////////////////
19 #include "../C/activation.h"
20 #include "primitive.hpp"
24 /// @addtogroup cpp_api C++ API
26 /// @addtogroup cpp_topology Network Topology
28 /// @addtogroup cpp_primitives Primitives
31 /// @brief Activation using rectified linear unit or parameterized rectified linear unit.
32 /// @details Can get one negative slope or negative slope per channel.
34 /// out(i,x,y) = max(0, in(i,x,y)) + slope(i) * min(0, in(i,x,y))
36 /// @li out(i,x,y) : value at x, y from i-th feature map after activation.
37 /// @li in(i,x,y) : value at x, y from i-th feature map before activation.
38 /// @li slope(i) : the slope value of the i-th feature map (can be shared across channels or one slope per channel).
39 struct activation : public primitive_base<activation, CLDNN_PRIMITIVE_DESC(activation)>
41 CLDNN_DECLARE_PRIMITIVE(activation)
43 /// @brief Constructs Relu primitive.
44 /// @param id This primitive id.
45 /// @param input Input primitive id.
46 /// @param activation_func activation function.
47 /// @param additional_params additional params (slope/max_val/linear a,b).
49 const primitive_id& id,
50 const primitive_id& input,
51 cldnn_activation_func activation_func,
52 cldnn_activation_additional_params additional_params = { 0.f,0.f },
53 const padding& output_padding = padding()
55 : primitive_base(id, {input}, output_padding)
56 , activation_func(activation_func)
57 , additional_params(additional_params)
58 , additional_params_input("")
62 /// @brief Constructs activation with input per feature.
63 /// @param id This primitive id.
64 /// @param input Input primitive id.
65 /// @param additional_params_input additional params stored on a memory.
66 /// Input x dimension should be equal to input feature size (one value per channel. in case of linear is one pair per channel).
67 /// All other dimensions should be 1.
69 const primitive_id& id,
70 const primitive_id& input,
71 const primitive_id& additional_params_input,
72 cldnn_activation_func activation_func,
73 const padding& output_padding = padding()
75 : primitive_base(id, { input }, output_padding)
76 , activation_func(activation_func)
77 , additional_params({ 0,0 })
78 , additional_params_input(additional_params_input)
82 /// @brief Constructs a copy from basic C API @CLDNN_PRIMITIVE_DESC{activation}
83 activation(const dto* dto)
85 , activation_func(dto->activation_func)
86 , additional_params(dto->additional_params)
87 , additional_params_input(dto->additional_params_input)
91 /// @brief activation function.
92 cldnn_activation_func activation_func;
94 /// @brief activation additional params.
95 cldnn_activation_additional_params additional_params;
97 /// @brief PRelu activation slope input primitive id.
98 /// Input x dimension should be equal to input feature size (one slope per channel).
99 /// All other dimensions should be 1.
100 primitive_id additional_params_input;
104 std::vector<std::reference_wrapper<const primitive_id>> get_dependencies() const override
106 if (additional_params_input.empty())
108 return{ additional_params_input };
111 void update_dto(dto& dto) const override
113 dto.activation_func = activation_func;
114 dto.additional_params = additional_params;
115 dto.additional_params_input = additional_params_input.c_str();