Skip to content

Commit 9d7e12c

Browse files
committed
applied second round of Rafal's comments
1 parent a8baf31 commit 9d7e12c

File tree

4 files changed

+54
-31
lines changed

4 files changed

+54
-31
lines changed

src/memory_provider.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ static umf_result_t umfDefaultGetAllocationPropertiesSize(
154154
return UMF_RESULT_ERROR_NOT_SUPPORTED;
155155
}
156156

157+
static umf_result_t umfDefaultResidentDeviceChange(void *provider,
158+
uint32_t device_index,
159+
bool is_adding) {
160+
(void)provider;
161+
(void)device_index;
162+
(void)is_adding;
163+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
164+
}
165+
157166
void assignOpsExtDefaults(umf_memory_provider_ops_t *ops) {
158167
if (!ops->ext_purge_lazy) {
159168
ops->ext_purge_lazy = umfDefaultPurgeLazy;
@@ -183,6 +192,10 @@ void assignOpsExtDefaults(umf_memory_provider_ops_t *ops) {
183192
ops->ext_get_allocation_properties_size =
184193
umfDefaultGetAllocationPropertiesSize;
185194
}
195+
196+
if (!ops->ext_resident_device_change) {
197+
ops->ext_resident_device_change = umfDefaultResidentDeviceChange;
198+
}
186199
}
187200

188201
void assignOpsIpcDefaults(umf_memory_provider_ops_t *ops) {

src/provider/provider_cuda.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,6 @@ 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-
814805
static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
815806
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
816807
.initialize = cu_memory_provider_initialize,
@@ -838,7 +829,7 @@ static umf_memory_provider_ops_t UMF_CUDA_MEMORY_PROVIDER_OPS = {
838829
cu_memory_provider_get_allocation_properties,
839830
.ext_get_allocation_properties_size =
840831
cu_memory_provider_get_allocation_properties_size,
841-
.ext_resident_device_change = cu_memory_provider_resident_device_change,
832+
.ext_resident_device_change = NULL,
842833
};
843834

844835
const umf_memory_provider_ops_t *umfCUDAMemoryProviderOps(void) {

src/provider/provider_level_zero.c

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,37 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetResidentDevices(
361361
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
362362
}
363363

364-
if (residentDevicesCount && !residentDevicesIndices) {
364+
if (residentDevicesCount > 0 && residentDevicesIndices == NULL) {
365365
LOG_ERR("Resident devices indices array is NULL, but "
366366
"residentDevicesCount is not zero");
367367
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
368368
}
369369

370+
if (deviceCount > 0 && hDevices == NULL) {
371+
LOG_ERR("All devices array is NULL, but deviceCount is not zero");
372+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
373+
}
374+
375+
for (uint32_t first_idx = 0; first_idx < residentDevicesCount;
376+
first_idx++) {
377+
if (residentDevicesIndices[first_idx] >= deviceCount) {
378+
LOG_ERR("Resident device index:%u is out of range, should be less "
379+
"than deviceCount:%u",
380+
residentDevicesIndices[first_idx], deviceCount);
381+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
382+
}
383+
for (uint32_t second_idx = 0; second_idx < first_idx; second_idx++) {
384+
if (residentDevicesIndices[first_idx] ==
385+
residentDevicesIndices[second_idx]) {
386+
LOG_ERR("resident device indices are not unique, idx:%u and "
387+
"idx:%u both point to indice:%u",
388+
first_idx, second_idx,
389+
residentDevicesIndices[first_idx]);
390+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
391+
}
392+
}
393+
}
394+
370395
hParams->device_handles = hDevices;
371396
hParams->device_count = deviceCount;
372397
hParams->resident_device_indices = residentDevicesIndices;
@@ -989,7 +1014,7 @@ static umf_result_t ze_memory_provider_get_allocation_properties_size(
9891014
}
9901015

9911016
struct ze_memory_provider_resident_device_change_data {
992-
bool isAdding;
1017+
bool is_adding;
9931018
uint32_t peer_device_index;
9941019
ze_memory_provider_t *source_memory_provider;
9951020
uint32_t success_changes;
@@ -1022,7 +1047,7 @@ static int ze_memory_provider_resident_device_change_helper(uintptr_t key,
10221047
}
10231048

10241049
ze_result_t result;
1025-
if (change_data->isAdding) {
1050+
if (change_data->is_adding) {
10261051
result = g_ze_ops.zeContextMakeMemoryResident(
10271052
change_data->source_memory_provider->context, peer_device,
10281053
info->props.base, info->props.base_size);
@@ -1048,12 +1073,12 @@ static int ze_memory_provider_resident_device_change_helper(uintptr_t key,
10481073

10491074
static umf_result_t
10501075
ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
1051-
bool isAdding) {
1076+
bool is_adding) {
10521077
ze_memory_provider_t *ze_provider = provider;
10531078

10541079
LOG_INFO("%s resident device with id:%d, src_provider:%p, existing peers "
10551080
"count:%d",
1056-
(isAdding ? "adding" : "removing"), device_index, provider,
1081+
(is_adding ? "adding" : "removing"), device_index, provider,
10571082
ze_provider->resident_device_count);
10581083

10591084
uint32_t existing_peer_index = 0;
@@ -1066,7 +1091,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
10661091
if (ze_provider->resident_device_count == 0 ||
10671092
existing_peer_index == ze_provider->resident_device_count) {
10681093
// not found
1069-
if (!isAdding) { // impossible for UR, should be an assertion
1094+
if (!is_adding) {
1095+
// impossible for UR, should be an assertion
10701096
LOG_ERR("trying to remove resident device of idx:%d but the device "
10711097
"is not a peer of provider:%p currently",
10721098
device_index, provider);
@@ -1082,8 +1108,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
10821108
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
10831109
}
10841110

1085-
if (ze_provider->device_count <=
1086-
device_index) { // impossible for UR, should be an assertion
1111+
if (ze_provider->device_count <= device_index) {
1112+
// impossible for UR, should be an assertion
10871113
LOG_ERR("using too large peer device idx:%d, devices count is %d",
10881114
device_index, ze_provider->device_count);
10891115
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
@@ -1095,7 +1121,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
10951121

10961122
} else {
10971123
// found
1098-
if (isAdding) { // impossible for UR, should be an assertion
1124+
if (is_adding) {
1125+
// impossible for UR, should be an assertion
10991126
LOG_ERR("trying to add resident device of idx:%d but the device is "
11001127
"already a peer of provider:%p",
11011128
device_index, provider);
@@ -1109,7 +1136,7 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
11091136
}
11101137

11111138
struct ze_memory_provider_resident_device_change_data privData = {
1112-
.isAdding = isAdding,
1139+
.is_adding = is_adding,
11131140
.peer_device_index = device_index,
11141141
.source_memory_provider = ze_provider,
11151142
.success_changes = 0,
@@ -1129,7 +1156,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
11291156
LOG_ERR("umfMemoryTrackerIterateAll did not manage to do some change "
11301157
"numFailed:%d, numSuccess:%d",
11311158
privData.success_changes, privData.failed_changes);
1132-
return UMF_RESULT_ERROR_INVALID_ARGUMENT; // probably some other result is better, best just change into assertion
1159+
// TODO: change into permanent assertion when avail
1160+
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
11331161
}
11341162

11351163
LOG_INFO("ze_memory_provider_resident_device_change done, numSuccess:%d",

src/provider/provider_tracking.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,15 +1336,6 @@ static umf_result_t trackingGetAllocationPropertiesSize(
13361336
p->hUpstream, memory_property_id, size);
13371337
}
13381338

1339-
static umf_result_t trackingResidentDeviceChange(void *provider,
1340-
uint32_t device_index,
1341-
bool is_adding) {
1342-
(void)provider;
1343-
(void)device_index;
1344-
(void)is_adding;
1345-
return UMF_RESULT_SUCCESS;
1346-
}
1347-
13481339
umf_memory_provider_ops_t UMF_TRACKING_MEMORY_PROVIDER_OPS = {
13491340
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
13501341
.initialize = trackingInitialize,
@@ -1367,7 +1358,7 @@ umf_memory_provider_ops_t UMF_TRACKING_MEMORY_PROVIDER_OPS = {
13671358
.ext_ctl = NULL,
13681359
.ext_get_allocation_properties = trackingGetAllocationProperties,
13691360
.ext_get_allocation_properties_size = trackingGetAllocationPropertiesSize,
1370-
.ext_resident_device_change = trackingResidentDeviceChange,
1361+
.ext_resident_device_change = NULL,
13711362
};
13721363

13731364
static void free_ipc_cache_value(void *unused, void *ipc_cache_value) {

0 commit comments

Comments
 (0)