Skip to content

Commit 2717f9f

Browse files
committed
Merge branch 'ibuf3' of https://github.com/rdeodhar/llvm into ibuf3
2 parents a799ff4 + 3e7a03c commit 2717f9f

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,8 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
19131913
try {
19141914
*RetMem = new _pi_buffer(
19151915
Context, pi_cast<char *>(Ptr) /* Level Zero Memory Handle */,
1916-
HostPtrOrNull);
1916+
HostPtrOrNull, nullptr, 0, 0,
1917+
DeviceIsIntegrated /* Flag indicating allocation in host memory */);
19171918
} catch (const std::bad_alloc &) {
19181919
return PI_OUT_OF_HOST_MEMORY;
19191920
} catch (...) {
@@ -3996,22 +3997,6 @@ piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer, pi_bool BlockingMap,
39963997
assert(Buffer);
39973998
assert(Queue);
39983999

3999-
// Check if this is an integrated device
4000-
bool DeviceIsIntegrated = Queue->Device->ZeDeviceProperties.flags &
4001-
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
4002-
4003-
// Query the buffer allocation to determine if host allocation
4004-
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
4005-
ze_device_handle_t ZeDeviceHandle;
4006-
4007-
ZE_CALL(
4008-
zeMemGetAllocProperties(Queue->Context->ZeContext, Buffer->getZeHandle(),
4009-
&ZeMemoryAllocationProperties, &ZeDeviceHandle));
4010-
4011-
bool BufferUsesHostMem =
4012-
DeviceIsIntegrated &&
4013-
(ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_HOST);
4014-
40154000
// For discrete devices we don't need a commandlist
40164001
ze_command_list_handle_t ZeCommandList = nullptr;
40174002
ze_fence_handle_t ZeFence = nullptr;
@@ -4040,7 +4025,9 @@ piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer, pi_bool BlockingMap,
40404025
// in shared memory and thus is accessible from the host as is.
40414026
// Can we get SYCL RT to predict/allocate in shared memory
40424027
// from the beginning?
4043-
if (BufferUsesHostMem) {
4028+
//
4029+
// On integrated devices the buffer has been allocated in host memory.
4030+
if (Buffer->OnHost) {
40444031
// Wait on incoming events before doing the copy
40454032
piEventsWait(NumEventsInWaitList, EventWaitList);
40464033
if (Buffer->MapHostPtr) {
@@ -4097,22 +4084,6 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
40974084
const pi_event *EventWaitList, pi_event *Event) {
40984085
assert(Queue);
40994086

4100-
// Check if this is an integrated device
4101-
bool DeviceIsIntegrated = Queue->Device->ZeDeviceProperties.flags &
4102-
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
4103-
4104-
// Query the buffer allocation to determine if host allocation
4105-
ze_memory_allocation_properties_t ZeMemoryAllocationProperties = {};
4106-
ze_device_handle_t ZeDeviceHandle;
4107-
4108-
ZE_CALL(
4109-
zeMemGetAllocProperties(Queue->Context->ZeContext, MemObj->getZeHandle(),
4110-
&ZeMemoryAllocationProperties, &ZeDeviceHandle));
4111-
4112-
bool BufferUsesHostMem =
4113-
DeviceIsIntegrated &&
4114-
(ZeMemoryAllocationProperties.type == ZE_MEMORY_TYPE_HOST);
4115-
41164087
// Integrated devices don't need a command list.
41174088
// If discrete we will get a commandlist later.
41184089
ze_command_list_handle_t ZeCommandList = nullptr;
@@ -4147,10 +4118,10 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
41474118
// any memory, so there is nothing to free. This is indicated by a nullptr.
41484119
if (Event)
41494120
(*Event)->CommandData =
4150-
(BufferUsesHostMem ? nullptr
4151-
: (MemObj->MapHostPtr ? nullptr : MappedPtr));
4121+
(MemObj->OnHost ? nullptr : (MemObj->MapHostPtr ? nullptr : MappedPtr));
41524122

4153-
if (BufferUsesHostMem) {
4123+
// On integrated devices the buffer is allocated in host memory.
4124+
if (MemObj->OnHost) {
41544125
// Wait on incoming events before doing the copy
41554126
piEventsWait(NumEventsInWaitList, EventWaitList);
41564127
memcpy(pi_cast<char *>(MemObj->getZeHandle()) + MapInfo.Offset, MappedPtr,

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ struct _pi_mem : _pi_object {
354354
// piEnqueueMemBufferMap for details).
355355
char *MapHostPtr;
356356

357+
// Flag to indicate that this memory is allocated in host memory
358+
bool OnHost;
359+
357360
// Supplementary data to keep track of the mappings of this memory
358361
// created with piEnqueueMemBufferMap and piEnqueueMemImageMap.
359362
struct Mapping {
@@ -381,8 +384,8 @@ struct _pi_mem : _pi_object {
381384
pi_result removeMapping(void *MappedTo, Mapping &MapInfo);
382385

383386
protected:
384-
_pi_mem(pi_context Ctx, char *HostPtr)
385-
: Context{Ctx}, MapHostPtr{HostPtr}, Mappings{} {}
387+
_pi_mem(pi_context Ctx, char *HostPtr, bool MemOnHost = false)
388+
: Context{Ctx}, MapHostPtr{HostPtr}, OnHost{MemOnHost}, Mappings{} {}
386389

387390
private:
388391
// The key is the host pointer representing an active mapping.
@@ -398,8 +401,10 @@ struct _pi_mem : _pi_object {
398401
struct _pi_buffer final : _pi_mem {
399402
// Buffer/Sub-buffer constructor
400403
_pi_buffer(pi_context Ctx, char *Mem, char *HostPtr,
401-
_pi_mem *Parent = nullptr, size_t Origin = 0, size_t Size = 0)
402-
: _pi_mem(Ctx, HostPtr), ZeMem{Mem}, SubBuffer{Parent, Origin, Size} {}
404+
_pi_mem *Parent = nullptr, size_t Origin = 0, size_t Size = 0,
405+
bool MemOnHost = false)
406+
: _pi_mem(Ctx, HostPtr, MemOnHost), ZeMem{Mem}, SubBuffer{Parent, Origin,
407+
Size} {}
403408

404409
void *getZeHandle() override { return ZeMem; }
405410

0 commit comments

Comments
 (0)