Skip to content

Commit a031173

Browse files
committed
Merge branch 'ibuf3' of https://github.com/rdeodhar/llvm into ibuf3
2 parents 6445c61 + dd683b3 commit a031173

File tree

2 files changed

+43
-111
lines changed

2 files changed

+43
-111
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 41 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,21 +3322,9 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {
33223322
ze_event_handle_t ZeEvent = EventList[I]->ZeEvent;
33233323
zePrint("ZeEvent = %lx\n", pi_cast<std::uintptr_t>(ZeEvent));
33243324

3325-
// If event comes from a Map/UnMap operation in integrated device, then do
3326-
// sync, memcpy, and signaling on the host
3325+
// If event comes from a Map/UnMap operation on integrated device
3326+
// then nothing needs to be done here except signal the event.
33273327
if (EventList[I]->HostSyncforMap) {
3328-
#if 0
3329-
for (auto ZeWaitEvent : EventList[I]->waitEvents) {
3330-
zePrint("ZeWaitEvent = %lx\n", pi_cast<std::uintptr_t>(ZeWaitEvent));
3331-
if (ZeWaitEvent)
3332-
ZE_CALL(zeEventHostSynchronize(ZeWaitEvent, UINT32_MAX));
3333-
}
3334-
if (EventList[I]->CopyPending) {
3335-
memcpy(EventList[I]->DstBuffer, EventList[I]->SrcBuffer,
3336-
EventList[I]->RetMapSize);
3337-
EventList[I]->CopyPending = false;
3338-
}
3339-
#endif
33403328
ZE_CALL(zeEventHostSignal(ZeEvent));
33413329
} else {
33423330
ZE_CALL(zeEventHostSynchronize(ZeEvent, UINT32_MAX));
@@ -4015,9 +4003,6 @@ piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer, pi_bool BlockingMap,
40154003
assert(Buffer);
40164004
assert(Queue);
40174005

4018-
// Lock automatically releases when this goes out of scope.
4019-
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
4020-
40214006
// Query the buffer allocation to determine if host allocation
40224007
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
40234008
ze_device_handle_t ZeDeviceHandle;
@@ -4058,51 +4043,23 @@ piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer, pi_bool BlockingMap,
40584043
// Can we get SYCL RT to predict/allocate in shared memory
40594044
// from the beginning?
40604045
if (BufferUsesHostMem) {
4061-
(*Event)->HostSyncforMap = true;
4062-
#if 0
4063-
for (uint32_t i = 0; i < NumEventsInWaitList; i++) {
4064-
zePrint("Map added ZeWaitEvent = %lx\n",
4065-
pi_cast<std::uintptr_t>(EventWaitList[i]->ZeEvent));
4066-
(*Event)->waitEvents.push_back(EventWaitList[i]->ZeEvent);
4067-
}
4068-
#else
4069-
for (uint32_t i = 0; i < NumEventsInWaitList; i++) {
4070-
auto Queue = EventWaitList[i]->Queue;
4071-
zePrint("Got Q\n");
4072-
if (Queue->RefCount > 0) {
4073-
zePrint("Executing commandlist\n");
4074-
if (auto Res = Queue->executeOpenCommandList())
4075-
return Res;
4076-
}
4077-
}
4078-
for (uint32_t i = 0; i < NumEventsInWaitList; i++) {
4079-
zePrint("Going to wait on ZeWaitEvent = %lx\n",
4080-
pi_cast<std::uintptr_t>(EventWaitList[i]->ZeEvent));
4081-
auto ZeWaitEvent = EventWaitList[i]->ZeEvent;
4082-
if (ZeWaitEvent)
4083-
ZE_CALL(zeEventHostSynchronize(ZeWaitEvent, UINT32_MAX));
4084-
}
4085-
#endif
4046+
// Wait on incoming events before doing the copy
4047+
piEventsWait(NumEventsInWaitList, EventWaitList);
40864048
if (Buffer->MapHostPtr) {
40874049
*RetMap = Buffer->MapHostPtr + Offset;
4088-
#if 0
4089-
(*Event)->SrcBuffer = pi_cast<char*>(Buffer->getZeHandle()) + Offset;
4090-
(*Event)->DstBuffer = *RetMap;
4091-
(*Event)->RetMapSize = Size;
4092-
(*Event)->CopyPending = true;
4093-
#else
4094-
zePrint("Doing memcpy %p %p %zu\n", *RetMap,
4095-
pi_cast<char *>(Buffer->getZeHandle()) + Offset, Size);
40964050
memcpy(*RetMap, pi_cast<char *>(Buffer->getZeHandle()) + Offset, Size);
4097-
zePrint("DONE\n");
4098-
#endif
40994051
} else {
41004052
*RetMap = pi_cast<char *>(Buffer->getZeHandle()) + Offset;
41014053
}
4054+
// Mark this event as handled
4055+
(*Event)->HostSyncforMap = true;
41024056

41034057
return Buffer->addMapping(*RetMap, Offset, Size);
41044058
}
41054059

4060+
// Lock automatically releases when this goes out of scope.
4061+
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
4062+
41064063
// For discrete devices we need a command list
41074064
if (auto Res = Queue->Device->getAvailableCommandList(Queue, &ZeCommandList,
41084065
&ZeFence))
@@ -4141,9 +4098,6 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
41414098
const pi_event *EventWaitList, pi_event *Event) {
41424099
assert(Queue);
41434100

4144-
// Lock automatically releases when this goes out of scope.
4145-
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
4146-
41474101
// Query the buffer allocation to determine if host allocation
41484102
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
41494103
ze_device_handle_t ZeDeviceHandle;
@@ -4194,57 +4148,47 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
41944148

41954149
if (BufferUsesHostMem) {
41964150
(*Event)->HostSyncforMap = true;
4197-
#if 0
4198-
for (uint32_t i = 0; i < NumEventsInWaitList; i++) {
4199-
zePrint("UnMap Added ZeWaitEvent = %lx\n",
4200-
pi_cast<std::uintptr_t>(EventWaitList[i]->ZeEvent));
4201-
(*Event)->waitEvents.push_back(EventWaitList[i]->ZeEvent);
4202-
}
4203-
(*Event)->SrcBuffer = MappedPtr;
4204-
(*Event)->DstBuffer =
4205-
pi_cast<char*>(MemObj->getZeHandle()) + MapInfo.Offset;
4206-
(*Event)->RetMapSize = MapInfo.Size;
4207-
(*Event)->CopyPending = true;
4208-
#else
4209-
for (uint32_t i = 0; i < NumEventsInWaitList; i++) {
4210-
auto ZeWaitEvent = EventWaitList[i]->ZeEvent;
4211-
if (ZeWaitEvent)
4212-
ZE_CALL(zeEventHostSynchronize(ZeWaitEvent, UINT32_MAX));
4213-
}
4151+
// Wait on incoming events before doing the copy
4152+
piEventsWait(NumEventsInWaitList, EventWaitList);
42144153
memcpy(pi_cast<char *>(MemObj->getZeHandle()) + MapInfo.Offset, MappedPtr,
42154154
MapInfo.Size);
4216-
#endif
4217-
} else {
4155+
// Mark this event as handled
4156+
(*Event)->HostSyncforMap = true;
42184157

4219-
if (auto Res = Queue->Device->getAvailableCommandList(Queue, &ZeCommandList,
4220-
&ZeFence))
4221-
return Res;
4158+
return PI_SUCCESS;
4159+
}
42224160

4223-
ze_event_handle_t *ZeEventWaitList =
4224-
_pi_event::createZeEventList(NumEventsInWaitList, EventWaitList);
4161+
// Lock automatically releases when this goes out of scope.
4162+
std::lock_guard<std::mutex> lock(Queue->PiQueueMutex);
42254163

4226-
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, NumEventsInWaitList,
4227-
ZeEventWaitList));
4164+
if (auto Res = Queue->Device->getAvailableCommandList(Queue, &ZeCommandList,
4165+
&ZeFence))
4166+
return Res;
42284167

