Skip to content

Commit f3999e1

Browse files
committed
[UR] Pull in fix that allows handling location properties in USM allocs.
Also handle translating these properties in pi2ur.
1 parent 2f644e3 commit f3999e1

File tree

2 files changed

+76
-34
lines changed

2 files changed

+76
-34
lines changed

sycl/plugins/unified_runtime/CMakeLists.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@ endif()
5656
if(SYCL_PI_UR_USE_FETCH_CONTENT)
5757
include(FetchContent)
5858

59-
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
60-
# commit 47af3ee296ae0517213114332ffd3ac54a456b16
61-
# Merge: bd76c510 f2ca7a91
62-
# Author: Omar Ahmed <[email protected]>
63-
# Date: Thu Nov 30 16:11:56 2023 +0000
64-
# - Merge pull request #1072 from omarahmed1111/merge-some-main-changes-into-adapters-third-patch
65-
# - Merge main into adapters branch
66-
set(UNIFIED_RUNTIME_TAG 47af3ee296ae0517213114332ffd3ac54a456b16)
59+
set(UNIFIED_RUNTIME_REPO "https://github.com/aarongreig/unified-runtime.git")
60+
61+
set(UNIFIED_RUNTIME_TAG b78f541d27246f542287e77496fea7c2f04aadf5)
6762

6863
if(SYCL_PI_UR_OVERRIDE_FETCH_CONTENT_REPO)
6964
set(UNIFIED_RUNTIME_REPO "${SYCL_PI_UR_OVERRIDE_FETCH_CONTENT_REPO}")

