• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_AVG_POOL_FUSION_H_
18 #define MINDSPORE_CORE_OPS_AVG_POOL_FUSION_H_
19 #include <memory>
20 #include <vector>
21 #include "ops/base_operator.h"
22 #include "mindapi/base/types.h"
23 #include "mindapi/base/format.h"
24 
25 namespace mindspore {
26 namespace ops {
27 constexpr auto kNameAvgPoolFusion = "AvgPoolFusion";
28 /// \brief AvgPoolFusion defined AvgPool operator prototype of lite.
29 class MIND_API AvgPoolFusion : public BaseOperator {
30  public:
31   MIND_API_BASE_MEMBER(AvgPoolFusion);
32   /// \brief Constructor.
AvgPoolFusion()33   AvgPoolFusion() : BaseOperator(kNameAvgPoolFusion) { InitIOName({"x"}, {"output"}); }
34 
35   /// \brief Method to init the op's attributes.
36   ///
37   /// \param[in] kernel_size Define the size of the kernel.
38   /// \param[in] stride Define the moving size of the kernel.
39   /// \param[in] pad_mode Define the padding method.
40   /// \param[in] format Define the format of input tensor.
41   /// \param[in] pad Define the concrete padding value on each dimension
42   /// \param[in] round_mode Define numerical operation mode of the output tensor.
43   /// \param[in] global Define a boolean value to indicate whether to do global pooling. If true, kernel_size will be
44   ///            useless.
45   /// \param[in] activation_type Define the activation type.
46   void Init(const std::vector<int64_t> &kernel_size = {1}, const std::vector<int64_t> &stride = {1},
47             const PadMode &pad_mode = VALID, const Format &format = NCHW,
48             const std::vector<int64_t> &pad = {0, 0, 0, 0}, const RoundMode &round_mode = RoundMode::FLOOR,
49             const bool global = false, const ActivationType activation_type = NO_ACTIVATION);
50 
51   /// \brief Set pad_mode.
52   void set_pad_mode(const int64_t &pad_mode);
53   /// \brief Set kernel_size.
54   void set_kernel_size(const std::vector<int64_t> &kernel_size);
55   /// \brief Set strides.
56   void set_strides(const std::vector<int64_t> &strides);
57   /// \brief Set format.
58   void set_data_format(const int64_t &data_format);
59   /// \brief Set pad.
60   void set_pad(const std::vector<int64_t> &pad);
61   /// \brief Set round_mode.
62   void set_round_mode(const int64_t &round_mode);
63 
64   /// \brief Get kernel_size.
65   ///
66   /// \return kernel_size.
67   std::vector<int64_t> get_kernel_size() const;
68   /// \brief Get strides.
69   ///
70   /// \return strides.
71   std::vector<int64_t> get_strides() const;
72   /// \brief Get pad_mode.
73   ///
74   /// \return pad_mode.
75   int64_t get_pad_mode() const;
76   /// \brief Get format.
77   ///
78   /// \return format.
79   int64_t get_data_format() const;
80   /// \brief Get pad.
81   ///
82   /// \return pad.
83   std::vector<int64_t> get_pad() const;
84   /// \brief Get round_mode.
85   ///
86   /// \return round_mode.
87   int64_t get_round_mode() const;
88 
89   /// \brief Method to set global attribute.
90   ///
91   /// \param[in] global Define a boolean value to indicate whether to do global pooling. If true, kernel_size will be
92   ///            useless.
93   void set_global(const bool global);
94 
95   /// \brief Method to set activation type.
96   ///
97   /// \param[in] activation_type Define the activation type.
98   void set_activation_type(const ActivationType activation_type);
99 
100   /// \brief Method to get global attribute.
101   ///
102   /// \return a boolean value to indicate whether to do global pooling. If true, kernel_size will be useless.
103   bool get_global() const;
104 
105   /// \brief Method to get activation type.
106   ///
107   /// \return activation type.
108   ActivationType get_activation_type() const;
109 };
110 
111 abstract::AbstractBasePtr AvgPoolFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
112                                              const std::vector<abstract::AbstractBasePtr> &input_args);
113 }  // namespace ops
114 }  // namespace mindspore
115 
116 #endif  // MINDSPORE_CORE_OPS_AVG_POOL_FUSION_H_
117