From b6173e3a6c401dbe1522399229813ce93abf4d2d Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Thu, 11 Mar 2021 16:20:20 -0800 Subject: [PATCH 1/2] [SYCL] Revert support for pinned_host_memory extension in Level-Zero backend. Make it a NOP Signed-off-by: Sergey V Maslov --- sycl/plugins/level_zero/pi_level_zero.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 183f1285057e6..48e484e089632 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -2286,20 +2286,16 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size, Context->Devices[0]->ZeDeviceProperties.flags & ZE_DEVICE_PROPERTY_FLAG_INTEGRATED; - // Having PI_MEM_FLAGS_HOST_PTR_ALLOC for buffer requires allocation of - // pinned host memory which then becomes automatically accessible from - // discrete devices through PCI. This property ensures that the memory - // map/unmap operations are free of cost and the buffer is optimized for - // frequent accesses from the host giving improved performance. - // see: - // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/UsePinnedMemoryProperty/UsePinnedMemoryPropery.adoc - bool AllocHostPtr = Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC; - - if (AllocHostPtr) { - PI_ASSERT(HostPtr == nullptr, PI_INVALID_VALUE); + if (Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC) { + // Having PI_MEM_FLAGS_HOST_PTR_ALLOC for buffer requires allocation of + // pinned host memory, see: + // https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/UsePinnedMemoryProperty/UsePinnedMemoryPropery.adoc + // We are however missing such functionality in Level Zero, so we just + // ignore the flag for now. + // } - if (AllocHostPtr || DeviceIsIntegrated) { + if (DeviceIsIntegrated) { ze_host_mem_alloc_desc_t ZeDesc = {}; ZeDesc.flags = 0; @@ -2341,7 +2337,7 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size, *RetMem = new _pi_buffer( Context, pi_cast(Ptr) /* Level Zero Memory Handle */, HostPtrOrNull, nullptr, 0, 0, - AllocHostPtr || DeviceIsIntegrated /* allocation in host memory */); + DeviceIsIntegrated /* allocation in host memory */); } catch (const std::bad_alloc &) { return PI_OUT_OF_HOST_MEMORY; } catch (...) { From d2a3c815e84277e1a8e213faf4d2364fa7cbea8c Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Thu, 11 Mar 2021 16:45:54 -0800 Subject: [PATCH 2/2] address review comments Signed-off-by: Sergey V Maslov --- sycl/plugins/level_zero/pi_level_zero.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 48e484e089632..ada35944e502b 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -4576,18 +4576,17 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer, // TODO: Level Zero is missing the memory "mapping" capabilities, so we are // left to doing new memory allocation and a copy (read) on discrete devices. - // For pinned host memory and integrated devices, we have allocated the - // buffer in host memory so no actions are needed here except for - // synchronizing on incoming events. A host-to-host copy is done if a host - // pointer had been supplied during buffer creation on integrated devices. + // For integrated devices, we have allocated the buffer in host memory so no + // actions are needed here except for synchronizing on incoming events. + // A host-to-host copy is done if a host pointer had been supplied during + // buffer creation on integrated devices. // // TODO: for discrete, check if the input buffer is already allocated // in shared memory and thus is accessible from the host as is. // Can we get SYCL RT to predict/allocate in shared memory // from the beginning? - // For pinned host memory and integrated devices the buffer has been - // allocated in host memory. + // For integrated devices the buffer has been allocated in host memory. if (Buffer->OnHost) { // Wait on incoming events before doing the copy PI_CALL(piEventsWait(NumEventsInWaitList, EventWaitList)); @@ -4691,8 +4690,7 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr, (*Event)->CommandData = (MemObj->OnHost ? nullptr : (MemObj->MapHostPtr ? nullptr : MappedPtr)); - // For pinned host memory and integrated devices the buffer is allocated - // in host memory. + // For integrated devices the buffer is allocated in host memory. if (MemObj->OnHost) { // Wait on incoming events before doing the copy PI_CALL(piEventsWait(NumEventsInWaitList, EventWaitList));