Skip to content

[SYCL] Revert support for pinned_host_memory extension in Level-Zero backend. Make it a NOP #3349

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

Merged
merged 2 commits into from
Mar 13, 2021
Merged
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
36 changes: 15 additions & 21 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -2341,7 +2337,7 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
*RetMem = new _pi_buffer(
Context, pi_cast<char *>(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 (...) {
Expand Down Expand Up @@ -4580,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));
Expand Down Expand Up @@ -4695,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));
Expand Down