sycl/plugins/unified_runtime/pi2ur.hpp

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,12 +2697,28 @@ inline pi_result piMemBufferCreate(pi_context Context, pi_mem_flags Flags,
26972697
inline pi_result piextUSMHostAlloc(void **ResultPtr, pi_context Context,
26982698
pi_usm_mem_properties *Properties,
26992699
size_t Size, pi_uint32 Alignment) {
2700+
ur_usm_desc_t USMDesc{};
2701+
USMDesc.align = Alignment;
2702+
2703+
ur_usm_alloc_location_desc_t UsmLocationDesc{};
2704+
UsmLocationDesc.stype = UR_STRUCTURE_TYPE_USM_ALLOC_LOCATION_DESC;
2705+
2706+
if (Properties) {
2707+
uint32_t Next = 0;
2708+
while (Properties[Next]) {
2709+
if (Properties[Next] == PI_MEM_USM_ALLOC_BUFFER_LOCATION) {
2710+
UsmLocationDesc.location = static_cast<uint32_t>(Properties[Next + 1]);
2711+
USMDesc.pNext = &UsmLocationDesc;
2712+
} else {
2713+
return PI_ERROR_INVALID_VALUE;
2714+
}
2715+
Next += 2;
2716+
}
2717+
}
27002718

2701-
std::ignore = Properties;
27022719
ur_context_handle_t UrContext =
27032720
reinterpret_cast<ur_context_handle_t>(Context);
2704-
ur_usm_desc_t USMDesc{};
2705-
USMDesc.align = Alignment;
2721+
27062722
ur_usm_pool_handle_t Pool{};
27072723
HANDLE_ERRORS(urUSMHostAlloc(UrContext, &USMDesc, Pool, Size, ResultPtr));
27082724
return PI_SUCCESS;
@@ -3131,14 +3147,29 @@ inline pi_result piextUSMDeviceAlloc(void **ResultPtr, pi_context Context,
31313147
pi_device Device,
31323148
pi_usm_mem_properties *Properties,
31333149
size_t Size, pi_uint32 Alignment) {
3134-
3135-
std::ignore = Properties;
31363150
ur_context_handle_t UrContext =
31373151
reinterpret_cast<ur_context_handle_t>(Context);
31383152
auto UrDevice = reinterpret_cast<ur_device_handle_t>(Device);
31393153

31403154
ur_usm_desc_t USMDesc{};
31413155
USMDesc.align = Alignment;
3156+
3157+
ur_usm_alloc_location_desc_t UsmLocDesc{};
3158+
UsmLocDesc.stype = UR_STRUCTURE_TYPE_USM_ALLOC_LOCATION_DESC;
3159+
3160+
if (Properties) {
3161+
uint32_t Next = 0;
3162+
while (Properties[Next]) {
3163+
if (Properties[Next] == PI_MEM_USM_ALLOC_BUFFER_LOCATION) {
3164+
UsmLocDesc.location = static_cast<uint32_t>(Properties[Next + 1]);
3165+
USMDesc.pNext = &UsmLocDesc;
3166+
} else {
3167+
return PI_ERROR_INVALID_VALUE;
3168+
}
3169+
Next += 2;
3170+
}
3171+
}
3172+
31423173
ur_usm_pool_handle_t Pool{};
31433174
HANDLE_ERRORS(
31443175
urUSMDeviceAlloc(UrContext, UrDevice, &USMDesc, Pool, Size, ResultPtr));
@@ -3171,42 +3202,58 @@ inline pi_result piextUSMSharedAlloc(void **ResultPtr, pi_context Context,
31713202
pi_device Device,
31723203
pi_usm_mem_properties *Properties,
31733204
size_t Size, pi_uint32 Alignment) {
3174-
3175-
std::ignore = Properties;
3176-
if (Properties && *Properties != 0) {
3177-
PI_ASSERT(*(Properties) == PI_MEM_ALLOC_FLAGS && *(Properties + 2) == 0,
3178-
PI_ERROR_INVALID_VALUE);
3179-
}
3180-
31813205
ur_context_handle_t UrContext =
31823206
reinterpret_cast<ur_context_handle_t>(Context);
31833207
auto UrDevice = reinterpret_cast<ur_device_handle_t>(Device);
31843208

31853209
ur_usm_desc_t USMDesc{};
3210+
USMDesc.align = Alignment;
31863211
ur_usm_device_desc_t UsmDeviceDesc{};
31873212
UsmDeviceDesc.stype = UR_STRUCTURE_TYPE_USM_DEVICE_DESC;
31883213
ur_usm_host_desc_t UsmHostDesc{};
31893214
UsmHostDesc.stype = UR_STRUCTURE_TYPE_USM_HOST_DESC;
3215+
ur_usm_alloc_location_desc_t UsmLocationDesc{};
3216+
UsmLocationDesc.stype = UR_STRUCTURE_TYPE_USM_ALLOC_LOCATION_DESC;
3217+
3218+
// One properties bitfield can correspond to a host_desc and a device_desc
3219+
// struct, since having `0` values in these is harmless we can set up this
3220+
// pNext chain in advance.
3221+
USMDesc.pNext = &UsmDeviceDesc;
3222+
UsmDeviceDesc.pNext = &UsmHostDesc;
3223+
31903224
if (Properties) {
3191-
if (Properties[0] == PI_MEM_ALLOC_FLAGS) {
3192-
if (Properties[1] == PI_MEM_ALLOC_WRTITE_COMBINED) {
3193-
UsmDeviceDesc.flags |= UR_USM_DEVICE_MEM_FLAG_WRITE_COMBINED;
3194-
}
3195-
if (Properties[1] == PI_MEM_ALLOC_INITIAL_PLACEMENT_DEVICE) {
3196-
UsmDeviceDesc.flags |= UR_USM_DEVICE_MEM_FLAG_INITIAL_PLACEMENT;
3225+
uint32_t Next = 0;
3226+
while (Properties[Next]) {
3227+
switch (Properties[Next]) {
3228+
case PI_MEM_ALLOC_FLAGS: {
3229+
if (Properties[Next + 1] & PI_MEM_ALLOC_WRTITE_COMBINED) {
3230+
UsmDeviceDesc.flags |= UR_USM_DEVICE_MEM_FLAG_WRITE_COMBINED;
3231+
}
3232+
if (Properties[Next + 1] & PI_MEM_ALLOC_INITIAL_PLACEMENT_DEVICE) {
3233+
UsmDeviceDesc.flags |= UR_USM_DEVICE_MEM_FLAG_INITIAL_PLACEMENT;
3234+
}
3235+
if (Properties[Next + 1] & PI_MEM_ALLOC_INITIAL_PLACEMENT_HOST) {
3236+
UsmHostDesc.flags |= UR_USM_HOST_MEM_FLAG_INITIAL_PLACEMENT;
3237+
}
3238+
if (Properties[Next + 1] & PI_MEM_ALLOC_DEVICE_READ_ONLY) {
3239+
UsmDeviceDesc.flags |= UR_USM_DEVICE_MEM_FLAG_DEVICE_READ_ONLY;
3240+
}
3241+
break;
31973242
}
3198-
if (Properties[1] == PI_MEM_ALLOC_INITIAL_PLACEMENT_HOST) {
3199-
UsmHostDesc.flags |= UR_USM_HOST_MEM_FLAG_INITIAL_PLACEMENT;
3243+
case PI_MEM_USM_ALLOC_BUFFER_LOCATION: {
3244+
UsmLocationDesc.location = static_cast<uint32_t>(Properties[Next + 1]);
3245+
// We wait until we've seen a BUFFER_LOCATION property to tack this
3246+
// onto the end of the chain, a `0` here might be valid as far as we
3247+
// know so we must exclude it unless we've been given a value.
3248+
UsmHostDesc.pNext = &UsmLocationDesc;
3249+
break;
32003250
}
3201-
if (Properties[1] == PI_MEM_ALLOC_DEVICE_READ_ONLY) {
3202-
UsmDeviceDesc.flags |= UR_USM_DEVICE_MEM_FLAG_DEVICE_READ_ONLY;
3251+
default:
3252+
return PI_ERROR_INVALID_VALUE;
32033253
}
3254+
Next += 2;
32043255
}
32053256
}
3206-
UsmDeviceDesc.pNext = &UsmHostDesc;
3207-
USMDesc.pNext = &UsmDeviceDesc;
3208-
3209-
USMDesc.align = Alignment;
32103257

32113258
ur_usm_pool_handle_t Pool{};
32123259
HANDLE_ERRORS(

0 commit comments

Comments
 (0)