Skip to content

Commit 608ce45

Browse files
committed
update allocation.
Signed-off-by: rbegam <[email protected]>
1 parent 1244582 commit 608ce45

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,6 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
20712071
}
20722072
PI_ASSERT(Context, PI_INVALID_CONTEXT);
20732073
PI_ASSERT(RetMem, PI_INVALID_VALUE);
2074-
PI_ASSERT(HostPtr && PI_MEM_FLAGS_HOST_PTR_ALLOC, PI_INVALID_VALUE);
20752074

20762075
if (properties != nullptr) {
20772076
die("piMemBufferCreate: no mem properties goes to Level-Zero RT yet");
@@ -2080,10 +2079,6 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
20802079
void *Ptr;
20812080
ze_device_handle_t ZeDevice = Context->Devices[0]->ZeDevice;
20822081

2083-
ze_device_mem_alloc_desc_t ZeDeviceMemDesc = {};
2084-
ZeDeviceMemDesc.flags = 0;
2085-
ZeDeviceMemDesc.ordinal = 0;
2086-
20872082
// We treat integrated devices (physical memory shared with the CPU)
20882083
// differently from discrete devices (those with distinct memories).
20892084
// For integrated devices, allocating the buffer in host shared memory
@@ -2093,28 +2088,31 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
20932088
Context->Devices[0]->ZeDeviceProperties.flags &
20942089
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
20952090

2091+
// PI_MEM_FLAGS_HOST_PTR_ALLOC flag indicates allocation of pinned
2092+
// host memory which is accessible from device.
20962093
bool AllocHostPtr = Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC;
20972094

2098-
if (DeviceIsIntegrated) {
2095+
if (AllocHostPtr) {
2096+
assert(HostPtr == nullptr &&
2097+
"PI_MEM_FLAGS_HOST_PTR_ALLOC cannot be used with host pointer");
2098+
20992099
ze_host_mem_alloc_desc_t ZeDesc = {};
21002100
ZeDesc.flags = 0;
21012101

21022102
ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, 1, &Ptr));
2103+
}
21032104

2104-
} else if (AllocHostPtr) {
2105-
// Currently L0 does not support allocation of pinned
2106-
// host memory. So for PI_MEM_FLAGS_HOST_PTR_ALLOC flag, it allocates
2107-
// from host accessible memory.
2108-
ze_host_mem_alloc_desc_t ZeHostMemDesc = {};
2109-
ZeHostMemDesc.flags = 0;
2105+
if (DeviceIsIntegrated) {
2106+
ze_host_mem_alloc_desc_t ZeDesc = {};
2107+
ZeDesc.flags = 0;
21102108

2111-
ZE_CALL(zeMemAllocShared(Context->ZeContext, &ZeDeviceMemDesc,
2112-
&ZeHostMemDesc, Size,
2113-
1, // TODO: alignment
2114-
nullptr, // not bound to any device
2115-
&Ptr));
2109+
ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, 1, &Ptr));
21162110

21172111
} else {
2112+
ze_device_mem_alloc_desc_t ZeDeviceMemDesc = {};
2113+
ZeDeviceMemDesc.flags = 0;
2114+
ZeDeviceMemDesc.ordinal = 0;
2115+
21182116
ZE_CALL(zeMemAllocDevice(Context->ZeContext, &ZeDeviceMemDesc, Size, 1,
21192117
ZeDevice, &Ptr));
21202118
}

0 commit comments

Comments
 (0)