-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Script] Add support for merging block annotations #18079
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
acbcaf7 to
947e5b8
Compare
| } | ||
| // Case 2.2: the values are not both dicts, check if the keys are the same | ||
| if (!ffi::AnyEqual()(old_value.value(), value)) { | ||
| LOG(FATAL) << "ValueError: Try to merge two annotations with different values for key `" |
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.
might be useful to cross check error reporting here, to make sure when error happens, we can locate the span and have right ^^^^^ to point at the code location. @Hzfengsy can you confirm?
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.
Confirmed it works well. Try with testcase:
from tvm.script import tir as T
@T.prim_func
def func3():
with T.block():
T.block_attr({"key1": "block1"})
T.block_attr({"key1": "block2"})
T.evaluate(0)get output:
error: Try to merge two annotations with different values for key `key1`, previous one is "block1", new one is "block2"
--> /path/to/tvm/t.py:7:9
|
7 | T.block_attr({"key1": "block2"})
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: run with `TVM_BACKTRACE=1` environment variable to display a backtrace.
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.
Also I added a test case to test the error in tests/python/tvmscript/test_tvmscript_error_report.py
This commit introduces functionality to merge block annotations in TVM script. The implementation includes: - MergeAnnotations function that recursively merges annotation dictionaries - Support for nested dictionary merging with new values overriding old ones - Error handling for conflicting annotation values - BlockAttrs function that uses the merging logic to combine multiple T.block_attr() calls within the same block The feature allows users to specify block attributes incrementally using multiple T.block_attr() calls, which will be automatically merged together.
947e5b8 to
cd54fcc
Compare
This commit introduces functionality to merge block annotations in TVM script. The implementation includes: - MergeAnnotations function that recursively merges annotation dictionaries - Support for nested dictionary merging with new values overriding old ones - Error handling for conflicting annotation values - BlockAttrs function that uses the merging logic to combine multiple T.block_attr() calls within the same block The feature allows users to specify block attributes incrementally using multiple T.block_attr() calls, which will be automatically merged together.
This commit introduces functionality to merge block annotations in TVM script. The implementation includes:
The feature allows users to specify block attributes incrementally using multiple T.block_attr() calls, which will be automatically merged together.