Skip to content

Initial affinity assignment plumbing through flow/stream/hal. - #10833

Merged
benvanik merged 4 commits into
mainfrom
benvanik-affinity-prep
Oct 24, 2022
Merged

benvanik merged 4 commits into
mainfrom
benvanik-affinity-prep

Conversation

@benvanik

@benvanik benvanik commented Oct 18, 2022 •

Copy link
Copy Markdown
Collaborator

The stream affinity attr is changed to an interface and a placeholder #hal.affinity.queue<...> implementation is defined to support single-device multi-queue assignment. There's still a decent number of things that will need to change for heterogeneous devices where we'll want affinities to specify #hal.device.target values but for now queues are enough. The queues specified are carried all the way to the runtime device queue affinity masks.

Example:

// run only on queue 0
%0 = flow.dispatch @ex::@entry0(%input) {stream.affinity = #hal.affinity.queue<[0]>} : ...
// run on either queue 1 or 2
%1 = flow.dispatch @ex::@entry1(%input) {stream.affinity = #hal.affinity.queue<[1, 2]>} : ...
// run on any queue (attr can also be omitted)
%2 = flow.dispatch @ex::@entry2(%0, %1) {stream.affinity = #hal.affinity.queue<*>} : ...

->

hal.device.queue.execute<%device : !hal.device> affinity(%c1)   // 0b001
hal.device.queue.execute<%device : !hal.device> affinity(%c6)   // 0b110
hal.device.queue.execute<%device : !hal.device> affinity(%c-1)  // 0b111...

Currently the affinities are picked up starting from the flow.dispatch.region/flow.dispatch.workgroups ops. To specify affinities before then the various dispatch region formation code (I guess 3 different ways now?) will need to be updated to respect user affinity specification (only fuse compatible things) and put the affinity attribute on the resulting dispatch region.

Affinities attributes must implement the interface and as such are at this layer IREE-specific. Before dispatch region formation (or as part of it) anything else could be used, with the only requirement being that before the stream dialect transformation pipeline is entered they are all turned in to stream.affinity attributes. For example a frontend could say my.device_placement = "please run this on queue 4 🙇" so long as it can later be mapped to stream.affinity = #hal.affinity.queue<[4]>.

Progress on #10765.

@benvanik
benvanik requested a review from ScottTodd October 18, 2022 19:31
@benvanik
benvanik force-pushed the benvanik-affinity-prep branch 2 times, most recently from e13e611 to dd2109c Compare October 18, 2022 21:15
@benvanik
benvanik marked this pull request as ready for review October 18, 2022 23:23
This is a placeholder for some more involved attributes that allow
specifying HAL device targets and other constraints.

I don't like that hal now relies on stream like this; in the future
target specification may move to a dedicated dialect that is shared
across flow/stream/hal.

Progress on #10765.
Partitioning now respects affinities, properly clones ops when
affinities allow, and drops affinities from partitioned ops to clean up
the IR.

Progress on #10765.
@benvanik
benvanik force-pushed the benvanik-affinity-prep branch from dd2109c to 962c073 Compare October 24, 2022 20:43
@benvanik
benvanik enabled auto-merge October 24, 2022 20:43
@benvanik
benvanik merged commit 87c5f3f into main Oct 24, 2022
@benvanik
benvanik deleted the benvanik-affinity-prep branch October 24, 2022 21:59
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.

2 participants