Skip to content

[UR][Offload] Improvements to offload event handling #19515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions unified-runtime/source/adapters/offload/enqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
hKernel->Args.getStorageSize(), &LaunchArgs, &EventOut));

if (phEvent) {
auto *Event = new ur_event_handle_t_();
auto *Event = new ur_event_handle_t_(UR_COMMAND_KERNEL_LAUNCH, hQueue);
Event->OffloadEvent = EventOut;
*phEvent = Event;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(
}

if (phEvent) {
auto *Event = new ur_event_handle_t_();
auto *Event = new ur_event_handle_t_(UR_COMMAND_MEM_BUFFER_READ, hQueue);
Event->OffloadEvent = EventOut;
*phEvent = Event;
}
Expand Down Expand Up @@ -149,21 +149,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferWrite(
}

if (phEvent) {
auto *Event = new ur_event_handle_t_();
auto *Event = new ur_event_handle_t_(UR_COMMAND_MEM_BUFFER_WRITE, hQueue);
Event->OffloadEvent = EventOut;
*phEvent = Event;
}

return UR_RESULT_SUCCESS;
}

ur_result_t enqueueNoOp(ur_queue_handle_t hQueue, ur_event_handle_t *phEvent) {
ur_result_t enqueueNoOp(ur_command_t Type, ur_queue_handle_t hQueue,
ur_event_handle_t *phEvent) {
// This path is a no-op, but we can't output a real event because
// Offload doesn't currently support creating arbitrary events, and we
// don't know the last real event in the queue. Instead we just have to
// wait on the whole queue and then return an empty (implicitly
// finished) event.
*phEvent = ur_event_handle_t_::createEmptyEvent();
*phEvent = ur_event_handle_t_::createEmptyEvent(Type, hQueue);
return urQueueFinish(hQueue);
}

Expand Down Expand Up @@ -197,7 +198,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap(
}

if (phEvent) {
enqueueNoOp(hQueue, phEvent);
enqueueNoOp(UR_COMMAND_MEM_BUFFER_MAP, hQueue, phEvent);
}
}
*ppRetMap = MapPtr;
Expand Down Expand Up @@ -231,7 +232,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap(
}

if (phEvent) {
enqueueNoOp(hQueue, phEvent);
enqueueNoOp(UR_COMMAND_MEM_UNMAP, hQueue, phEvent);
}
}
BufferImpl.unmap(pMappedPtr);
Expand Down
9 changes: 8 additions & 1 deletion unified-runtime/source/adapters/offload/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ur_api.h>

#include "event.hpp"
#include "queue.hpp"
#include "ur2offload.hpp"

UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
Expand All @@ -22,6 +23,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(ur_event_handle_t hEvent,
UrReturnHelper ReturnValue(propSize, pPropValue, pPropSizeRet);

switch (propName) {
case UR_EVENT_INFO_CONTEXT:
return ReturnValue(hEvent->UrQueue->UrContext);
case UR_EVENT_INFO_COMMAND_QUEUE:
return ReturnValue(hEvent->UrQueue);
case UR_EVENT_INFO_COMMAND_TYPE:
return ReturnValue(hEvent->Type);
case UR_EVENT_INFO_REFERENCE_COUNT:
return ReturnValue(hEvent->RefCount.load());
default:
Expand Down Expand Up @@ -63,9 +70,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) {
// if (Res) {
// return offloadResultToUR(Res);
// }
delete hEvent;
}

delete hEvent;
return UR_RESULT_SUCCESS;
}

Expand Down
9 changes: 7 additions & 2 deletions unified-runtime/source/adapters/offload/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
struct ur_event_handle_t_ : RefCounted {
ol_event_handle_t OffloadEvent;
ur_command_t Type;
ur_queue_handle_t UrQueue;

static ur_event_handle_t createEmptyEvent() {
auto *Event = new ur_event_handle_t_();
ur_event_handle_t_(ur_command_t Type, ur_queue_handle_t Queue)
: Type(Type), UrQueue(Queue) {}

static ur_event_handle_t createEmptyEvent(ur_command_t Type,
ur_queue_handle_t Queue) {
auto *Event = new ur_event_handle_t_(Type, Queue);
// Null event represents an empty event. Waiting on it is a no-op.
Event->OffloadEvent = nullptr;

Expand Down
8 changes: 5 additions & 3 deletions unified-runtime/source/adapters/offload/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#include "queue.hpp"
#include "ur2offload.hpp"

UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
[[maybe_unused]] ur_context_handle_t hContext, ur_device_handle_t hDevice,
const ur_queue_properties_t *, ur_queue_handle_t *phQueue) {
UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(ur_context_handle_t hContext,
ur_device_handle_t hDevice,
const ur_queue_properties_t *,
ur_queue_handle_t *phQueue) {

assert(hContext->Device == hDevice);

Expand All @@ -31,6 +32,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
}

Queue->OffloadDevice = hDevice->OffloadDevice;
Queue->UrContext = hContext;

*phQueue = Queue;

Expand Down
1 change: 1 addition & 0 deletions unified-runtime/source/adapters/offload/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
struct ur_queue_handle_t_ : RefCounted {
ol_queue_handle_t OffloadQueue;
ol_device_handle_t OffloadDevice;
ur_context_handle_t UrContext;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "fixtures.h"
#include "uur/checks.h"
#include "uur/known_failure.h"

using urEventGetProfilingInfoTest = uur::event::urEventTest;
Expand Down Expand Up @@ -179,8 +180,9 @@ TEST_P(urEventGetProfilingInfoTest, InvalidValue) {

const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_QUEUED;
size_t property_size = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(event, property_name, 0, nullptr,
&property_size));
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urEventGetProfilingInfo(event, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_NE(property_size, 0);

uint64_t property_value = 0;
Expand Down Expand Up @@ -221,8 +223,10 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEventGetProfilingInfoForWaitWithBarrier);

TEST_P(urEventGetProfilingInfoForWaitWithBarrier, Success) {
uint64_t submit_value = 0;
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START,
size, &submit_value, nullptr));
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START, size,
&submit_value, nullptr),
UR_PROFILING_INFO_COMMAND_START);
ASSERT_NE(submit_value, 0);

uint64_t complete_value = 0;
Expand Down
Loading