-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[microNPU] Add MergeConstants pass #12029
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -938,3 +938,38 @@ def CopyComputeReordering(max_copy_movements: Optional[int] = None) -> tvm.IRMod | |
The new module with copy and compute nodes reordered. | ||
""" | ||
return _ffi_api.CopyComputeReordering(max_copy_movements) | ||
|
||
|
||
def MergeConstants(const_dict): | ||
""" | ||
This pass looks for the constants used by each compute operator | ||
and merges them into a single buffer. | ||
Constants written to a buffer with local scope are not merged. | ||
""" | ||
|
||
def mergeConstantsPass(mod): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style : this should be lower case. https://peps.python.org/pep-0008/#function-and-variable-names (Only exception is the Passes because we want them aligned with C++ ones and I think the from API PoV the accessible pass function should be MergeConstants) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
nonlocal const_dict | ||
try: | ||
mod["main"] | ||
except: | ||
raise tvm.TVMError( | ||
"Expected a single primitive function called 'main'. " | ||
"Please run the MergeConstants pass in conjunction with the LowerToTIR() pass." | ||
) | ||
|
||
new_const_dict = {} | ||
for param in const_dict.keys(): | ||
new_const_dict[tvm.tir.IntImm("int64", param)] = tvm.nd.array(const_dict[param]) | ||
mod["main"] = mod["main"].with_attr("ethos-u.const-dict", new_const_dict) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit : lets stick to const_dict There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
mod = _ffi_api.MergeConstants()(mod) | ||
const_dict = mod["main"].attrs["ethos-u.const-dict"] | ||
mod = _ffi_api.RemoveConstDictAttribute()(mod) | ||
|
||
new_const_dict = {} | ||
for param in const_dict.keys(): | ||
new_const_dict[int(param)] = const_dict[param].numpy() | ||
|
||
return mod, new_const_dict | ||
|
||
return mergeConstantsPass |
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.
Please leave a comment that MergeConstant pass currently does not support striped schedules and requires further investigation.