Skip to content

[Stream] Adding AffinityTopologyAttrInterface and HAL implementation. - #20885

Merged
benvanik merged 10 commits into
iree-org:mainfrom
ziereis:stream_topology_attr
Jun 4, 2025
Merged

benvanik merged 10 commits into
iree-org:mainfrom
ziereis:stream_topology_attr

Conversation

@ziereis

@ziereis ziereis commented May 22, 2025 •

Copy link
Copy Markdown
Contributor

Adds IREE::Stream::AffinityTopologyAttrInterface so that analysis and passes in the stream dialect can query for topology information from target device layers. #hal.device.topology<...> is the first implementation.

Fixes #20854.

@ziereis
ziereis requested a review from benvanik as a code owner May 22, 2025 14:02
@ziereis
ziereis marked this pull request as draft May 22, 2025 14:03
@ziereis
ziereis force-pushed the stream_topology_attr branch 2 times, most recently from a6b4d68 to df5fce1 Compare May 22, 2025 14:10

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice first draft! Some minor style comments and then some ideas around the design inline.


let assemblyFormat = [{
`{` `[` $devices `]` `,`
`transfer_required` `=` $transferRequired `}`

@benvanik benvanik May 22, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the defaults make more sense we'd want to have the flag be flipped - instead of "transfer required" we'd want "no transfer is required" to be the new information. We can make the query function be the "is a transfer required" part and have something different in the IR. for example, unified_memory && transparent_access would let us set the policy as to whether we rematerialize large resources if the memory is discrete for performance separately from whether the buffers can be accessed without staging.

In the future we may be able to make the existing --iree-stream-resource-memory-model= flag that is used to force discrete/unified piggy back on this for cases with single devices as well, though we may need a special entry for generic host-device relations (vs device-device, even if one of those devices happens to be a local host executor).

@ziereis

ziereis commented May 23, 2025

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the Comments! Im not sure if i got the requiresTransfer(...) check correctly now.

Would something like this already be sufficient to signal that no transfer is required for transfers in both directions?

links = [
  (@device_cpu -> @device_gpu = {}),
  (@device_gpu -> @device_cpu = {transparent_access})
]

It indicates only gpu -> cpu access works. However, assuming I can always control the target device for memory allocation it would be sufficient to also elide transfers from cpu -> gpu?

Or should the requiresTransfer(...) function only check for the unified_memory flag and the transparent_access is only used later as additional (and optional?) information for choosing the allocation device?

Also, one follow up question about how this information should be incorporated into the module. You mentioned using the --iree-stream-resource-memory-model= flag, i assume at some point we would populate a default topology which would just be {} connections between all devices and the --iree-stream-resource-memory-model=unified would then add unified_memory to all entries. Do you think we would also want something like --iree-stream-topology-link-attr="device_a->device_b,transparent_access"?

ziereis added 3 commits May 23, 2025 09:37
Signed-off-by: Thomas Ziereis <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis
ziereis force-pushed the stream_topology_attr branch from fb33a0f to e231073 Compare May 23, 2025 07:38
@ziereis
ziereis requested a review from benvanik May 23, 2025 08:36
Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis
ziereis force-pushed the stream_topology_attr branch from 054a80f to d78741e Compare May 23, 2025 12:17
ziereis added 2 commits May 23, 2025 15:01
Signed-off-by: Thomas Ziereis <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis

ziereis commented May 26, 2025

Copy link
Copy Markdown
Contributor Author

Also removed the bidirectional '<->' arrows for now. They did seem to work fine when standalone but as soon as i used them as part of the #hal.device.topology<links = [...]> i would get this error:

test.mlir:9:34: error: unbalanced '<' character in pretty dialect name
  topology = #hal.device.topology<links = [

not sure how to work around this.

Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis
ziereis marked this pull request as ready for review May 28, 2025 06:53

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I think we should strongly type the properties to avoid the custom parser/printer/verifier and make it easier to maintain. We can still keep an optional dictionary for out-of-tree/core properties that we don't want to make part of the API but let the standard ones that the compiler supports be nice.

Signed-off-by: Thomas Ziereis <[email protected]>
@ziereis
ziereis requested a review from benvanik June 2, 2025 11:50

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it!

@benvanik benvanik changed the title Stream: Add topology attribute [Stream] Add AffinityTopologyAttrInterface and HAL implementation. Jun 4, 2025
@benvanik benvanik changed the title [Stream] Add AffinityTopologyAttrInterface and HAL implementation. [Stream] Adding AffinityTopologyAttrInterface and HAL implementation. Jun 4, 2025
@benvanik
benvanik enabled auto-merge (squash) June 4, 2025 15:21
@benvanik
benvanik merged commit c07bfb4 into iree-org:main Jun 4, 2025
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
…#20885)

Adds `IREE::Stream::AffinityTopologyAttrInterface` so that analysis and
passes in the stream dialect can query for topology information from
target device layers. `#hal.device.topology<...>` is the first
implementation.

Fixes #20854.

---------

Signed-off-by: Thomas Ziereis <[email protected]>
Co-authored-by: Ben Vanik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Stream] Add a mechanism for denoting device-device link topology for transfer elision when NUMA.

2 participants