Skip to content

Starting rework of HAL allocator APIs.#8389

Merged
benvanik merged 3 commits intomainfrom
benvanik-memory-types
Feb 23, 2022
Merged

Starting rework of HAL allocator APIs.#8389
benvanik merged 3 commits intomainfrom
benvanik-memory-types

Conversation

@benvanik
Copy link
Copy Markdown
Collaborator

This is the first part of a larger set of changes that reworks how buffers are allocated by both simplifying what the user needs to provide and adding more expression to what is provided. Memory types will still exist but in almost all cases be specified as OPTIMAL when allocating buffers enabling the implementation to choose the types based on availability and underlying API requirements. There are still cases where one would need to specify them (creating importable/exportable buffers, interoping with buffers allocated externally, etc) but usage will be the primary discriminator.

As part of this the allocator methods now take a iree_hal_buffer_params_t struct containing the various flags and attributes required to perform an allocation, enabling us to associate location information by way of queue affinities and alignment requirements which are required for exportable buffers in some implementations and virtual memory management. The intent is that zero initialization will be fine (once OPTIMAL is in place) but today both type and usage are required.

Future changes will significantly rework iree_hal_memory_type_t and iree_hal_buffer_usage_t and add some queries that can be used by allocator shims to determine how usage interacts with memory types. This will require compiler changes as well in order to plumb through the required usage information from the HAL dialect ops.

@benvanik benvanik added the hal/api IREE's public C hardware abstraction layer API label Feb 23, 2022
@benvanik benvanik force-pushed the benvanik-memory-types branch 2 times, most recently from 7f19dd0 to e8ff3b0 Compare February 23, 2022 03:57
This allows for more parameters to be added without needing to update
all the function signatures, particularly when cutting across layers
(such as the buffer view helpers). The new iree_hal_buffer_params_t
struct carries some additional fields for alignment and affinity that
future allocator implementations can use for placement.

The parameters are passed by-value today (which, given the amount means
on-stack). That's fine as all these methods had enough params to pass
on-stack anyway and by the time you're calling into the allocator to
do something you're already off the fast path. The
vtable/implementations use by-ref so that the stack copy is only done
once where the ergonomics matter (iree_hal_* user API).

Ergonomics from C++ will improve after follow-on changes simplify the
memory type/buffer usage fields.
Comment on lines -86 to +91
IREE_HAL_MEMORY_TYPE_HOST_LOCAL | IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE,
IREE_HAL_MEMORY_ACCESS_READ, IREE_HAL_BUFFER_USAGE_ALL,
(iree_hal_buffer_params_t){
.type = IREE_HAL_MEMORY_TYPE_HOST_LOCAL |
IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE,
.access = IREE_HAL_MEMORY_ACCESS_READ,
.usage = IREE_HAL_BUFFER_USAGE_ALL,
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was a little worried about these functions getting even more verbose, but this syntax with named initializers for the struct reads pretty easily.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

intellisense works pretty well too, and now (with the coming changes) that the fields are mostly optional these could even just be ..., {IREE_HAL_BUFFER_USAGE_FOO}, ... inline. C++ 20 will be able to do this named stuff too, but for now that unnamed style should at least make that cleaner 🤞

@benvanik benvanik merged commit e9cc1ec into main Feb 23, 2022
@benvanik benvanik deleted the benvanik-memory-types branch February 23, 2022 18:46
ScottTodd added a commit that referenced this pull request Feb 24, 2022
Missed in #8389 since this demo was disabled (re-enabled in #8382).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/api IREE's public C hardware abstraction layer API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants