tvm
affine_type.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_IR_AFFINE_TYPE_H_
25 #define TVM_IR_AFFINE_TYPE_H_
26 
27 #include <tvm/ir/expr.h>
28 #include <tvm/ir/type.h>
29 
30 namespace tvm {
31 
36 class AffineTypeNode : public Object {
37  public:
42  mutable Span span;
43 
44  static constexpr const char* _type_key = "AffineType";
45  static constexpr const bool _type_has_method_sequal_reduce = true;
46  static constexpr const bool _type_has_method_shash_reduce = true;
48 };
49 
54 class AffineType : public ObjectRef {
55  public:
57 };
58 
67  public:
75  int axis;
76 
78  v->Visit("scale", &scale);
79  v->Visit("zero_point", &zero_point);
80  v->Visit("dtype", &dtype);
81  v->Visit("axis", &axis);
82  }
83 
85  equal->MarkGraphNode();
86  return equal(scale, other->scale) && equal(zero_point, other->zero_point) &&
87  equal(dtype, other->dtype) && equal(axis, other->axis);
88  }
89 
90  void SHashReduce(SHashReducer hash_reduce) const {
91  hash_reduce->MarkGraphNode();
92  hash_reduce(scale);
93  hash_reduce(zero_point);
94  hash_reduce(dtype);
95  hash_reduce(axis);
96  }
97 
98  static constexpr const char* _type_key = "TensorAffineType";
100 };
101 
106 class TensorAffineType : public AffineType {
107  public:
108  TVM_DLL TensorAffineType(RelayExpr scale, RelayExpr zero_point, DataType dtype, int axis);
109 
111 };
112 
118  public:
121 
122  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("types", &types); }
123 
125  equal->MarkGraphNode();
126  return equal(types, other->types);
127  }
128 
129  void SHashReduce(SHashReducer hash_reduce) const {
130  hash_reduce->MarkGraphNode();
131  hash_reduce(types);
132  }
133 
134  static constexpr const char* _type_key = "TupleAffineType";
136 };
137 
142 class TupleAffineType : public AffineType {
143  public:
145 
147 };
148 
149 } // namespace tvm
150 #endif // TVM_IR_AFFINE_TYPE_H_
AffineType representation.
Definition: affine_type.h:36
TVM_DECLARE_BASE_OBJECT_INFO(AffineTypeNode, Object)
static constexpr const bool _type_has_method_shash_reduce
Definition: affine_type.h:46
Span span
Span that points to the original source code. Reserved debug information.
Definition: affine_type.h:42
static constexpr const bool _type_has_method_sequal_reduce
Definition: affine_type.h:45
static constexpr const char * _type_key
Definition: affine_type.h:44
Managed reference to AffineTypeNode.
Definition: affine_type.h:54
TVM_DEFINE_OBJECT_REF_METHODS(AffineType, ObjectRef, AffineTypeNode)
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Managed reference to RelayExprNode.
Definition: expr.h:442
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:137
virtual void MarkGraphNode()=0
Mark current comparison as graph node in hashing. Graph node hash will depends on the graph structure...
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:121
Definition: source_map.h:120
TensorAffineType representation.
Definition: affine_type.h:66
TVM_DECLARE_BASE_OBJECT_INFO(TensorAffineTypeNode, AffineTypeNode)
void SHashReduce(SHashReducer hash_reduce) const
Definition: affine_type.h:90
void VisitAttrs(tvm::AttrVisitor *v)
Definition: affine_type.h:77
RelayExpr zero_point
The zero point of this type.
Definition: affine_type.h:71
int axis
The axis for per-channel quantization.
Definition: affine_type.h:75
RelayExpr scale
The scale of this type.
Definition: affine_type.h:69
bool SEqualReduce(const TensorAffineTypeNode *other, SEqualReducer equal) const
Definition: affine_type.h:84
DataType dtype
The data type of this type.
Definition: affine_type.h:73
static constexpr const char * _type_key
Definition: affine_type.h:98
Managed reference to AffineTypes.
Definition: affine_type.h:106
TensorAffineType(RelayExpr scale, RelayExpr zero_point, DataType dtype, int axis)
TVM_DEFINE_OBJECT_REF_METHODS(TensorAffineType, AffineType, TensorAffineTypeNode)
TupleAffineType representation.
Definition: affine_type.h:117
Array< TensorAffineType > types
The types of this tuple.
Definition: affine_type.h:120
bool SEqualReduce(const TupleAffineTypeNode *other, SEqualReducer equal) const
Definition: affine_type.h:124
void SHashReduce(SHashReducer hash_reduce) const
Definition: affine_type.h:129
TVM_DECLARE_BASE_OBJECT_INFO(TupleAffineTypeNode, AffineTypeNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: affine_type.h:122
static constexpr const char * _type_key
Definition: affine_type.h:134
Managed reference to TupleAffineTypes.
Definition: affine_type.h:142
TVM_DEFINE_OBJECT_REF_METHODS(TupleAffineType, AffineType, TupleAffineTypeNode)
TupleAffineType(Array< TensorAffineType > types)
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:43
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Base expr nodes in TVM.
IR/AST nodes for the unified type system in TVM.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal