Skip to content

Commit

Permalink
[hip] Cleanup the dispatch thread before the rest of the device. (#19826
Browse files Browse the repository at this point in the history
)

If the hip device is destroyed without all work having been completed,
the dispatch thread will then access the partially deleted device.

Move the dispatch cleanup to be the first thing we do in the destroy,
which will join the threads, and then the cleanup threads next, then we
can start removing the real
things from the device.

Signed-off-by: Andrew Woloszyn <andrew.woloszyn@gmail.com>
  • Loading branch information
AWoloszyn authored Jan 27, 2025
1 parent d72a7a1 commit 1bf7249
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions runtime/src/iree/hal/drivers/hip/hip_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ static void iree_hal_hip_device_destroy(iree_hal_device_t* base_device) {

const iree_hal_hip_dynamic_symbols_t* symbols = device->hip_symbols;

for (iree_host_size_t i = 0; i < device->device_count; ++i) {
iree_hal_hip_dispatch_thread_deinitialize(
device->devices[i].dispatch_thread);
}

iree_hal_hip_cleanup_thread_deinitialize(device->cleanup_thread);
iree_hal_hip_cleanup_thread_deinitialize(device->buffer_free_thread);

Expand Down Expand Up @@ -554,11 +559,6 @@ static void iree_hal_hip_device_destroy(iree_hal_device_t* base_device) {
symbols, hipDevicePrimaryCtxRelease(device->devices[i].hip_device));
}

for (iree_host_size_t i = 0; i < device->device_count; ++i) {
iree_hal_hip_dispatch_thread_deinitialize(
device->devices[i].dispatch_thread);
}

iree_arena_block_pool_deinitialize(&device->block_pool);

// Finally, destroy the device.
Expand Down

0 comments on commit 1bf7249

Please sign in to comment.