4229-
// TODO: Level Zero is missing the memory "mapping" capabilities, so we are
4230-
// left to doing copy (write back to the device).
4231-
// See https://gitlab.devtools.intel.com/one-api/level_zero/issues/293. //
4232-
// INTEL
4233-
//
4234-
// NOTE: Keep this in sync with the implementation of
4235-
// piEnqueueMemBufferMap/piEnqueueMemImageMap.
4168+
ze_event_handle_t *ZeEventWaitList =
4169+
_pi_event::createZeEventList(NumEventsInWaitList, EventWaitList);
42364170

4237-
ZE_CALL(zeCommandListAppendMemoryCopy(
4238-
ZeCommandList, pi_cast<char *>(MemObj->getZeHandle()) + MapInfo.Offset,
4239-
MappedPtr, MapInfo.Size, ZeEvent, 0, nullptr));
4171+
ZE_CALL(zeCommandListAppendWaitOnEvents(ZeCommandList, NumEventsInWaitList,
4172+
ZeEventWaitList));
42404173

4241-
// Execute command list asynchronously, as the event will be used
4242-
// to track down its completion.
4243-
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence))
4244-
return Res;
4174+
// TODO: Level Zero is missing the memory "mapping" capabilities, so we are
4175+
// left to doing copy (write back to the device).
4176+
// See https://gitlab.devtools.intel.com/one-api/level_zero/issues/293. //
4177+
// INTEL
4178+
//
4179+
// NOTE: Keep this in sync with the implementation of
4180+
// piEnqueueMemBufferMap/piEnqueueMemImageMap.
42454181

4246-
_pi_event::deleteZeEventList(ZeEventWaitList);
4247-
}
4182+
ZE_CALL(zeCommandListAppendMemoryCopy(
4183+
ZeCommandList, pi_cast<char *>(MemObj->getZeHandle()) + MapInfo.Offset,
4184+
MappedPtr, MapInfo.Size, ZeEvent, 0, nullptr));
4185+
4186+
// Execute command list asynchronously, as the event will be used
4187+
// to track down its completion.
4188+
if (auto Res = Queue->executeCommandList(ZeCommandList, ZeFence))
4189+
return Res;
4190+
4191+
_pi_event::deleteZeEventList(ZeEventWaitList);
42484192

42494193
return PI_SUCCESS;
42504194
}

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,9 @@ struct _pi_event : _pi_object {
451451
// Level Zero event pool handle.
452452
ze_event_pool_handle_t ZeEventPool;
453453

454-
// The following are used by MemBufferMap/UnMap on integrated devices
455-
// Flag to indicate that a copy is pending from a map/unmap operation
454+
// This flag is used by MemBufferMap/UnMap on integrated devices
455+
// to indicate that all actions have already been done.
456456
bool HostSyncforMap = false;
457-
#if 0
458-
// List of incoming events to be satisfied before the copy can be done
459-
std::vector<ze_event_handle_t> waitEvents;
460-
// The destination of the map/unmap copy
461-
void *DstBuffer = nullptr;
462-
// The source of the map/unmap copy
463-
void *SrcBuffer = nullptr;
464-
// The size of the copy
465-
size_t RetMapSize = 0;
466-
// A flag that enables doing the copy only once, for a list of events
467-
bool CopyPending = false;
468-
#endif
469457

470458
// Level Zero command list where the command signaling this event was appended
471459
// to. This is currently used to remember/destroy the command list after all

0 commit comments

Comments
 (0)