You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2025/07/29 12:34:39 UTC

[PR] [REFACTOR][FFI] Phase out SEqualReduce/SHashReduce [tvm]

tqchen opened a new pull request, #18172:
URL: https://github.com/apache/tvm/pull/18172

   This PR phases out old SEqualReduce/SHashReduce mechanism in favor of the new reflection mechanism via ffi/reflection. It helps us to reduce the places we need to register the reflection related information.
   
   See the current IR examples for upgrading to the new mechanism.


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [REFACTOR][FFI] Phase out SEqualReduce/SHashReduce [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [REFACTOR][FFI] Phase out SEqualReduce/SHashReduce [tvm]

Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 merged PR #18172:
URL: https://github.com/apache/tvm/pull/18172


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org