tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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") {
43  TVM_ATTR_FIELD(axis)
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.");
58  TVM_ATTR_FIELD(compute_dtype)
59  .set_default("None")
60  .describe(
61  "Specifies the data type used during requantize. Supported "
62  "options: \"int64\", \"float32\", \"float64\"");
63  TVM_ATTR_FIELD(out_dtype)
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].");
76  TVM_ATTR_FIELD(axis)
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") {
88  TVM_ATTR_FIELD(axis)
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> {
98  int axis;
99 
100  TVM_DECLARE_ATTRS(DequantizeAttrs, "relay.attrs.DequantizeAttrs") {
101  TVM_ATTR_FIELD(axis)
102  .describe(
103  "The channel axis for channel wise dequantization. Default value is -1,"
104  "which corresponds to the last axis.")
105  .set_default(-1);
106  }
107 };
108 
110 struct BroadcastAttrs : public tvm::AttrsNode<BroadcastAttrs> {
111  int lhs_axis;
112  int rhs_axis;
113 
114  TVM_DECLARE_ATTRS(BroadcastAttrs, "relay.attrs.BroadcastAttrs") {
115  TVM_ATTR_FIELD(lhs_axis)
116  .describe(
117  "The channel axis for channel wise broadcast. Default value is -1,"
118  "which corresponds to the last axis.")
119  .set_default(-1);
120  TVM_ATTR_FIELD(rhs_axis)
121  .describe(
122  "The channel axis for channel wise broadcast. Default value is -1,"
123  "which corresponds to the last axis.")
124  .set_default(-1);
125  }
126 };
127 
128 } // namespace qnn
129 } // namespace relay
130 } // namespace tvm
131 #endif // TVM_RELAY_QNN_ATTRS_H_
int lhs_axis
Definition: attrs.h:111
TVM_DECLARE_ATTRS(BroadcastAttrs, "relay.attrs.BroadcastAttrs")
Definition: attrs.h:114
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Attribute for broadcast operator.
Definition: attrs.h:110
std::string compute_dtype
Definition: attrs.h:39
Attribute for quantize operator.
Definition: attrs.h:70
Helpers for attribute objects.
int axis
Definition: attrs.h:85
std::string rounding
Definition: attrs.h:38
Runtime primitive data type.
Definition: data_type.h:41
int rhs_axis
Definition: attrs.h:112
Attribute for requantize operator.
Definition: attrs.h:36
Attribute for dequantize operator.
Definition: attrs.h:97
int axis
Definition: attrs.h:37
#define TVM_ATTR_FIELD(FieldName)
Declare an attribute field.
Definition: attrs.h:76
int axis
Definition: attrs.h:98
DataType out_dtype
Definition: attrs.h:71
TVM_DECLARE_ATTRS(QuantizeAttrs, "relay.attrs.QuantizeAttrs")
Definition: attrs.h:74
DataType NullValue< DataType >()
Definition: attrs.h:90
TVM_DECLARE_ATTRS(RequantizeAttrs, "relay.attrs.RequantizeAttrs")
Definition: attrs.h:42
int axis
Definition: attrs.h:72
TVM_DECLARE_ATTRS(SimulatedQuantizeAttrs, "relay.attrs.SimulatedQuantizeAttrs")
Definition: attrs.h:87
The base class of the all the Use "curiously recurring template pattern".
Definition: attrs.h:834
TVM_DECLARE_ATTRS(DequantizeAttrs, "relay.attrs.DequantizeAttrs")
Definition: attrs.h:100
DataType out_dtype
Definition: attrs.h:40