Skip to content

Commit 41562aa

Browse files
committed
adds a test and comments.
Signed-off-by: rbegam <[email protected]>
1 parent cb74ace commit 41562aa

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,21 +2088,25 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
20882088
Context->Devices[0]->ZeDeviceProperties.flags &
20892089
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
20902090

2091-
// PI_MEM_FLAGS_HOST_PTR_ALLOC flag indicates allocation of pinned
2092-
// host memory which is accessible from device.
2091+
// Having PI_MEM_FLAGS_HOST_PTR_ALLOC for buffer requires allocation of
2092+
// pinned host memory which then becomes automatically accessible from
2093+
// discrete devices through PCI. This property ensures that the memory
2094+
// map/unmap operations are free of cost and the buffer is optimized for
2095+
// frequent accesses from the host giving improved performance.
2096+
// see:
2097+
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/UsePinnedMemoryProperty/UsePinnedMemoryPropery.adoc
20932098
bool AllocHostPtr = Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC;
20942099

20952100
if (AllocHostPtr) {
2096-
assert(HostPtr == nullptr &&
2097-
"PI_MEM_FLAGS_HOST_PTR_ALLOC cannot be used with host pointer");
2101+
PI_ASSERT(HostPtr == nullptr, PI_INVALID_VALUE);
20982102

20992103
ze_host_mem_alloc_desc_t ZeDesc = {};
21002104
ZeDesc.flags = 0;
21012105

21022106
ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, 1, &Ptr));
2103-
}
21042107

2105-
if (DeviceIsIntegrated) {
2108+
} else if (DeviceIsIntegrated) {
2109+
21062110
ze_host_mem_alloc_desc_t ZeDesc = {};
21072111
ZeDesc.flags = 0;
21082112

@@ -2144,7 +2148,7 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
21442148
*RetMem = new _pi_buffer(
21452149
Context, pi_cast<char *>(Ptr) /* Level Zero Memory Handle */,
21462150
HostPtrOrNull, nullptr, 0, 0,
2147-
DeviceIsIntegrated /* Flag indicating allocation in host memory */);
2151+
AllocHostPtr || DeviceIsIntegrated /* allocation in host memory */);
21482152
} catch (const std::bad_alloc &) {
21492153
return PI_OUT_OF_HOST_MEMORY;
21502154
} catch (...) {
@@ -4283,8 +4287,8 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
42834287
void **RetMap) {
42844288

42854289
// TODO: we don't implement read-only or write-only, always read-write.
4286-
// assert((map_flags & CL_MAP_READ) != 0);
4287-
// assert((map_flags & CL_MAP_WRITE) != 0);
4290+
// assert((map_flags & PI_MAP_READ) != 0);
4291+
// assert((map_flags & PI_MAP_WRITE) != 0);
42884292
PI_ASSERT(Buffer, PI_INVALID_MEM_OBJECT);
42894293
PI_ASSERT(Queue, PI_INVALID_QUEUE);
42904294

@@ -4307,17 +4311,18 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
43074311

43084312
// TODO: Level Zero is missing the memory "mapping" capabilities, so we are
43094313
// left to doing new memory allocation and a copy (read) on discrete devices.
4310-
// On integrated devices we have allocated the buffer in host memory
4311-
// so no actions are needed here except for synchronizing on incoming events
4312-
// and doing a host-to-host copy if a host pointer had been supplied
4313-
// during buffer creation.
4314+
// For pinned host memory and integrated devices, we have allocated the
4315+
// buffer in host memory so no actions are needed here except for
4316+
// synchronizing on incoming events. A host-to-host copy is done if a host
4317+
// pointer had been supplied during buffer creation on integrated devices.
43144318
//
43154319
// TODO: for discrete, check if the input buffer is already allocated
43164320
// in shared memory and thus is accessible from the host as is.
43174321
// Can we get SYCL RT to predict/allocate in shared memory
43184322
// from the beginning?
4319-
//
4320-
// On integrated devices the buffer has been allocated in host memory.
4323+
4324+
// For pinned host memory and integrated devices the buffer has been
4325+
// allocated in host memory.
43214326
if (Buffer->OnHost) {
43224327
// Wait on incoming events before doing the copy
43234328
piEventsWait(NumEventsInWaitList, EventWaitList);
@@ -4417,7 +4422,8 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
44174422
(*Event)->CommandData =
44184423
(MemObj->OnHost ? nullptr : (MemObj->MapHostPtr ? nullptr : MappedPtr));
44194424

4420-
// On integrated devices the buffer is allocated in host memory.
4425+
// For pinned host memory and integrated devices the buffer is allocated
4426+
// in host memory.
44214427
if (MemObj->OnHost) {
44224428
// Wait on incoming events before doing the copy
44234429
piEventsWait(NumEventsInWaitList, EventWaitList);

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ struct _pi_mem : _pi_object {
390390
char *MapHostPtr;
391391

392392
// Flag to indicate that this memory is allocated in host memory
393+
// if created with PI_MEM_FLAGS_HOST_PTR_ALLOC and/or integrated devices.
393394
bool OnHost;
394395

395396
// Supplementary data to keep track of the mappings of this memory

0 commit comments

Comments
 (0)