Repository navigation
Adding support for #hal.device.optimal<...> through to runtime. - #20879
Merged
Merged
Conversation
Progress on #20857.
benvanik
force-pushed
the
users/benvanik/allocator-select
branch
from
May 21, 2025 21:10
2741108 to
934fdff
Compare
I don't like having the two ops but they're an implementation detail that can be fixed in the future without changes above/below. Progress on #20857.
benvanik
force-pushed
the
users/benvanik/allocator-select
branch
from
May 21, 2025 21:40
934fdff to
f43d9cb
Compare
benvanik
marked this pull request as ready for review
May 22, 2025 00:07
ScottTodd
approved these changes
May 22, 2025
ScottTodd
left a comment
Member
There was a problem hiding this comment.
As more multi-device (especially heterogeneous) code lands, we should think more about integration tests. Unit test coverage via lit tests is great, but I'd like to see some tests showing what the user-observable behavior is.
The `--device_lead_allocator=` flag can be used in tooling to specify a device that should be preferred as the allocator when a selection is requested. If the device isn't in the list the first will be returned. For simple cases of CPU + some accelerator this should work and more complex situations will need something more designed. Fixes #20857.
Collaborator
Author
|
With whatever other non-CPU target we get working as part of #20851 we'll ensure there are e2e tests for it that uses the new flag (they'll all require the flag to work at all, so they'll be easy to spot if it breaks). |
benvanik
force-pushed
the
users/benvanik/allocator-select
branch
from
May 22, 2025 21:21
f43d9cb to
bbfc44f
Compare
benvanik
enabled auto-merge (squash)
May 22, 2025 21:21
benvanik
added a commit
that referenced
this pull request
May 22, 2025
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
AWoloszyn
pushed a commit
that referenced
this pull request
Dec 1, 2025
…0879) This is an experimental approach for representing a set of device affinities that are able to be resolved at runtime. Currently this is limited to allocation-related ops but may be extended in the future to allow for runtime-provided device rankings based on benchmarked performance. The new `#hal.device.optimal<...>` affinity attribute represents a set of affinities that an operation is able to execute with. The expectation is that the exact affinity can be resolved during compilation if sufficient information is available (TBD) or at runtime based on a user-provided policy (`iree_hal_module_device_policy_t`). As with other treatments of device topology in the runtime this policy is left to the hosting framework or application to decide how they want to configure their overall topology. The common IREE command line tooling adds a `--device_lead_allocator=N` flag to let the user denote which device ordinal (of `--device=` flags) is to be chosen when a `#hal.device.optimal` request makes it all the way to runtime. For simple cases of CPU+accelerator this allows for hack-free ways to indicate the lead allocator that is responsible for any buffer allocation that is used on multiple devices. The `#hal.device.optimal<...>` attr lowers to a `hal.allocator.select` op/runtime call that takes a list of devices/queue masks along with the memory types and buffer usage of the request and returns the selected device/queue mask. Size is not included such that the selection can be memoized across an entire program at initialization time. A pass is added that runs at the same time as device query memoization to hoist the selection into globals. Future changes can enhance the pass to fold the selection when sufficient information has been provided. Future work on #20855 will result in affinity assignment on resource allocations lowering into this new `#hal.device.optimal<...>` attr and deallocations switching to either use the recently added `origin` attr or the same optimal attr (given that it should be consistent and provides more information). Future work on #20856 will ensure that allocations that may be used on multiple devices (regardless of whether runtime-selected) get the appropriate bits set but that may require #20854. Progress on #20851. Progress on #20855 (analysis will lower into this attr). Progress on #20856 (will be used to set bits). Fixes #20857.
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.
This is an experimental approach for representing a set of device affinities that are able to be resolved at runtime. Currently this is limited to allocation-related ops but may be extended in the future to allow for runtime-provided device rankings based on benchmarked performance.
The new
#hal.device.optimal<...>affinity attribute represents a set of affinities that an operation is able to execute with. The expectation is that the exact affinity can be resolved during compilation if sufficient information is available (TBD) or at runtime based on a user-provided policy (iree_hal_module_device_policy_t). As with other treatments of device topology in the runtime this policy is left to the hosting framework or application to decide how they want to configure their overall topology. The common IREE command line tooling adds a--device_lead_allocator=Nflag to let the user denote which device ordinal (of--device=flags) is to be chosen when a#hal.device.optimalrequest makes it all the way to runtime. For simple cases of CPU+accelerator this allows for hack-free ways to indicate the lead allocator that is responsible for any buffer allocation that is used on multiple devices.The
#hal.device.optimal<...>attr lowers to ahal.allocator.selectop/runtime call that takes a list of devices/queue masks along with the memory types and buffer usage of the request and returns the selected device/queue mask. Size is not included such that the selection can be memoized across an entire program at initialization time. A pass is added that runs at the same time as device query memoization to hoist the selection into globals. Future changes can enhance the pass to fold the selection when sufficient information has been provided.Future work on #20855 will result in affinity assignment on resource allocations lowering into this new
#hal.device.optimal<...>attr and deallocations switching to either use the recently addedoriginattr or the same optimal attr (given that it should be consistent and provides more information). Future work on #20856 will ensure that allocations that may be used on multiple devices (regardless of whether runtime-selected) get the appropriate bits set but that may require #20854.Progress on #20851.
Progress on #20855 (analysis will lower into this attr).
Progress on #20856 (will be used to set bits).
Fixes #20857.