1 /**
2 * Copyright 2020-2021 Huawei Technologies Co., Ltd
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 "ops/fusion/activation.h"
18 #include <string>
19 #include <algorithm>
20 #include <memory>
21 #include <vector>
22 #include "ops/op_utils.h"
23
24 namespace mindspore {
25 namespace ops {
set_alpha(const float alpha)26 void Activation::set_alpha(const float alpha) { (void)this->AddAttr(kAlpha, MakeValue(alpha)); }
27
set_min_val(const float min_val)28 void Activation::set_min_val(const float min_val) { (void)this->AddAttr(kMinVal, MakeValue(min_val)); }
29
set_max_val(const float max_val)30 void Activation::set_max_val(const float max_val) { (void)this->AddAttr(kMaxVal, MakeValue(max_val)); }
31
set_activation_type(const ActivationType & activation_type)32 void Activation::set_activation_type(const ActivationType &activation_type) {
33 int64_t swi = activation_type;
34 (void)this->AddAttr(kActivationType, MakeValue(swi));
35 }
36
get_alpha() const37 float Activation::get_alpha() const {
38 auto value_ptr = this->GetAttr(kAlpha);
39 return GetValue<float>(value_ptr);
40 }
41
get_min_val() const42 float Activation::get_min_val() const {
43 auto value_ptr = this->GetAttr(kMinVal);
44 return GetValue<float>(value_ptr);
45 }
46
get_max_val() const47 float Activation::get_max_val() const {
48 auto value_ptr = this->GetAttr(kMaxVal);
49 return GetValue<float>(value_ptr);
50 }
51
get_activation_type() const52 ActivationType Activation::get_activation_type() const {
53 auto value_ptr = GetAttr(kActivationType);
54 return ActivationType(GetValue<int64_t>(value_ptr));
55 }
56
set_approximate(bool approximate)57 void Activation::set_approximate(bool approximate) { (void)this->AddAttr(kApproximate, MakeValue(approximate)); }
58
get_approximate() const59 bool Activation::get_approximate() const {
60 auto value_ptr = this->GetAttr(kApproximate);
61 return value_ptr != nullptr && GetValue<bool>(value_ptr);
62 }
63
Init(const float alpha,const float min_val,const float max_val,const ActivationType & activation_type,bool approximate)64 void Activation::Init(const float alpha, const float min_val, const float max_val,
65 const ActivationType &activation_type, bool approximate) {
66 this->set_alpha(alpha);
67 this->set_min_val(min_val);
68 this->set_max_val(max_val);
69 this->set_activation_type(activation_type);
70 this->set_approximate(approximate);
71 }
72 REGISTER_PRIMITIVE_C(kNameActivation, Activation);
73 } // namespace ops
74 } // namespace mindspore
75