Skip to content

Commit

Permalink
Updated based on PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
AWoloszyn committed Dec 10, 2024
1 parent e0db717 commit a043143
Show file tree
Hide file tree
Showing 8 changed files with 386 additions and 355 deletions.
5 changes: 3 additions & 2 deletions runtime/src/iree/hal/drivers/hip/cleanup_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ iree_status_t iree_hal_hip_cleanup_thread_initialize(
iree_status_t status =
iree_thread_create((iree_thread_entry_t)iree_hal_hip_cleanup_thread_main,
thread, params, host_allocator, &thread->thread);
if (!iree_status_is_ok(status)) {
if (iree_status_is_ok(status)) {
*out_thread = thread;
} else {
iree_hal_hip_callback_queue_deinitialize(&thread->queue);
iree_slim_mutex_deinitialize(&thread->mutex);
iree_allocator_free(host_allocator, thread);
}
IREE_TRACE_ZONE_END(z0);
*out_thread = thread;
return status;
}

Expand Down
9 changes: 5 additions & 4 deletions runtime/src/iree/hal/drivers/hip/dispatch_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ iree_status_t iree_hal_hip_dispatch_thread_initialize(
iree_status_t status =
iree_thread_create((iree_thread_entry_t)iree_hal_hip_dispatch_thread_main,
thread, params, host_allocator, &thread->thread);
if (!iree_status_is_ok(status)) {

if (iree_status_is_ok(status)) {
*out_thread = thread;
} else {
iree_hal_hip_dispatch_queue_deinitialize(&thread->queue);
iree_slim_mutex_deinitialize(&thread->mutex);
iree_allocator_free(host_allocator, thread);
}
IREE_TRACE_ZONE_END(z0);
*out_thread = thread;
return status;
}

Expand Down Expand Up @@ -163,11 +165,10 @@ iree_status_t iree_hal_hip_dispatch_thread_add_dispatch(
iree_slim_mutex_unlock(&thread->mutex);
iree_notification_post(&thread->notification, IREE_ALL_WAITERS);

IREE_TRACE_ZONE_END(z0);

if (!iree_status_is_ok(status)) {
iree_status_ignore(dispatch(user_data, iree_status_clone(status)));
}
IREE_TRACE_ZONE_END(z0);

// If this was a failure then it was put into thread->failure_status.
return status;
Expand Down
9 changes: 4 additions & 5 deletions runtime/src/iree/hal/drivers/hip/dispatch_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
#include "iree/hal/api.h"
#include "iree/hal/drivers/hip/dynamic_symbols.h"

// iree_hal_hip_dispatch_thread is used simply as a way to get
// work off of the main thread. This is important to do for
// a single reason. There are 2 types of command buffer that we
// use in hip. One is a pre-recorded command buffer
// iree_hal_hip_dispatch_thread is used to get work off of the main thread.
// This is important to do for a single reason. There are 2 types of
// command buffer that we use in hip. One is a pre-recorded command buffer
// iree_hal_deferred_command_buffer_t, which when executed
// calls all of the associated hipStream based commands.
// The other is iree_hal_hip_graph_command_buffer_t which when executed
Expand All @@ -28,8 +27,8 @@
// work off of the main thread. There are a couple of
// caveats, as now we have to move async allocations and deallocations
// to that thread as well, as they need to remain in-order.

typedef struct iree_hal_hip_dispatch_thread_t iree_hal_hip_dispatch_thread_t;

typedef struct iree_hal_hip_event_t iree_hal_hip_event_t;

typedef iree_status_t (*iree_hal_hip_dispatch_callback_t)(void* user_data,
Expand Down
26 changes: 10 additions & 16 deletions runtime/src/iree/hal/drivers/hip/event_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ iree_status_t iree_hal_hip_event_pool_allocate(
event_pool->device_context = device_context;

iree_status_t status = iree_hal_hip_set_context(symbols, device_context);

if (iree_status_is_ok(status)) {
for (iree_host_size_t i = 0; i < available_capacity; ++i) {
status = iree_hal_hip_event_create(
Expand Down Expand Up @@ -253,22 +252,17 @@ iree_status_t iree_hal_hip_event_pool_acquire(
IREE_TRACE_ZONE_APPEND_TEXT(z0, "unpooled acquire");
IREE_TRACE_ZONE_APPEND_VALUE_I64(z0, (int64_t)remaining_count);

iree_status_t status = iree_hal_hip_set_context(event_pool->symbols,
event_pool->device_context);
if (iree_status_is_ok(status)) {
for (iree_host_size_t i = 0; i < remaining_count; ++i) {
status = iree_hal_hip_event_create(event_pool->symbols, event_pool,
event_pool->host_allocator,
&out_events[from_pool_count + i]);
if (!iree_status_is_ok(status)) {
// Must release all events we've acquired so far.
iree_hal_hip_event_pool_release_event(event_pool, from_pool_count + i,
out_events);
IREE_TRACE_ZONE_END(z0);
return status;
}
}
IREE_RETURN_AND_END_ZONE_IF_ERROR(
z0, iree_hal_hip_set_context(event_pool->symbols,
event_pool->device_context));
for (iree_host_size_t i = 0; i < remaining_count; ++i) {
iree_status_t status = iree_hal_hip_event_create(
event_pool->symbols, event_pool, event_pool->host_allocator,
&out_events[from_pool_count + i]);
if (!iree_status_is_ok(status)) {
// Must release all events we've acquired so far.
iree_hal_hip_event_pool_release_event(event_pool, from_pool_count + i,
out_events);
IREE_TRACE_ZONE_END(z0);
return status;
}
Expand Down
Loading

0 comments on commit a043143

Please sign in to comment.