tqchen commented on PR #18172:
URL: https://github.com/apache/tvm/pull/18172#issuecomment-3132330099
Note for upgrading, typically for object, we need to
- Add `TVMFFISEqHashKind`, the most typical one would be
`kTVMFFISEqHashKindTreeNode`
- For AST that may defines a variable, add
`refl::AttachFieldFlag::SEqHashIgnore()` in extra of field def
- For fields that needs to be ignored, attach
`refl::AttachFieldFlag::SEqHashIgnore()`
It is also possible to define custom s_equal/reduce, see module.h for an
example
Some examples
```c++
/*! \brief range over one dimension */
class RangeNode : public Object {
public:
/*! \brief beginning of the node */
PrimExpr min;
/*! \brief the extend of range */
PrimExpr extent;
/*! \brief the location of this range in the source */
mutable Span span;
/*! \brief constructor */
RangeNode() {}
RangeNode(PrimExpr min, PrimExpr extent, Span span = Span())
: min(min), extent(extent), span(span) {}
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<RangeNode>()
.def_ro("min", &RangeNode::min)
.def_ro("extent", &RangeNode::extent)
.def_ro("span", &RangeNode::span,
refl::AttachFieldFlag::SEqHashIgnore());
}
static constexpr const char* _type_key = "ir.Range";
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind =
kTVMFFISEqHashKindTreeNode;
TVM_DECLARE_FINAL_OBJECT_INFO(RangeNode, Object);
};
```
```c++
class TFuncObj : public Object {
public:
Array<TVar> params;
Array<ObjectRef> body;
String comment;
TFuncObj(Array<TVar> params, Array<ObjectRef> body, String comment)
: params(params), body(body), comment(comment) {}
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
refl::ObjectDef<TFuncObj>()
.def_ro("params", &TFuncObj::params,
refl::AttachFieldFlag::SEqHashDef())
.def_ro("body", &TFuncObj::body)
.def_ro("comment", &TFuncObj::comment,
refl::AttachFieldFlag::SEqHashIgnore());
}
static constexpr const char* _type_key = "test.Func";
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind =
kTVMFFISEqHashKindTreeNode;
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(TFuncObj, Object);
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]