Skip to content

Adding skeleton AMDGPU buffer handle and handle pool. - #21044

Merged
benvanik merged 1 commit into
mainfrom
users/benvanik/amdgpu-buffer
Jun 13, 2025
Merged

benvanik merged 1 commit into
mainfrom
users/benvanik/amdgpu-buffer

Conversation

@benvanik

@benvanik benvanik commented Jun 7, 2025

Copy link
Copy Markdown
Collaborator

The driver will implement two buffer types to start (or more?): iree_hal_amdgpu_external_buffer_t and iree_hal_amdgpu_transient_buffer_t. The external buffer will be used for imported buffers and synchronous allocations (probably), while the transient buffer is used for all asynchronous allocations. The transient buffer maintains a reference to a device-accessible iree_hal_amdgpu_device_allocation_handle_t that stores the allocated pointer. The device-side allocator will update the handle as it allocates/deallocates and anyone resolving buffer pointers (e.g. iree_hal_amdgpu_device_buffer_ref_resolve) fetches the current pointer from the handle. The pointer is only valid between alloca/dealloca ops (which will set/reset the pointer).

iree_hal_amdgpu_device_buffer_ref_t is a variant that allows binding tables and command buffer ops to reference typed buffers. Most code can dereference device pointers (synchronously allocated buffers, imported buffers, etc) and the transient buffer handles. Command buffers can reference binding table slots with a relative offset/length. iree_hal_amdgpu_device_workgroup_count_buffer_ref_t is a special case for indirect dispatches (where the length is always known) as it packs better into space-constrained structs.

A simple iree_hal_amdgpu_buffer_pool_t handles both the host iree_hal_buffer_t instances and device allocation handles. The device allocation handles can be stored in device memory to avoid additional bus traffic on each dereference. In the steady state of invocations with alloca/dealloca the pool should remove all host/device allocations.

@benvanik
benvanik requested review from AWoloszyn and ScottTodd June 7, 2025 04:28
@benvanik benvanik added the hal/amdgpu Runtime AMDGPU HAL backend label Jun 7, 2025
@benvanik
benvanik marked this pull request as ready for review June 7, 2025 04:30
@benvanik
benvanik force-pushed the users/benvanik/amdgpu-buffer branch from 0e3a533 to fd8e95f Compare June 9, 2025 16:21
@benvanik
benvanik force-pushed the users/benvanik/amdgpu-system branch 2 times, most recently from 57a0d9b to f3b3161 Compare June 12, 2025 18:37
@benvanik
benvanik force-pushed the users/benvanik/amdgpu-buffer branch from fd8e95f to f239530 Compare June 12, 2025 18:37
@benvanik
benvanik force-pushed the users/benvanik/amdgpu-system branch from f3b3161 to 1217491 Compare June 12, 2025 19:32
Base automatically changed from users/benvanik/amdgpu-system to main June 12, 2025 20:17
@benvanik
benvanik force-pushed the users/benvanik/amdgpu-buffer branch 2 times, most recently from 7f6f67e to 4a20958 Compare June 12, 2025 21:32
Comment on lines +46 to +47
// Topology with all CPU and GPU agents. Buffers must be visible to all.
const iree_hal_amdgpu_topology_t* topology;

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.

Out of curiosity, can the topology change while the program is running, e.g. from a new GPU being connected or a previously hidden device being made available? Would that trigger a device loss or some other error that the application or IREE runtime libraries would listen for and respond to?

I get the impression that HSA is low enough level that such events could happen... like on a laptop with multiple accelerators or some platform with hot swappable devices.

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.

Conceptually yeah, but I don't think so in practice. I love the idea though :)

I think everything assumes it is all handled by automatic driver-level power island magic instead: you can always create a device and have it live but if you don't do anything with it for awhile it'll power down/go idle, and then when you go to use it again it comes back. Hot swap is a process restart kind of thing. ROCR itself caches a bunch of things at library load time and never re-queries (and thus HIP & co do the same), so we'll be limited by that even if we did want to do something cooler. A hosting application could be a bit more dynamic by reinitializing IREE if there was a significant event where they wanted to switch the active device set, so long as the underlying layers were fixed to be more dynamic.

@benvanik
benvanik merged commit 616c960 into main Jun 13, 2025
@benvanik
benvanik deleted the users/benvanik/amdgpu-buffer branch June 13, 2025 03:53
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
The driver will implement two buffer types to start (or more?):
`iree_hal_amdgpu_external_buffer_t` and
`iree_hal_amdgpu_transient_buffer_t`. The external buffer will be used
for imported buffers and synchronous allocations (probably), while the
transient buffer is used for all asynchronous allocations. The transient
buffer maintains a reference to a device-accessible
`iree_hal_amdgpu_device_allocation_handle_t` that stores the allocated
pointer. The device-side allocator will update the handle as it
allocates/deallocates and anyone resolving buffer pointers (e.g.
`iree_hal_amdgpu_device_buffer_ref_resolve`) fetches the current pointer
from the handle. The pointer is only valid between alloca/dealloca ops
(which will set/reset the pointer).

`iree_hal_amdgpu_device_buffer_ref_t` is a variant that allows binding
tables and command buffer ops to reference typed buffers. Most code can
dereference device pointers (synchronously allocated buffers, imported
buffers, etc) and the transient buffer handles. Command buffers can
reference binding table slots with a relative offset/length.
`iree_hal_amdgpu_device_workgroup_count_buffer_ref_t` is a special case
for indirect dispatches (where the length is always known) as it packs
better into space-constrained structs.

A simple `iree_hal_amdgpu_buffer_pool_t` handles both the host
`iree_hal_buffer_t` instances and device allocation handles. The device
allocation handles can be stored in device memory to avoid additional
bus traffic on each dereference. In the steady state of invocations with
alloca/dealloca the pool should remove all host/device allocations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/amdgpu Runtime AMDGPU HAL backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants