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_REDUCE_FUSION_H_ 18 #define MINDSPORE_CORE_OPS_REDUCE_FUSION_H_ 19 #include <map> 20 #include <vector> 21 #include <string> 22 #include <memory> 23 #include "ops/reduce.h" 24 #include "abstract/abstract_value.h" 25 #include "utils/check_convert_utils.h" 26 27 namespace mindspore { 28 namespace ops { 29 constexpr auto kNameReduceFusion = "ReduceFusion"; 30 /// \brief ReduceFusion defined Reduce operator prototype of lite. 31 class MS_CORE_API ReduceFusion : public Reduce { 32 public: 33 /// \brief Constructor. ReduceFusion()34 ReduceFusion() : Reduce(kNameReduceFusion) {} 35 36 /// \brief Destructor. 37 ~ReduceFusion() = default; 38 39 MS_DECLARE_PARENT(ReduceFusion, PrimitiveC); 40 41 /// \brief Method to init the op's attributes. 42 /// 43 /// \param[in] keep_dims Define a boolean value to indicate whether output dimension is kept or not. 44 /// \param[in] mode Define the concrete reduction mode. 45 /// \param[in] reduce_to_end Define a boolean value to indicate whether the operation need to do from the given axis 46 /// to the last. 47 /// \param[in] coeff Define a size factor applied to output. 48 void Init(const bool keep_dims = false, const ReduceMode mode = ReduceMode::Reduce_Mean, 49 const bool reduce_to_end = false, const float coeff = 1.0); 50 51 /// \brief Method to set keep_dims attribute. 52 /// 53 /// \param[in] keep_dims Define a boolean value to indicate whether output dimension is kept or not. 54 void set_keep_dims(const bool keep_dims); 55 56 /// \brief Method to set mode attribute. 57 /// 58 /// \param[in] mode Define the concrete reduction mode. 59 void set_mode(const ReduceMode mode); 60 61 /// \brief Method to set reduce_to_end attribute. 62 /// 63 /// \param[in] reduce_to_end Define a boolean value to indicate whether the operation need to do from the given axis 64 /// to the last. 65 void set_reduce_to_end(const bool reduce_to_end); 66 67 /// \brief Method to set coeff attribute. 68 /// 69 /// \param[in] coeff Define a size factor applied to output. 70 void set_coeff(const float coeff); 71 72 /// \brief Method to get keep_dims attribute. 73 /// 74 /// \return a boolean value. 75 bool get_keep_dims() const; 76 77 /// \brief Method to get mode attribute. 78 /// 79 /// \return reduction mode. 80 ReduceMode get_mode() const; 81 82 /// \brief Method to get reduce_to_end attribute. 83 /// 84 /// \return a boolean value. 85 bool get_reduce_to_end() const; 86 87 /// \brief Method to get coeff attribute. 88 /// 89 /// \return a size factor applied to output. 90 float get_coeff() const; 91 }; 92 AbstractBasePtr ReduceFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 93 const std::vector<AbstractBasePtr> &input_args); 94 using PrimReduceFusiuonPtr = std::shared_ptr<ReduceFusion>; 95 } // namespace ops 96 } // namespace mindspore 97 98 #endif // MINDSPORE_CORE_OPS_REDUCE_FUSION_H_ 99