Skip to content

Commit 7430e14

Browse files
committed
Add resident device change call
1 parent f502e96 commit 7430e14

14 files changed

+360
-31
lines changed

include/umf/memory_pool_ops.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ typedef struct umf_memory_pool_ops_t {
191191
/// failure.
192192
///
193193
umf_result_t (*ext_trim_memory)(void *pool, size_t minBytesToKeep);
194+
195+
///
196+
/// @brief Adds or removes devices on which allocations should be made
197+
/// resident.
198+
/// @param pool pointer to the memory pool
199+
/// @param peerIdx identifier of device
200+
/// @param isAdding boolean indicating if peer is to be removed or added
201+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on
202+
/// failure.
203+
///
204+
umf_result_t (*ext_resident_device_change)(void *pool, uint32_t peerIdx,
205+
_Bool isAdding);
194206
} umf_memory_pool_ops_t;
195207

196208
#ifdef __cplusplus

include/umf/memory_provider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,17 @@ umf_result_t
265265
umfMemoryProviderAllocationMerge(umf_memory_provider_handle_t hProvider,
266266
void *lowPtr, void *highPtr, size_t totalSize);
267267

268+
/// @brief Adds or removes devices on which allocations should be made
269+
/// resident.
270+
/// @param hProvider handle to the memory provider
271+
/// @param deviceIndex identifier of device
272+
/// @param isAdding boolean indicating if peer is to be removed or added
273+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on
274+
/// failure.
275+
umf_result_t
276+
umfMemoryProviderResidentDeviceChange(umf_memory_provider_handle_t hProvider,
277+
uint32_t deviceIndex, bool isAdding);
278+
268279
#ifdef __cplusplus
269280
}
270281
#endif

include/umf/memory_provider_ops.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define UMF_MEMORY_PROVIDER_OPS_H 1
1212

1313
#include <stdarg.h>
14+
#include <stdbool.h>
1415

1516
#include <umf/base.h>
1617

@@ -322,6 +323,17 @@ typedef struct umf_memory_provider_ops_t {
322323
void *provider, umf_memory_property_id_t memory_property_id,
323324
size_t *size);
324325

326+
/// @brief Adds or removes devices on which allocations should be made
327+
/// resident.
328+
/// @param provider handle to the memory provider
329+
/// @param device_index identifier of device
330+
/// @param is_adding boolean indicating if peer is to be removed or added
331+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on
332+
/// failure.
333+
umf_result_t (*ext_resident_device_change)(void *provider,
334+
uint32_t device_index,
335+
bool is_adding);
336+
325337
} umf_memory_provider_ops_t;
326338

327339
#ifdef __cplusplus

include/umf/providers/provider_level_zero.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetMemoryType(
6666
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
6767
umf_result_t umfLevelZeroMemoryProviderParamsSetResidentDevices(
6868
umf_level_zero_memory_provider_params_handle_t hParams,
69-
ze_device_handle_t *hDevices, uint32_t deviceCount);
69+
ze_device_handle_t *hDevices, uint32_t deviceCount,
70+
uint32_t *residentDevicesIndices, uint32_t residentDevicesCount);
7071

