Memory planning: Support shared_allocation with offset - #21840
Memory planning: Support shared_allocation with offset#21840Erik-Lundell wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21840
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 0f4e271 with merge base 79e3eae ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Previously, there was a mechanism that let passes annotate nodes with a meta field "_share_alloc_with_arg_idx", to indicate to memory planning algorithms that a node output tensor is shared. Generalize this by adding the meta field "_shared_alloc_offset", to allow setting an offset from the base shared allocation. This meta is picked up by the MemoryPlanningPass, and transfered to the TensorSpec. To do this, a new field "storage_base_offset" is added to the TensorSpec. "inplace_base" is renamed to "storage_base", while keeping a inplace_base as an alias. When inplace_base is used, the storage_base_offset is not allowed to be non-zero. This work exposed an issue where planning of inplace_base/storage_base backing tensors didn't respect the lifetimes of backed tensors. Fix this by extending lifetimes accordingly in update_all_tensors_lifetime. Handling of unexpected values of TensorSpec in _move_memory_meta_to_spec were also changed to errors instead of silent returns. Finally, modify the greedy algorithm to respect the new offset. Signed-off-by: Erik Lundell <erik.lundell@arm.com> Change-Id: I8d8348487aaf0d29e87fbcc563183b1d9c1d73b1
|
@claude review this PR |
|
Claude finished @Erik-Lundell's task in 3m 25s —— View job PR Review: Memory planning —
|
Previously, there was a mechanism that let
passes annotate nodes with a meta field
"_share_alloc_with_arg_idx", to indicate to
memory planning algorithms that a node output
tensor is shared. Generalize this by adding
the meta field "_shared_alloc_offset", to allow
setting an offset from the base shared allocation.
This meta is picked up by the MemoryPlanningPass,
and transfered to the TensorSpec. To do this,
a new field "storage_base_offset" is added to the
TensorSpec. "inplace_base" is renamed to
"storage_base", while keeping a inplace_base as
an alias. When inplace_base
is used, the storage_base_offset is not allowed
to be non-zero.
This work exposed an issue where planning of
inplace_base/storage_base backing tensors didn't
respect the lifetimes of backed tensors. Fix
this by extending lifetimes accordingly in
update_all_tensors_lifetime. Handling of unexpected values of TensorSpec in _move_memory_meta_to_spec
were also changed to errors instead of silent
returns.
Finally, modify the greedy algorithm to respect
the new offset.
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani