• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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_DYNAMIC_QUANT_H_
18 #define MINDSPORE_CORE_OPS_DYNAMIC_QUANT_H_
19 
20 #include <algorithm>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "mindapi/base/types.h"
27 #include "ops/base_operator.h"
28 
29 namespace mindspore {
30 namespace ops {
31 constexpr auto kNameDynamicQuant = "DynamicQuant";
32 /// \brief the DynamicQuant operator prototype.
33 class MIND_API DynamicQuant : public BaseOperator {
34  public:
35   MIND_API_BASE_MEMBER(DynamicQuant);
36   /// \brief Constructor.
DynamicQuant()37   DynamicQuant() : BaseOperator(kNameDynamicQuant) {}
38 
39   /// \brief Method to init the op's attributes.
40   ///
41   /// \param[in] symmetric Define whether symmetric quantization.
42   /// \param[in] dst_type Define the data type of output.
43   void Init(const bool symmetric, const int64_t dst_type);
44 
45   /// \brief Method to set symmetric attribute.
46   ///
47   /// \param[in] symmetric Define whether symmetric quantization.
48   void set_symmetric(const bool symmetric);
49 
50   /// \brief Method to get symmetric attribute.
51   ///
52   /// \return Whether symmetric quantization.
53   bool get_symmetric() const;
54 
55   /// \brief Method to set dst_type attribute.
56   ///
57   /// \param[in] dst_type Define the data type of output.
58   void set_dst_type(const int64_t dst_type);
59 
60   /// \brief Method to get dst_type attribute.
61   ///
62   /// \return the data type of output.
63   int64_t get_dst_type() const;
64 
65   /// \brief Method to set prefer_axis attribute.
66   ///
67   /// \param[in] prefer_axis Define the preferred axis.
68   void set_prefer_axis(const int64_t prefer_axis);
69 
70   /// \brief Method to get prefer_axis attribute.
71   ///
72   /// \return the preferred axis.
73   int64_t get_prefer_axis() const;
74 
75   /// \brief Method to set activation_channel attribute.
76   ///
77   /// \param[in] activation_channel Define whether activation perchannel quantization.
78   void set_activation_channel(const bool activation_channel);
79 
80   /// \brief Method to get activation_channel attribute.
81   ///
82   /// \return Whether activation perchannel quantization.
83   bool get_activation_channel() const;
84 
85   /// \brief Method to set transpose attribute.
86   ///
87   /// \param[in] symmetric Define whether transpose matrix.
88   void set_transpose(const bool transpose);
89 
90   /// \brief Method to get transpose attribute.
91   ///
92   /// \return Whether transpose matrix.
93   bool get_transpose() const;
94 
95   /// \brief Method to set prefer_axis attribute.
96   ///
97   /// \param[in] prefer_axis Define the preferred axis.
98   void set_prefer_axes(const std::vector<int> &prefer_axes);
99 
100   /// \brief Method to get prefer_axis attribute.
101   ///
102   /// \return the preferred axis.
103   std::vector<int> get_prefer_axes() const;
104 };
105 MIND_API abstract::AbstractBasePtr DynamicQuantInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
106                                                      const std::vector<abstract::AbstractBasePtr> &input_args);
107 }  // namespace ops
108 }  // namespace mindspore
109 
110 #endif  // MINDSPORE_CORE_OPS_QUANTD_TYPE_CAST_H_
111