7172
typedef enum umf_level_zero_memory_provider_free_policy_t {
7273
UMF_LEVEL_ZERO_MEMORY_PROVIDER_FREE_POLICY_DEFAULT =

src/critnib/critnib.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ int critnib_find(struct critnib *c, uintptr_t key, enum find_dir_t dir,
10941094
*
10951095
* If func() returns non-zero, the search is aborted.
10961096
*/
1097-
static int iter(struct critnib_node *__restrict n, word min, word max,
1097+
static int iter(struct critnib_node *__restrict n, const word min,
1098+
const word max,
10981099
int (*func)(word key, void *value, void *privdata),
10991100
void *privdata) {
11001101
if (is_leaf(n)) {
@@ -1129,9 +1130,21 @@ static int iter(struct critnib_node *__restrict n, word min, word max,
11291130
void critnib_iter(critnib *c, uintptr_t min, uintptr_t max,
11301131
int (*func)(uintptr_t key, void *value, void *privdata),
11311132
void *privdata) {
1133+
bool wasIterating = false;
11321134
utils_mutex_lock(&c->mutex);
11331135
if (c->root) {
11341136
iter(c->root, min, max, func, privdata);
1137+
wasIterating = true;
11351138
}
11361139
utils_mutex_unlock(&c->mutex);
1140+
if (!wasIterating) {
1141+
LOG_DEBUG("there was no root, iterating critnib:%p was skipped",
1142+
(void *)c);
1143+
}
1144+
}
1145+
1146+
void critnib_iter_all(critnib *c,
1147+
int (*func)(uintptr_t key, void *value, void *privdata),
1148+
void *privdata) {
1149+
critnib_iter(c, 0, (uintptr_t)-1, func, privdata);
11371150
}

src/critnib/critnib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ int critnib_insert(critnib *c, uintptr_t key, void *value, int update);
3535
void critnib_iter(critnib *c, uintptr_t min, uintptr_t max,
3636
int (*func)(uintptr_t key, void *value, void *privdata),
3737
void *privdata);
38+
void critnib_iter_all(critnib *c,
39+
int (*func)(uintptr_t key, void *value, void *privdata),
40+
void *privdata);
41+
3842
int critnib_remove_release(critnib *c, uintptr_t key);
3943

4044
/*

src/libumf.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ EXPORTS
6060
umfMemoryProviderPurgeForce
6161
umfMemoryProviderPurgeLazy
6262
umfMemoryProviderPutIPCHandle
63+
umfMemoryProviderResidentDeviceChange
6364
umfMempolicyCreate
6465
umfMempolicyDestroy
6566
umfMempolicySetCustomSplitPartitions

src/libumf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ UMF_1.0 {
5454
umfMemoryProviderPurgeForce;
5555
umfMemoryProviderPurgeLazy;
5656
umfMemoryProviderPutIPCHandle;
57+
umfMemoryProviderResidentDeviceChange;
5758
umfMempolicyCreate;
5859
umfMempolicyDestroy;
5960
umfMempolicySetCustomSplitPartitions;

src/memory_provider.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,13 @@ umf_result_t umfMemoryProviderGetAllocationPropertiesSize(
606606
checkErrorAndSetLastProvider(res, hProvider);
607607
return res;
608608
}
609+
610+
umf_result_t
611+
umfMemoryProviderResidentDeviceChange(umf_memory_provider_handle_t hProvider,
612+
uint32_t deviceIndex, bool isAdding) {
613+
UMF_CHECK((hProvider != NULL), UMF_RESULT_ERROR_INVALID_ARGUMENT);
614+
umf_result_t res = hProvider->ops.ext_resident_device_change(
615+
hProvider->provider_priv, deviceIndex, isAdding);
616+
checkErrorAndSetLastProvider(res, hProvider);
617+
return res;
618+
}

src/provider/provider_cuda.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,15 @@ static umf_result_t cu_memory_provider_get_allocation_properties_size(
802802
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
803803
}
804804

805+
static umf_result_t
806+
cu_memory_provider_resident_device_change(void *provider, uint32_t device_index,
807+
bool is_adding) {
808+
(void)provider;
809+
(void)device_index;
810+
(void)is_adding;
811+
return UMF_RESULT_SUCCESS;
812+
}
813+
805814
static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
806815
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
807816
.initialize = cu_memory_provider_initialize,
@@ -829,6 +838,7 @@ static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
829838
cu_memory_provider_get_allocation_properties,
830839
.ext_get_allocation_properties_size =
831840
cu_memory_provider_get_allocation_properties_size,
841+
.ext_resident_device_change = cu_memory_provider_resident_device_change,
832842
};
833843

834844
const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void) {

0 commit comments

Comments
 (0)