Skip to content

[HAL] Add hal.allocator.resolve_memory_properties - #21115

Merged
benvanik merged 28 commits into
iree-org:mainfrom
ziereis:hal_resolve_memory_properties
Jul 29, 2025
Merged

benvanik merged 28 commits into
iree-org:mainfrom
ziereis:hal_resolve_memory_properties

Conversation

@ziereis

@ziereis ziereis commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

progress towards: #20856

Adds a new operation hal.allocator.resolve_memory_properties and a pass that tries to resolve it using the topology attribute. The same pass should aim to do the same thing for the hal.allocator.select op in a follow up.

ziereis added 11 commits June 17, 2025 09:27
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
@ziereis
ziereis requested a review from benvanik as a code owner June 17, 2025 12:07

@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! Major comments are:

  • remove the canonicalization patterns (to ensure there's only one point in the transformation pipeline where we resolve consistently)
  • decouple stream/hal by cloning the lifetime enum into HAL (for now, it can change in the future)
  • change the pass to doing a single pass module walk instead of a fixed-point pattern application (since fixed-point is not required)

// The bits set here are those that must be set for the buffer to be used as the
// buffer within the program with its defined resource lifetime.
LogicalResult
deriveRequiredResourceBufferBits(Location loc, IREE::Stream::Lifetime lifetime,

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.

We try to keep IR dirs small and focused exclusively on the structure and representation of dialects and their canonical form, and utilities used during conversion stay there. We also try to avoid "utils" dumpsters unless very useful to a large portion of code - and even if so scope them as tightly as possible (such as the conversion utils useful to conversion patterns). These are only needed in one single place in the code (where a lifetime is converted into HAL type/usage enums) and should live with that (in your ResolveTopologyQueries pass).

Having the patterns is nice for baking this out earlier but given what this does (interacting with devices/etc) it's best to do it in your pass in a consistent location - before ResolveTopologyQueriesPass runs there are resolve ops, and after it runs there are not. This makes it more difficult for behavior to creep in that assumes things are always resolved early (because a particular test/user always has a single device and never tests with multiple) and more predictable where to debug issues. So drop the canonicalizers here and then this (and the external resources mappable flag) can all move to ResolveTopologyQueries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i kept this at its original place (StreamToHAL/Utils.h) as its still used by BufferAsserts in the Stream conversion patterns. However i moved to cl flag and the deriveAllowedResourceBufferBits function to the pass.

ziereis added 9 commits June 30, 2025 06:39
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
@ziereis
ziereis requested a review from benvanik July 1, 2025 15:56

@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.

A few small style changes then LGTM! Nice work!

ziereis added 2 commits July 21, 2025 08:36
Signed-off-by: default <[email protected]>
Signed-off-by: default <[email protected]>
@ziereis

ziereis commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews! :)

@benvanik
benvanik merged commit bf42ef4 into iree-org:main Jul 29, 2025
hhkit pushed a commit to opencompl/iree that referenced this pull request Aug 8, 2025
Progress towards: iree-org#20856

Adds a new operation `hal.allocator.resolve_memory_properties` and a
pass that tries to resolve it using the topology attribute. The same
pass should aim to do the same thing for the `hal.allocator.select` op
in a follow up.

---------

Signed-off-by: default <[email protected]>
Signed-off-by: Thomas Ziereis <[email protected]>
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
Progress towards: #20856

Adds a new operation `hal.allocator.resolve_memory_properties` and a
pass that tries to resolve it using the topology attribute. The same
pass should aim to do the same thing for the `hal.allocator.select` op
in a follow up.

---------

Signed-off-by: default <[email protected]>
Signed-off-by: Thomas Ziereis <[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.

2 participants