Skip to content

Commit 61a5853

Browse files
committed
Add support for making memory resident on given devices in L0 provider
1 parent fcf1f5a commit 61a5853

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

include/umf/providers/provider_level_zero.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
extern "C" {
1515
#endif
1616

17+
typedef struct _ze_context_handle_t *ze_context_handle_t;
18+
typedef struct _ze_device_handle_t *ze_device_handle_t;
19+
1720
/// @brief USM memory allocation type
1821
typedef enum umf_usm_memory_type_t {
1922
UMF_MEMORY_TYPE_UNKNOWN = 0, ///< The memory pointed to is of unknown type
@@ -24,9 +27,17 @@ typedef enum umf_usm_memory_type_t {
2427

2528
/// @brief Level Zero Memory Provider settings struct
2629
typedef struct level_zero_memory_provider_params_t {
27-
void *level_zero_context_handle; ///< Handle to the Level Zero context
28-
void *level_zero_device_handle; ///< Handle to the Level Zero device
30+
ze_context_handle_t
31+
level_zero_context_handle; ///< Handle to the Level Zero context
32+
ze_device_handle_t
33+
level_zero_device_handle; ///< Handle to the Level Zero device
34+
2935
umf_usm_memory_type_t memory_type; ///< Allocation memory type
36+
37+
ze_device_handle_t *
38+
resident_device_handles; ///< Array of devices for which the memory should be made resident
39+
uint32_t
40+
resident_device_count; ///< Number of devices for which the memory should be made resident
3041
} level_zero_memory_provider_params_t;
3142

3243
umf_memory_provider_ops_t *umfLevelZeroMemoryProviderOps(void);

src/provider/provider_level_zero.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ typedef struct ze_memory_provider_t {
2727
ze_context_handle_t context;
2828
ze_device_handle_t device;
2929
ze_memory_type_t memory_type;
30+
31+
ze_device_handle_t *resident_device_handles;
32+
uint32_t resident_device_count;
3033
} ze_memory_provider_t;
3134

3235
typedef struct ze_ops_t {
@@ -48,6 +51,9 @@ typedef struct ze_ops_t {
4851
ze_ipc_mem_handle_t,
4952
ze_ipc_memory_flags_t, void **);
5053
ze_result_t (*zeMemCloseIpcHandle)(ze_context_handle_t, void *);
54+
ze_result_t (*zeContextMakeMemoryResident)(ze_context_handle_t,
55+
ze_device_handle_t, void *,
56+
size_t);
5157
} ze_ops_t;
5258

5359
static ze_ops_t g_ze_ops;
@@ -78,11 +84,14 @@ static void init_ze_global_state(void) {
7884
util_get_symbol_addr(0, "zeMemOpenIpcHandle", lib_name);
7985
*(void **)&g_ze_ops.zeMemCloseIpcHandle =
8086
util_get_symbol_addr(0, "zeMemCloseIpcHandle", lib_name);
87+
*(void **)&g_ze_ops.zeContextMakeMemoryResident =
88+
util_get_symbol_addr(0, "zeContextMakeMemoryResident", lib_name);
8189

8290
if (!g_ze_ops.zeMemAllocHost || !g_ze_ops.zeMemAllocDevice ||
8391
!g_ze_ops.zeMemAllocShared || !g_ze_ops.zeMemFree ||
8492
!g_ze_ops.zeMemGetIpcHandle || !g_ze_ops.zeMemOpenIpcHandle ||
85-
!g_ze_ops.zeMemCloseIpcHandle) {
93+
!g_ze_ops.zeMemCloseIpcHandle ||
94+
!g_ze_ops.zeContextMakeMemoryResident) {
8695
// g_ze_ops.zeMemPutIpcHandle can be NULL because it was introduced
8796
// starting from Level Zero 1.6
8897
LOG_ERR("Required Level Zero symbols not found.");
@@ -181,6 +190,15 @@ static umf_result_t ze_memory_provider_alloc(void *provider, size_t size,
181190
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
182191
}
183192

193+
for (uint32_t i = 0; i < ze_provider->resident_device_count; i++) {
194+
ze_result = g_ze_ops.zeContextMakeMemoryResident(
195+
ze_provider->context, ze_provider->resident_device_handles[i],
196+
*resultPtr, size);
197+
if (ze_result != ZE_RESULT_SUCCESS) {
198+
break;
199+
}
200+
}
201+
184202
// TODO add error reporting
185203
return (ze_result == ZE_RESULT_SUCCESS)
186204
? UMF_RESULT_SUCCESS

0 commit comments

Comments
 (0)