Repository navigation
Assign optimal affinities to allocations during ScheduleAllocation. - #20965
Merged
Merged
Conversation
benvanik
force-pushed
the
users/benvanik/optimal-alloca
branch
2 times, most recently
from
June 2, 2025 18:56
71cc8c8 to
be7f79a
Compare
benvanik
force-pushed
the
users/benvanik/optimal-alloca
branch
from
June 2, 2025 20:37
be7f79a to
8d79459
Compare
benvanik
marked this pull request as ready for review
June 2, 2025 21:42
hanhanW
approved these changes
Jun 3, 2025
| util.global private @device_b : !hal.device | ||
|
|
||
| // CHECK-LABEL: @file_constant_optimal | ||
| // CHECK-SAME: (%[[BUFFER:.+]]: !util.buffer) |
Contributor
There was a problem hiding this comment.
Just sharing a tip: I usually match %[[BUFFER:[a-zA-Z0-9]+]] to get rid of matching the argument type. It is very useful when there are multiple function arguments.
Collaborator
Author
There was a problem hiding this comment.
I've dreamed of a shorthand for that - like [[BUFFER:\id]] or something. It's such a common thing in these tests that it always feels silly we have to spell out the regex!
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
…20965) Updates affinity analysis to better track operand/result usage independently from execution scope particularly with pinned ops. The improved tracking enables ScheduleAllocationPass to now join all potential affinities a result will be used on to produce the affinity for each allocation whether they are transients or constants/variables. By performing analysis at the point immediately prior to going from `stream.async.*` (with all optimizations/transfer elision/etc applied) to `stream.cmd.*` (where we can freely alias) we can produce the tightest usage affinities and segment each resource independently prior to packing. Deallocations that can either be inserted directly during ScheduleAllocationPass or analyzed later during stream->hal lowering can reuse the joined affinities while the fallback case sets the prefer-origin flag indicating that the runtime should decide. The behavior at runtime will be the same for each but by preserving that information in the compiler for longer we can in the future set timepoint affinities more tightly (today we don't track them, but really should). Example IR showing what this does today and what it can do once we elide transfers: https://gist.github.com/benvanik/ecc9b37fb2b670ce1ed2fb0d7c694287 Fixes #20855.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates affinity analysis to better track operand/result usage independently from execution scope particularly with pinned ops. The improved tracking enables ScheduleAllocationPass to now join all potential affinities a result will be used on to produce the affinity for each allocation whether they are transients or constants/variables. By performing analysis at the point immediately prior to going from
stream.async.*(with all optimizations/transfer elision/etc applied) tostream.cmd.*(where we can freely alias) we can produce the tightest usage affinities and segment each resource independently prior to packing.Deallocations that can either be inserted directly during ScheduleAllocationPass or analyzed later during stream->hal lowering can reuse the joined affinities while the fallback case sets the prefer-origin flag indicating that the runtime should decide. The behavior at runtime will be the same for each but by preserving that information in the compiler for longer we can in the future set timepoint affinities more tightly (today we don't track them, but really should).
Example IR showing what this does today and what it can do once we elide transfers:
https://gist.github.com/benvanik/ecc9b37fb2b670ce1ed2fb0d7c694287
Fixes #20855.