@@ -2071,7 +2071,6 @@ pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags, size_t Size,
2071
2071
}
2072
2072
PI_ASSERT (Context, PI_INVALID_CONTEXT);
2073
2073
PI_ASSERT (RetMem, PI_INVALID_VALUE);
2074
- PI_ASSERT (HostPtr && PI_MEM_FLAGS_HOST_PTR_ALLOC, PI_INVALID_VALUE);
2075
2074
2076
2075
if (properties != nullptr ) {
2077
2076
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,
2080
2079
void *Ptr;
2081
2080
ze_device_handle_t ZeDevice = Context->Devices [0 ]->ZeDevice ;
2082
2081
2083
- ze_device_mem_alloc_desc_t ZeDeviceMemDesc = {};
2084
- ZeDeviceMemDesc.flags = 0 ;
2085
- ZeDeviceMemDesc.ordinal = 0 ;
2086
-
2087
2082
// We treat integrated devices (physical memory shared with the CPU)
2088
2083
// differently from discrete devices (those with distinct memories).
2089
2084
// 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,
2093
2088
Context->Devices [0 ]->ZeDeviceProperties .flags &
2094
2089
ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
2095
2090
2091
+ // PI_MEM_FLAGS_HOST_PTR_ALLOC flag indicates allocation of pinned
2092
+ // host memory which is accessible from device.
2096
2093
bool AllocHostPtr = Flags & PI_MEM_FLAGS_HOST_PTR_ALLOC;
2097
2094
2098
- if (DeviceIsIntegrated) {
2095
+ if (AllocHostPtr) {
2096
+ assert (HostPtr == nullptr &&
2097
+ " PI_MEM_FLAGS_HOST_PTR_ALLOC cannot be used with host pointer" );
2098
+
2099
2099
ze_host_mem_alloc_desc_t ZeDesc = {};
2100
2100
ZeDesc.flags = 0 ;
2101
2101
2102
2102
ZE_CALL (zeMemAllocHost (Context->ZeContext , &ZeDesc, Size, 1 , &Ptr));
2103
+ }
2103
2104
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 ;
2110
2108
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));
2116
2110
2117
2111
} else {
2112
+ ze_device_mem_alloc_desc_t ZeDeviceMemDesc = {};
2113
+ ZeDeviceMemDesc.flags = 0 ;
2114
+ ZeDeviceMemDesc.ordinal = 0 ;
2115
+
2118
2116
ZE_CALL (zeMemAllocDevice (Context->ZeContext , &ZeDeviceMemDesc, Size, 1 ,
2119
2117
ZeDevice, &Ptr));
2120
2118
}
0 commit comments