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 #ifndef MINDSPORE_CORE_OPS_ACTIVATION_H_ 18 #define MINDSPORE_CORE_OPS_ACTIVATION_H_ 19 #include "ops/primitive_c.h" 20 #include "abstract/abstract_value.h" 21 #include "utils/check_convert_utils.h" 22 23 namespace mindspore { 24 namespace ops { 25 constexpr auto kNameActivation = "Activation"; 26 /// \brief Activation defined Activation operator prototype of lite. 27 class MS_CORE_API Activation : public PrimitiveC { 28 public: 29 /// \brief Constructor. Activation()30 Activation() : PrimitiveC(kNameActivation) {} 31 32 /// \brief Destructor. 33 ~Activation() = default; 34 35 MS_DECLARE_PARENT(Activation, PrimitiveC); 36 37 /// \brief Method to init the op's attributes. 38 /// 39 /// \param[in] alpha Define a size factor. 40 /// \param[in] min_val Define a lower bound. 41 /// \param[in] max_val Define a upper bound. 42 /// \param[in] activation_type Define the activation type. 43 /// \param[in] approximate Define a boolean value to decide whether to use an approximate algorithm, only useful for 44 /// GELU. 45 void Init(const float alpha = 0.2, const float min_val = -1.0, const float max_val = 1.0, 46 const ActivationType &activation_type = NO_ACTIVATION, bool approximate = false); 47 48 /// \brief Method to set alpha attribute. 49 /// 50 /// \param[in] alpha Define a size factor. 51 void set_alpha(const float alpha); 52 53 /// \brief Method to set min_val attribute. 54 /// 55 /// \param[in] min_val Define a lower bound. 56 void set_min_val(const float min_val); 57 58 /// \brief Method to set max_val attribute. 59 /// 60 /// \param[in] max_val Define a upper bound. 61 void set_max_val(const float max_val); 62 63 /// \brief Method to set activation type. 64 /// 65 /// \param[in] activation_type Define the activation type. 66 void set_activation_type(const ActivationType &activation_type); 67 68 /// \brief Method to get alpha attribute. 69 /// 70 /// \return alpha attribute. 71 float get_alpha() const; 72 73 /// \brief Method to get min_val attribute. 74 /// 75 /// \return min_val attribute. 76 float get_min_val() const; 77 78 /// \brief Method to get max_val attribute. 79 /// 80 /// \return max_val attribute. 81 float get_max_val() const; 82 83 /// \brief Method to get activation type. 84 /// 85 /// \return activation type. 86 ActivationType get_activation_type() const; 87 88 /// \brief Method to set approximate attribute. 89 /// 90 /// \param[in] approximate Define a boolean value to decide whether to use an approximate algorithm, only useful for 91 /// GELU. 92 void set_approximate(bool approximate); 93 94 /// \brief Method to get approximate attribute. 95 /// 96 /// \return approximate attribute. 97 bool get_approximate() const; 98 }; 99 } // namespace ops 100 } // namespace mindspore 101 102 #endif // MINDSPORE_CORE_OPS_ACTIVATION_H_ 103