tvm
attrs.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_RELAY_QNN_ATTRS_H_
25 #define TVM_RELAY_QNN_ATTRS_H_
26 
27 #include <tvm/ir/attrs.h>
28 
29 #include <string>
30 
31 namespace tvm {
32 namespace relay {
33 namespace qnn {
34 
36 struct RequantizeAttrs : public tvm::AttrsNode<RequantizeAttrs> {
37  int axis;
38  std::string rounding;
39  std::string compute_dtype;
41 
42  TVM_DECLARE_ATTRS(RequantizeAttrs, "relay.attrs.RequantizeAttrs") {
44  .describe(
45  "The output channel axis for channel wise quantization. Default value is -1,"
46  "which corresponds to the last axis.")
47  .set_default(-1);
48  TVM_ATTR_FIELD(rounding).set_default("None").describe(
49  "Defines the rounding direction when the value is midway between"
50  "two representable values. There are two supported modes - UPWARD"
51  "or TONEAREST. Both modes behave exactly same except at the"
52  "midpoints between the two representable values. At the midpoint,"
53  "UPWARD rounds towards positive infinity (for example -1.5 will be"
54  "rounded to -1). TONEAREST is the standard rounding where the"
55  "value is rounded away from zero at midpoints (for example, -1.5"
56  "rounds to -2). More context can be found at following gblic manual"
57  "https://www.gnu.org/software/libc/manual/html_node/Rounding.html.");
59  .set_default("None")
60  .describe(
61  "Specifies the data type used during requantize. Supported "
62  "options: \"int64\", \"float32\", \"float64\"");
64  .set_default(NullValue<DataType>())
65  .describe("Output data type, set to explicit type under mixed precision setting");
66  }
67 };
68 
70 struct QuantizeAttrs : public tvm::AttrsNode<QuantizeAttrs> {
72  int axis;
73 
74  TVM_DECLARE_ATTRS(QuantizeAttrs, "relay.attrs.QuantizeAttrs") {
75  TVM_ATTR_FIELD(out_dtype).describe("Output data type, can be one of [int8 or uint8].");
77  .describe(
78  "The output channel axis for channel wise quantization. Default value is -1,"
79  "which corresponds to the last axis.")
80  .set_default(-1);
81  }
82 };
83 
84 struct SimulatedQuantizeAttrs : public tvm::AttrsNode<SimulatedQuantizeAttrs> {
85  int axis;
86 
87  TVM_DECLARE_ATTRS(SimulatedQuantizeAttrs, "relay.attrs.SimulatedQuantizeAttrs") {
89  .describe(
90  "The output channel axis for channel wise quantization. Default value is -1,"
91  "which corresponds to the last axis.")
92  .set_default(-1);
93  }
94 };
95 
97 struct DequantizeAttrs : public tvm::AttrsNode<DequantizeAttrs> {
99  int axis;
100 
101  TVM_DECLARE_ATTRS(DequantizeAttrs, "relay.attrs.DequantizeAttrs") {
102  TVM_ATTR_FIELD(out_dtype).describe("Output data type, can be one of [float16, float32].");
104  .describe(
105  "The channel axis for channel wise dequantization. Default value is -1,"
106  "which corresponds to the last axis.")
107  .set_default(-1);
108  }
109 };
110 
112 struct BroadcastAttrs : public tvm::AttrsNode<BroadcastAttrs> {
113  int lhs_axis;
114  int rhs_axis;
115 
116  TVM_DECLARE_ATTRS(BroadcastAttrs, "relay.attrs.BroadcastAttrs") {
118  .describe(
119  "The channel axis for channel wise broadcast. Default value is -1,"
120  "which corresponds to the last axis.")
121  .set_default(-1);
123  .describe(
124  "The channel axis for channel wise broadcast. Default value is -1,"
125  "which corresponds to the last axis.")
126  .set_default(-1);
127  }
128 };
129 
130 } // namespace qnn
131 } // namespace relay
132 } // namespace tvm
133 #endif // TVM_RELAY_QNN_ATTRS_H_
The base class of the all the Use "curiously recurring template pattern".
Definition: attrs.h:870
Runtime primitive data type.
Definition: data_type.h:43
Helpers for attribute objects.
#define TVM_ATTR_FIELD(FieldName)
Declare an attribute field.
Definition: attrs.h:76
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
DataType NullValue< DataType >()
Definition: attrs.h:90
Attribute for broadcast operator.
Definition: attrs.h:112
TVM_DECLARE_ATTRS(BroadcastAttrs, "relay.attrs.BroadcastAttrs")
Definition: attrs.h:116
int lhs_axis
Definition: attrs.h:113
int rhs_axis
Definition: attrs.h:114
Attribute for dequantize operator.
Definition: attrs.h:97
int axis
Definition: attrs.h:99
TVM_DECLARE_ATTRS(DequantizeAttrs, "relay.attrs.DequantizeAttrs")
Definition: attrs.h:101
DataType out_dtype
Definition: attrs.h:98
Attribute for quantize operator.
Definition: attrs.h:70
TVM_DECLARE_ATTRS(QuantizeAttrs, "relay.attrs.QuantizeAttrs")
Definition: attrs.h:74
DataType out_dtype
Definition: attrs.h:71
int axis
Definition: attrs.h:72
Attribute for requantize operator.
Definition: attrs.h:36
int axis
Definition: attrs.h:37
DataType out_dtype
Definition: attrs.h:40
std::string compute_dtype
Definition: attrs.h:39
std::string rounding
Definition: attrs.h:38
TVM_DECLARE_ATTRS(RequantizeAttrs, "relay.attrs.RequantizeAttrs")
Definition: attrs.h:42
TVM_DECLARE_ATTRS(SimulatedQuantizeAttrs, "relay.attrs.SimulatedQuantizeAttrs")
Definition: attrs.h:87
int axis
Definition: attrs.h:85