Skip to content

Commit 2de2710

Browse files
committed
resolved conflicts.
Signed-off-by: rbegam <[email protected]>
1 parent 689f3fc commit 2de2710

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,10 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
20792079
void *Ptr;
20802080
ze_device_handle_t ZeDevice = Context->Devices[0]->ZeDevice;
20812081

2082+
ze_device_mem_alloc_desc_t ZeDeviceMemDesc = {};
2083+
ZeDeviceMemDesc.flags = 0;
2084+
ZeDeviceMemDesc.ordinal = 0;
2085+
20822086
// We treat integrated devices (physical memory shared with the CPU)
20832087
// differently from discrete devices (those with distinct memories).
20842088
// For integrated devices, allocating the buffer in host shared memory
@@ -2088,36 +2092,36 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
20882092
Context->Devices[0]->ZeDeviceProperties.flags &
20892093
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
20902094

2095+
bool AllocHostPtr = Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC;
2096+
20912097
if (DeviceIsIntegrated) {
20922098
ze_host_mem_alloc_desc_t ZeDesc = {};
20932099
ZeDesc.flags = 0;
20942100

20952101
ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeDesc, Size, 1, &Ptr));
20962102

2097-
} else {
2098-
ze_device_mem_alloc_desc_t ZeDesc = {};
2099-
ZeDesc.flags = 0;
2100-
ZeDesc.ordinal = 0;
2103+
} else if (AllocHostPtr){
2104+
// Currently L0 does not support allocation of pinned
2105+
// host memory. So for PI_MEM_FLAGS_HOST_PTR_ALLOC flag, it allocates
2106+
// from host accessible memory.
2107+
ze_host_mem_alloc_desc_t ZeHostMemDesc = {};
2108+
ZeHostMemDesc.flags = 0;
2109+
2110+
ZE_CALL(zeMemAllocShared(Context->ZeContext, &ZeDeviceMemDesc,
2111+
&ZeHostMemDesc, Size,
2112+
1, // TODO: alignment
2113+
nullptr, // not bound to any device
2114+
&Ptr));
21012115

2116+
} else {
21022117
ZE_CALL(
2103-
zeMemAllocDevice(Context->ZeContext, &ZeDesc, Size, 1, ZeDevice, &Ptr));
2118+
zeMemAllocDevice(Context->ZeContext, &ZeDeviceMemDesc, Size, 1,
2119+
ZeDevice, &Ptr));
21042120
}
2121+
21052122
if (HostPtr) {
2106-
// Currently zeMemAllocHost() does not support allocation of pinned
2107-
// host memory. So for PI_MEM_FLAGS_HOST_PTR_ALLOC flag, it allocates
2108-
// pageable host memory.
2109-
if ((Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC) != 0) {
2110-
ze_host_mem_alloc_desc_t ZeHostDesc = {};
2111-
ZeHostDesc.flags = 0;
2112-
2113-
ZE_CALL(zeMemAllocHost(Context->ZeContext, &ZeHostDesc, Size,
2114-
1, // TODO: alignment
2115-
&HostPtr));
2116-
ZE_CALL(zeCommandListAppendMemoryCopy(Context->ZeCommandListInit, Ptr,
2117-
HostPtr, Size, nullptr, 0,
2118-
nullptr));
2119-
} else if ((Flags & PI_MEM_FLAGS_HOST_PTR_USE) != 0 ||
2120-
(Flags & PI_MEM_FLAGS_HOST_PTR_COPY) != 0) {
2123+
if ((Flags & PI_MEM_FLAGS_HOST_PTR_USE) != 0 ||
2124+
(Flags & PI_MEM_FLAGS_HOST_PTR_COPY) != 0) {
21212125
// Initialize the buffer with user data
21222126
if (DeviceIsIntegrated) {
21232127
// Do a host to host copy
@@ -2129,14 +2133,16 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
21292133
HostPtr, Size, nullptr, 0,
21302134
nullptr));
21312135
}
2136+
} else if ((Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC) != 0) {
2137+
// Nothing more to do.
21322138
} else if (Flags == 0 || (Flags == PI_MEM_FLAGS_ACCESS_RW)) {
21332139
// Nothing more to do.
21342140
} else {
21352141
die("piMemBufferCreate: not implemented");
21362142
}
21372143
}
21382144

2139-
auto HostPtrOrNull = (Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC) ||
2145+
auto HostPtrOrNull =
21402146
(Flags & PI_MEM_FLAGS_HOST_PTR_USE) ? pi_cast<char *>(HostPtr) : nullptr;
21412147
try {
21422148
*RetMem = new _pi_buffer(

0 commit comments

Comments
 (0)