Skip to content

Commit f2e6794

Browse files
committed
Make USM pools optional with a device query to report support.
1 parent 7f1332e commit f2e6794

File tree

26 files changed

+162
-172
lines changed

26 files changed

+162
-172
lines changed

include/ur_api.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,6 +1636,9 @@ typedef enum ur_device_info_t {
16361636
UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT = 118, ///< [::ur_bool_t] return true if the device supports the
16371637
///< `EnqueueDeviceGlobalVariableWrite` and
16381638
///< `EnqueueDeviceGlobalVariableRead` entry points.
1639+
UR_DEVICE_INFO_USM_POOL_SUPPORT = 119, ///< [::ur_bool_t] return true if the device supports USM pooling. Pertains
1640+
///< to the `USMPool` entry points and usage of the `pool` parameter of the
1641+
///< USM alloc entry points.
16391642
UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP = 0x1000, ///< [::ur_bool_t] Returns true if the device supports the use of
16401643
///< command-buffers.
16411644
UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_CAPABILITIES_EXP = 0x1001, ///< [::ur_device_command_buffer_update_capability_flags_t] Command-buffer
@@ -3533,6 +3536,8 @@ typedef struct ur_usm_pool_limits_desc_t {
35333536
/// + `size` is greater than ::UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE.
35343537
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
35353538
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3539+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3540+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
35363541
UR_APIEXPORT ur_result_t UR_APICALL
35373542
urUSMHostAlloc(
35383543
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3580,6 +3585,8 @@ urUSMHostAlloc(
35803585
/// + `size` is greater than ::UR_DEVICE_INFO_MAX_MEM_ALLOC_SIZE.
35813586
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
35823587
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3588+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3589+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
35833590
UR_APIEXPORT ur_result_t UR_APICALL
35843591
urUSMDeviceAlloc(
35853592
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3629,6 +3636,8 @@ urUSMDeviceAlloc(
36293636
/// + If `UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT` and `UR_DEVICE_INFO_USM_CROSS_SHARED_SUPPORT` are both false.
36303637
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
36313638
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3639+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3640+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
36323641
UR_APIEXPORT ur_result_t UR_APICALL
36333642
urUSMSharedAlloc(
36343643
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3710,6 +3719,8 @@ urUSMGetMemAllocInfo(
37103719
/// + `::UR_USM_POOL_FLAGS_MASK & pPoolDesc->flags`
37113720
/// - ::UR_RESULT_ERROR_INVALID_VALUE
37123721
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
3722+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
3723+
/// + If any device associated with `hContext` reports `false` for ::UR_DEVICE_INFO_USM_POOL_SUPPORT
37133724
UR_APIEXPORT ur_result_t UR_APICALL
37143725
urUSMPoolCreate(
37153726
ur_context_handle_t hContext, ///< [in] handle of the context object
@@ -3728,6 +3739,7 @@ urUSMPoolCreate(
37283739
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
37293740
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
37303741
/// + `NULL == pPool`
3742+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
37313743
UR_APIEXPORT ur_result_t UR_APICALL
37323744
urUSMPoolRetain(
37333745
ur_usm_pool_handle_t pPool ///< [in][retain] pointer to USM memory pool
@@ -3750,6 +3762,7 @@ urUSMPoolRetain(
37503762
/// - ::UR_RESULT_ERROR_ADAPTER_SPECIFIC
37513763
/// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE
37523764
/// + `NULL == pPool`
3765+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
37533766
UR_APIEXPORT ur_result_t UR_APICALL
37543767
urUSMPoolRelease(
37553768
ur_usm_pool_handle_t pPool ///< [in][release] pointer to USM memory pool
@@ -3791,6 +3804,7 @@ typedef enum ur_usm_pool_info_t {
37913804
/// + `pPropValue == NULL && pPropSizeRet == NULL`
37923805
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
37933806
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
3807+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_FEATURE
37943808
UR_APIEXPORT ur_result_t UR_APICALL
37953809
urUSMPoolGetInfo(
37963810
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
@@ -2541,6 +2541,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_device_info_t value) {
25412541
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
25422542
os << "UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT";
25432543
break;
2544+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
2545+
os << "UR_DEVICE_INFO_USM_POOL_SUPPORT";
2546+
break;
25442547
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
25452548
os << "UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP";
25462549
break;
@@ -4040,6 +4043,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_device_info
40404043

40414044
os << ")";
40424045
} break;
4046+
case UR_DEVICE_INFO_USM_POOL_SUPPORT: {
4047+
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
4048+
if (sizeof(ur_bool_t) > size) {
4049+
os << "invalid size (is: " << size << ", expected: >=" << sizeof(ur_bool_t) << ")";
4050+
return UR_RESULT_ERROR_INVALID_SIZE;
4051+
}
4052+
os << (const void *)(tptr) << " (";
4053+
4054+
os << *tptr;
4055+
4056+
os << ")";
4057+
} break;
40434058
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: {
40444059
const ur_bool_t *tptr = (const ur_bool_t *)ptr;
40454060
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
@@ -1145,6 +1145,8 @@ ur_result_t urDeviceGetInfo(
11451145
return ReturnValue(false);
11461146
case UR_DEVICE_INFO_GLOBAL_VARIABLE_SUPPORT:
11471147
return ReturnValue(true);
1148+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
1149+
return ReturnValue(true);
11481150
default:
11491151
logger::error("Unsupported ParamName in urGetDeviceInfo");
11501152
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
@@ -411,6 +411,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
411411
case UR_DEVICE_INFO_ENQUEUE_NATIVE_COMMAND_SUPPORT_EXP:
412412
return ReturnValue(false);
413413

414+
case UR_DEVICE_INFO_USM_POOL_SUPPORT:
415+
return ReturnValue(false);
416+
414417
default:
415418
DIE_NO_IMPLEMENTATION;
416419
}

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)