Skip to content

Commit 8984c1c

Browse files
committed
Make USM pools optional with a device query to report support.
1 parent e3d127d commit 8984c1c

26 files changed

+162
-173
lines changed

include/ur_api.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,9 @@ typedef enum ur_device_info_t {
16391639
UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT = 118, ///< [::ur_bool_t] return true if the device supports the
16401640
///< `EnqueueDeviceGlobalVariableWrite` and
16411641
///< `EnqueueDeviceGlobalVariableRead` entry points.
1642+
UR_DEVICE_INFO_USM_POOL_SUPPORT = 119, ///< [::ur_bool_t] return true if the device supports USM pooling. Pertains
1643+
///< to the `USMPool` entry points and usage of the `pool` parameter of the
1644+
///< USM alloc entry points.
16421645
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000, ///< [::ur_bool_t] Returns true if the device supports the use of
16431646
///< command-buffers.
16441647
UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP = 0x1001, ///< [::ur_device_command_buffer_update_capability_flags_t] Command-buffer
@@ -3536,6 +3539,8 @@ typedef struct ur_usm_pool_limits_desc_t {
35363539
/// + `size` is greater than ::UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE.
35373540
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
35383541
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3542+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3543+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
35393544
UR_APIEXPORT ur_result_t UR_APICALL
35403545
urUSMHostAlloc(
35413546
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3583,6 +3588,8 @@ urUSMHostAlloc(
35833588
/// + `size` is greater than ::UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE.
35843589
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
35853590
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3591+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3592+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
35863593
UR_APIEXPORT ur_result_t UR_APICALL
35873594
urUSMDeviceAlloc(
35883595
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3632,6 +3639,8 @@ urUSMDeviceAlloc(
36323639
/// + If `UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT` and `UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT` are both false.
36333640
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
36343641
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3642+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3643+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
36353644
UR_APIEXPORT ur_result_t UR_APICALL
36363645
urUSMSharedAlloc(
36373646
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3713,6 +3722,8 @@ urUSMGetMemAllocInfo(
37133722
/// + `::UR_USM_POOL_FLAGS_MASK & pPoolDesc->flags`
37143723
/// - ::UR_RESULT_ERROR_INVALID_VALUE
37153724
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
3725+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3726+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
37163727
UR_APIEXPORT ur_result_t UR_APICALL
37173728
urUSMPoolCreate(
37183729
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3731,6 +3742,7 @@ urUSMPoolCreate(
37313742
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
37323743
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
37333744
/// + `NULL == pPool`
3745+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
37343746
UR_APIEXPORT ur_result_t UR_APICALL
37353747
urUSMPoolRetain(
37363748
ur_usm_pool_handle_t pPool ///< [in][retain] pointer to USM memory pool
@@ -3753,6 +3765,7 @@ urUSMPoolRetain(
37533765
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
37543766
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
37553767
/// + `NULL == pPool`
3768+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
37563769
UR_APIEXPORT ur_result_t UR_APICALL
37573770
urUSMPoolRelease(
37583771
ur_usm_pool_handle_t pPool ///< [in][release] pointer to USM memory pool
@@ -3794,6 +3807,7 @@ typedef enum ur_usm_pool_info_t {
37943807
/// + `pPropValue == NULL && pPropSizeRet == NULL`
37953808
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
37963809
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3810+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
37973811
UR_APIEXPORT ur_result_t UR_APICALL
37983812
urUSMPoolGetInfo(
37993813
ur_usm_pool_handle_t hPool, ///< [in] handle of the USM memory pool

include/ur_print.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) {
25502550
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
25512551
os << "UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT";
25522552
break;
2553+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
2554+
os << "UR_DEVICE_INFO_USM_POOL_SUPPORT";
2555+
break;
25532556
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
25542557
os << "UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP";
25552558
break;
@@ -4052,6 +4055,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info
40524055

40534056
os << ")";
40544057
} break;
4058+
case UR_DEVICE_INFO_USM_POOL_SUPPORT: {
4059+
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
4060+
if (sizeof(ur_bool_t) > size) {
4061+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_bool_t) << ")";
4062+
return UR_RESULT_ERROR_INVALID_SIZE;
4063+
}
4064+
os << (const void *)(tptr) << " (";
4065+
4066+
os << *tptr;
4067+
4068+
os << ")";
4069+
} break;
40554070
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: {
40564071
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
40574072
if (sizeof(ur_bool_t) > size) {

scripts/core/device.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ etors:
441441
desc: "[$x_device_handle_t] The composite device containing this component device."
442442
- name: GLOBAL_VARIABLE_SUPPORT
443443
desc: "[$x_bool_t] return true if the device supports the `EnqueueDeviceGlobalVariableWrite` and `EnqueueDeviceGlobalVariableRead` entry points."
444+
- name: USM_POOL_SUPPORT
445+
desc: "[$x_bool_t] return true if the device supports USM pooling. Pertains to the `USMPool` entry points and usage of the `pool` parameter of the USM alloc entry points."
444446
--- #--------------------------------------------------------------------------
445447
type: function
446448
desc: "Retrieves various information about device"

scripts/core/usm.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ returns:
264264
- "`size` is greater than $X_DEVICE_INFO_MAX_MEM_ALLOC_SIZE."
265265
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
266266
- $X_RESULT_ERROR_OUT_OF_RESOURCES
267+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
268+
- "If any device associated with `hContext` reports `false` for $X_DEVICE_INFO_USM_POOL_SUPPORT"
267269
--- #--------------------------------------------------------------------------
268270
type: function
269271
desc: "USM allocate device memory"
@@ -309,6 +311,8 @@ returns:
309311
- "`size` is greater than $X_DEVICE_INFO_MAX_MEM_ALLOC_SIZE."
310312
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
311313
- $X_RESULT_ERROR_OUT_OF_RESOURCES
314+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
315+
- "If any device associated with `hContext` reports `false` for $X_DEVICE_INFO_USM_POOL_SUPPORT"
312316
--- #--------------------------------------------------------------------------
313317
type: function
314318
desc: "USM allocate shared memory"
@@ -355,6 +359,8 @@ returns:
355359
- "If `UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT` and `UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT` are both false."
356360
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
357361
- $X_RESULT_ERROR_OUT_OF_RESOURCES
362+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
363+
- "If any device associated with `hContext` reports `false` for $X_DEVICE_INFO_USM_POOL_SUPPORT"
358364
--- #--------------------------------------------------------------------------
359365
type: function
360366
desc: "Free the USM memory object"
@@ -424,6 +430,8 @@ returns:
424430
- $X_RESULT_ERROR_INVALID_NULL_HANDLE
425431
- $X_RESULT_ERROR_INVALID_VALUE
426432
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
433+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE:
434+
- "If any device associated with `hContext` reports `false` for $X_DEVICE_INFO_USM_POOL_SUPPORT"
427435
--- #--------------------------------------------------------------------------
428436
type: function
429437
desc: "Get a reference to the pool handle. Increment its reference count"
@@ -436,6 +444,7 @@ params:
436444
desc: "[in][retain] pointer to USM memory pool"
437445
returns:
438446
- $X_RESULT_ERROR_INVALID_NULL_HANDLE
447+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE
439448
--- #--------------------------------------------------------------------------
440449
type: function
441450
desc: "Decrement the pool's reference count and delete the pool if the reference count becomes zero."
@@ -452,6 +461,7 @@ params:
452461
desc: "[in][release] pointer to USM memory pool"
453462
returns:
454463
- $X_RESULT_ERROR_INVALID_NULL_HANDLE
464+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE
455465
--- #--------------------------------------------------------------------------
456466
type: enum
457467
desc: "Get USM memory pool information"
@@ -499,3 +509,4 @@ returns:
499509
- "`pPropValue == NULL && pPropSizeRet == NULL`"
500510
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
501511
- $X_RESULT_ERROR_OUT_OF_RESOURCES
512+
- $X_RESULT_ERROR_UNSUPPORTED_FEATURE

source/adapters/cuda/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10761076
return ReturnValue(static_cast<ur_bool_t>(false));
10771077
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
10781078
return ReturnValue(static_cast<ur_bool_t>(true));
1079+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
1080+
return ReturnValue(static_cast<ur_bool_t>(true));
10791081
case UR_DEVICE_INFO_COMPONENT_DEVICES:
10801082
case UR_DEVICE_INFO_COMPOSITE_DEVICE:
10811083
case UR_DEVICE_INFO_MAX_READ_WRITE_IMAGE_ARGS:

source/adapters/hip/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
889889

890890
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
891891
return ReturnValue(ur_bool_t{false});
892+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
893+
return ReturnValue(ur_bool_t{true});
892894
// TODO: Investigate if this information is available on HIP.
893895
case UR_DEVICE_INFO_COMPONENT_DEVICES:
894896
case UR_DEVICE_INFO_COMPOSITE_DEVICE:

source/adapters/level_zero/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,8 @@ ur_result_t urDeviceGetInfo(
11551155
return ReturnValue(false);
11561156
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
11571157
return ReturnValue(true);
1158+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
1159+
return ReturnValue(true);
11581160
default:
11591161
logger::error("Unsupported ParamName in urGetDeviceInfo");
11601162
logger::error("ParamNameParamName={}(0x{})", ParamName,

source/adapters/native_cpu/device.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
414414
case UR_DEVICE_INFO_ENQUEUE_NATIVE_COMMAND_SUPPORT_EXP:
415415
return ReturnValue(false);
416416

417+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
418+
return ReturnValue(false);
419+
417420
default:
418421
DIE_NO_IMPLEMENTATION;
419422
}

source/adapters/opencl/device.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10481048
case UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS: {
10491049
return ReturnValue(false);
10501050
}
1051+
1052+
case UR_DEVICE_INFO_USM_POOL_SUPPORT: {
1053+
return ReturnValue(false);
1054+
}
1055+
10511056
/* TODO: Check regularly to see if support is enabled in OpenCL. Intel GPU
10521057
* EU device-specific information extensions. Some of the queries are
10531058
* enabled by cl_intel_device_attribute_query extension, but it's not yet in

source/adapters/opencl/ur_interface_loader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ urGetUSMProcAddrTable(ur_api_version_t Version, ur_usm_dditable_t *pDdiTable) {
238238
pDdiTable->pfnFree = urUSMFree;
239239
pDdiTable->pfnGetMemAllocInfo = urUSMGetMemAllocInfo;
240240
pDdiTable->pfnHostAlloc = urUSMHostAlloc;
241-
pDdiTable->pfnPoolCreate = nullptr;
242-
pDdiTable->pfnPoolRetain = nullptr;
243-
pDdiTable->pfnPoolRelease = nullptr;
244-
pDdiTable->pfnPoolGetInfo = nullptr;
241+
pDdiTable->pfnPoolCreate = urUSMPoolCreate;
242+
pDdiTable->pfnPoolRetain = urUSMPoolRetain;
243+
pDdiTable->pfnPoolRelease = urUSMPoolRelease;
244+
pDdiTable->pfnPoolGetInfo = urUSMPoolGetInfo;
245245
pDdiTable->pfnSharedAlloc = urUSMSharedAlloc;
246246
return UR_RESULT_SUCCESS;
247247
}

0 commit comments

Comments
 (0)