Skip to content

Commit 149f08d

Browse files
[SYCL] Support interop_task with Level-Zero using get_mem() (#3307)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent d655cd4 commit 149f08d

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,6 @@ zeModuleGetPropertiesMock(ze_module_handle_t hModule,
911911

912912
static bool isOnlineLinkEnabled();
913913
// End forward declarations for mock Level Zero APIs
914-
std::once_flag OnceFlag;
915914

916915
// This function will ensure compatibility with both Linux and Windowns for
917916
// setting environment variables.
@@ -2548,9 +2547,8 @@ pi_result piMemImageCreate(pi_context Context, pi_mem_flags Flags,
25482547
}
25492548

25502549
pi_result piextMemGetNativeHandle(pi_mem Mem, pi_native_handle *NativeHandle) {
2551-
(void)Mem;
2552-
(void)NativeHandle;
2553-
die("piextMemGetNativeHandle: not supported");
2550+
PI_ASSERT(Mem, PI_INVALID_MEM_OBJECT);
2551+
*NativeHandle = pi_cast<pi_native_handle>(Mem->getZeHandle());
25542552
return PI_SUCCESS;
25552553
}
25562554

@@ -4107,13 +4105,52 @@ pi_result piSamplerRelease(pi_sampler Sampler) {
41074105
//
41084106
pi_result piEnqueueEventsWait(pi_queue Queue, pi_uint32 NumEventsInWaitList,
41094107
const pi_event *EventWaitList, pi_event *Event) {
4110-
(void)Queue;
4111-
(void)NumEventsInWaitList;
4112-
(void)EventWaitList;
4113-
(void)Event;
41144108

4115-
die("piEnqueueEventsWait: not implemented");
4116-
return {};
4109+
PI_ASSERT(Queue, PI_INVALID_QUEUE);
4110+
PI_ASSERT(Event, PI_INVALID_EVENT);
4111+
4112+
_pi_ze_event_list_t TmpWaitList;
4113+
if (auto Res = TmpWaitList.createAndRetainPiZeEventList(NumEventsInWaitList,
4114+
EventWaitList, Queue))
4115+
return Res;
4116+
4117+
// Lock automatically releases when this goes out of scope.
4118+
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
4119+
4120+
// Get a new command list to be used on this call
4121+
ze_command_list_handle_t ZeCommandList = nullptr;
4122+
ze_fence_handle_t ZeFence = nullptr;
4123+
if (auto Res = Queue->Context->getAvailableCommandList(Queue, &ZeCommandList,
4124+
&ZeFence))
4125+
return Res;
4126+
4127+
ze_event_handle_t ZeEvent = nullptr;
4128+
auto Res = createEventAndAssociateQueue(Queue, Event, PI_COMMAND_TYPE_USER,
4129+
ZeCommandList);
4130+
if (Res != PI_SUCCESS)
4131+
return Res;
4132+
ZeEvent = (*Event)->ZeEvent;
4133+
(*Event)->WaitList = TmpWaitList;
4134+
4135+
const auto &WaitList = (*Event)->WaitList;
4136+
if (WaitList.Length) {
4137+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, WaitList.Length,
4138+
WaitList.ZeEventList));
4139+
4140+
ZE_CALL(zeCommandListAppendSignalEvent(ZeCommandList, ZeEvent));
4141+
4142+
// Execute command list asynchronously as the event will be used
4143+
// to track down its completion.
4144+
return Queue->executeCommandList(ZeCommandList, ZeFence);
4145+
} else {
4146+
// If wait-list is empty, then this particular command should wait until
4147+
// all previous enqueued commands to the command-queue have completed.
4148+
//
4149+
// TODO: find a way to do that without blocking the host.
4150+
ZE_CALL(zeCommandQueueSynchronize(Queue->ZeCommandQueue, UINT64_MAX));
4151+
ZE_CALL(zeEventHostSignal(ZeEvent));
4152+
return PI_SUCCESS;
4153+
}
41174154
}
41184155

41194156
pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
@@ -4798,8 +4835,8 @@ enqueueMemImageCommandHelper(pi_command_type CommandType, pi_queue Queue,
47984835
if (Result != PI_SUCCESS)
47994836
return Result;
48004837

4801-
// TODO: Level Zero does not support row_pitch/slice_pitch for images yet.
4802-
// Check that SYCL RT did not want pitch larger than default.
4838+
// TODO: Level Zero does not support row_pitch/slice_pitch for images yet.
4839+
// Check that SYCL RT did not want pitch larger than default.
48034840
(void)RowPitch;
48044841
(void)SlicePitch;
48054842
#ifndef NDEBUG

0 commit comments

Comments
 (0)