Skip to content

Commit e383a36

Browse files
committed
[UR][Offload] Improvements to offload event handling
* Implemented device infos for event handles. * Fixed event being deleted before it should have been. * Make the tests consider profiling info optional.
1 parent 22ee417 commit e383a36

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

unified-runtime/source/adapters/offload/enqueue.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
7474
hKernel->Args.getStorageSize(), &LaunchArgs, &EventOut));
7575

7676
if (phEvent) {
77-
auto *Event = new ur_event_handle_t_();
77+
auto *Event = new ur_event_handle_t_(UR_COMMAND_KERNEL_LAUNCH, hQueue);
7878
Event->OffloadEvent = EventOut;
7979
*phEvent = Event;
8080
}
@@ -117,7 +117,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(
117117
}
118118

119119
if (phEvent) {
120-
auto *Event = new ur_event_handle_t_();
120+
auto *Event = new ur_event_handle_t_(UR_COMMAND_MEM_BUFFER_READ, hQueue);
121121
Event->OffloadEvent = EventOut;
122122
*phEvent = Event;
123123
}
@@ -149,21 +149,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferWrite(
149149
}
150150

151151
if (phEvent) {
152-
auto *Event = new ur_event_handle_t_();
152+
auto *Event = new ur_event_handle_t_(UR_COMMAND_MEM_BUFFER_WRITE, hQueue);
153153
Event->OffloadEvent = EventOut;
154154
*phEvent = Event;
155155
}
156156

157157
return UR_RESULT_SUCCESS;
158158
}
159159

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

@@ -197,7 +198,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap(
197198
}
198199

199200
if (phEvent) {
200-
enqueueNoOp(hQueue, phEvent);
201+
enqueueNoOp(UR_COMMAND_MEM_BUFFER_MAP, hQueue, phEvent);
201202
}
202203
}
203204
*ppRetMap = MapPtr;
@@ -231,7 +232,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap(
231232
}
232233

233234
if (phEvent) {
234-
enqueueNoOp(hQueue, phEvent);
235+
enqueueNoOp(UR_COMMAND_MEM_UNMAP, hQueue, phEvent);
235236
}
236237
}
237238
BufferImpl.unmap(pMappedPtr);

unified-runtime/source/adapters/offload/event.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ur_api.h>
1313

1414
#include "event.hpp"
15+
#include "queue.hpp"
1516
#include "ur2offload.hpp"
1617

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

2425
switch (propName) {
26+
case UR_EVENT_INFO_CONTEXT:
27+
return ReturnValue(hEvent->UrQueue->UrContext);
28+
case UR_EVENT_INFO_COMMAND_QUEUE:
29+
return ReturnValue(hEvent->UrQueue);
30+
case UR_EVENT_INFO_COMMAND_TYPE:
31+
return ReturnValue(hEvent->Type);
2532
case UR_EVENT_INFO_REFERENCE_COUNT:
2633
return ReturnValue(hEvent->RefCount.load());
2734
default:
@@ -63,9 +70,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) {
6370
// if (Res) {
6471
// return offloadResultToUR(Res);
6572
// }
73+
delete hEvent;
6674
}
6775

68-
delete hEvent;
6976
return UR_RESULT_SUCCESS;
7077
}
7178

unified-runtime/source/adapters/offload/event.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
struct ur_event_handle_t_ : RefCounted {
1919
ol_event_handle_t OffloadEvent;
2020
ur_command_t Type;
21+
ur_queue_handle_t UrQueue;
2122

22-
static ur_event_handle_t createEmptyEvent() {
23-
auto *Event = new ur_event_handle_t_();
23+
ur_event_handle_t_(ur_command_t Type, ur_queue_handle_t Queue) : Type(Type), UrQueue(Queue) {}
24+
25+
static ur_event_handle_t createEmptyEvent(ur_command_t Type, ur_queue_handle_t Queue) {
26+
auto *Event = new ur_event_handle_t_(Type, Queue);
2427
// Null event represents an empty event. Waiting on it is a no-op.
2528
Event->OffloadEvent = nullptr;
2629

unified-runtime/source/adapters/offload/queue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "ur2offload.hpp"
1919

2020
UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
21-
[[maybe_unused]] ur_context_handle_t hContext, ur_device_handle_t hDevice,
21+
ur_context_handle_t hContext, ur_device_handle_t hDevice,
2222
const ur_queue_properties_t *, ur_queue_handle_t *phQueue) {
2323

2424
assert(hContext->Device == hDevice);
@@ -31,6 +31,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
3131
}
3232

3333
Queue->OffloadDevice = hDevice->OffloadDevice;
34+
Queue->UrContext = hContext;
3435

3536
*phQueue = Queue;
3637

unified-runtime/source/adapters/offload/queue.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
struct ur_queue_handle_t_ : RefCounted {
1919
ol_queue_handle_t OffloadQueue;
2020
ol_device_handle_t OffloadDevice;
21+
ur_context_handle_t UrContext;
2122
};

unified-runtime/test/conformance/event/urEventGetProfilingInfo.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

77
#include "fixtures.h"
8+
#include "uur/checks.h"
89
#include "uur/known_failure.h"
910

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

180181
const ur_profiling_info_t property_name = UR_PROFILING_INFO_COMMAND_QUEUED;
181182
size_t property_size = 0;
182-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, property_name, 0, nullptr,
183-
&property_size));
183+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
184+
urEventGetProfilingInfo(event, property_name, 0, nullptr, &property_size),
185+
property_name);
184186
ASSERT_NE(property_size, 0);
185187

186188
uint64_t property_value = 0;
@@ -221,8 +223,10 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE(urEventGetProfilingInfoForWaitWithBarrier);
221223

222224
TEST_P(urEventGetProfilingInfoForWaitWithBarrier, Success) {
223225
uint64_t submit_value = 0;
224-
ASSERT_SUCCESS(urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START,
225-
size, &submit_value, nullptr));
226+
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
227+
urEventGetProfilingInfo(event, UR_PROFILING_INFO_COMMAND_START, size,
228+
&submit_value, nullptr),
229+
UR_PROFILING_INFO_COMMAND_START);
226230
ASSERT_NE(submit_value, 0);
227231

228232
uint64_t complete_value = 0;

0 commit comments

Comments
 (0)