-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add Python functor support for TIR expressions and statements #18060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces Python functor support for TIR expressions and statements by adding new C++ classes and corresponding Python bindings for both visitor and mutator patterns. It also updates import paths and macro formatting to align with the new functor dispatch design.
- Introduces PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++ and the necessary Python bindings.
- Updates module imports in the Python interface to reflect the new functor support.
- Adjusts macro formatting in the C++ header for clearer block structure.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tir/analysis/buffer_access_lca_detector.cc | Removes an unused lambda capture parameter to simplify the lambda. |
| python/tvm/tir/init.py | Adds imports for the new functor classes. |
| python/tvm/runtime/support.py | Introduces the derived_object decorator for TVM objects. |
| python/tvm/relax/expr_functor.py | Changes the derived_object import and corrects the order of imports. |
| include/tvm/relax/expr_functor.h | Adjusts macro formatting for improved readability. |
| const PrimExpr& binding) -> const ScopeInfo* { | ||
| const ScopeInfo* highest_scope = nullptr; | ||
| PostOrderVisit(binding, [this, &itervar, &highest_scope](const ObjectRef& obj) { | ||
| PostOrderVisit(binding, [this, &highest_scope](const ObjectRef& obj) { |
Copilot
AI
Jun 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda no longer uses the captured variable 'itervar'. Removing it from the capture list improves clarity and avoids potential confusion.
|
cc @jinhongyii |
40f6d9f to
14f0261
Compare
This commit introduces Python interfaces for TIR functors, enabling Python-side customization of expression and statement visiting and mutation operations. Key changes: - Add PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++ - Implement Python bindings for all TIR expression and statement types - Support both visitor (read-only) and mutator (transforming) patterns - Add comprehensive dispatch mechanisms for Python callbacks - Include FFI registrations for Python-C++ interoperability This enables users to write custom TIR transformations and analysis passes directly in Python while maintaining performance through selective Python callback dispatch.
…#18060) This commit introduces Python interfaces for TIR functors, enabling Python-side customization of expression and statement visiting and mutation operations. Key changes: - Add PyStmtExprVisitorNode and PyStmtExprMutatorNode classes in C++ - Implement Python bindings for all TIR expression and statement types - Support both visitor (read-only) and mutator (transforming) patterns - Add comprehensive dispatch mechanisms for Python callbacks - Include FFI registrations for Python-C++ interoperability This enables users to write custom TIR transformations and analysis passes directly in Python while maintaining performance through selective Python callback dispatch.
This commit introduces Python interfaces for TIR functors, enabling Python-side customization of expression and statement visiting and mutation operations.
Key changes:
This enables users to write custom TIR transformations and analysis passes directly in Python while maintaining performance through selective Python callback dispatch.