@@ -361,12 +361,37 @@ umf_result_t umfLevelZeroMemoryProviderParamsSetResidentDevices(
361
361
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
362
362
}
363
363
364
- if (residentDevicesCount && ! residentDevicesIndices ) {
364
+ if (residentDevicesCount > 0 && residentDevicesIndices == NULL ) {
365
365
LOG_ERR ("Resident devices indices array is NULL, but "
366
366
"residentDevicesCount is not zero" );
367
367
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
368
368
}
369
369
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
+
370
395
hParams -> device_handles = hDevices ;
371
396
hParams -> device_count = deviceCount ;
372
397
hParams -> resident_device_indices = residentDevicesIndices ;
@@ -989,7 +1014,7 @@ static umf_result_t ze_memory_provider_get_allocation_properties_size(
989
1014
}
990
1015
991
1016
struct ze_memory_provider_resident_device_change_data {
992
- bool isAdding ;
1017
+ bool is_adding ;
993
1018
uint32_t peer_device_index ;
994
1019
ze_memory_provider_t * source_memory_provider ;
995
1020
uint32_t success_changes ;
@@ -1022,7 +1047,7 @@ static int ze_memory_provider_resident_device_change_helper(uintptr_t key,
1022
1047
}
1023
1048
1024
1049
ze_result_t result ;
1025
- if (change_data -> isAdding ) {
1050
+ if (change_data -> is_adding ) {
1026
1051
result = g_ze_ops .zeContextMakeMemoryResident (
1027
1052
change_data -> source_memory_provider -> context , peer_device ,
1028
1053
info -> props .base , info -> props .base_size );
@@ -1048,12 +1073,12 @@ static int ze_memory_provider_resident_device_change_helper(uintptr_t key,
1048
1073
1049
1074
static umf_result_t
1050
1075
ze_memory_provider_resident_device_change (void * provider , uint32_t device_index ,
1051
- bool isAdding ) {
1076
+ bool is_adding ) {
1052
1077
ze_memory_provider_t * ze_provider = provider ;
1053
1078
1054
1079
LOG_INFO ("%s resident device with id:%d, src_provider:%p, existing peers "
1055
1080
"count:%d" ,
1056
- (isAdding ? "adding" : "removing" ), device_index , provider ,
1081
+ (is_adding ? "adding" : "removing" ), device_index , provider ,
1057
1082
ze_provider -> resident_device_count );
1058
1083
1059
1084
uint32_t existing_peer_index = 0 ;
@@ -1066,7 +1091,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
1066
1091
if (ze_provider -> resident_device_count == 0 ||
1067
1092
existing_peer_index == ze_provider -> resident_device_count ) {
1068
1093
// not found
1069
- if (!isAdding ) { // impossible for UR, should be an assertion
1094
+ if (!is_adding ) {
1095
+ // impossible for UR, should be an assertion
1070
1096
LOG_ERR ("trying to remove resident device of idx:%d but the device "
1071
1097
"is not a peer of provider:%p currently" ,
1072
1098
device_index , provider );
@@ -1082,8 +1108,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
1082
1108
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
1083
1109
}
1084
1110
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
1087
1113
LOG_ERR ("using too large peer device idx:%d, devices count is %d" ,
1088
1114
device_index , ze_provider -> device_count );
1089
1115
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -1095,7 +1121,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
1095
1121
1096
1122
} else {
1097
1123
// found
1098
- if (isAdding ) { // impossible for UR, should be an assertion
1124
+ if (is_adding ) {
1125
+ // impossible for UR, should be an assertion
1099
1126
LOG_ERR ("trying to add resident device of idx:%d but the device is "
1100
1127
"already a peer of provider:%p" ,
1101
1128
device_index , provider );
@@ -1109,7 +1136,7 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
1109
1136
}
1110
1137
1111
1138
struct ze_memory_provider_resident_device_change_data privData = {
1112
- .isAdding = isAdding ,
1139
+ .is_adding = is_adding ,
1113
1140
.peer_device_index = device_index ,
1114
1141
.source_memory_provider = ze_provider ,
1115
1142
.success_changes = 0 ,
@@ -1129,7 +1156,8 @@ ze_memory_provider_resident_device_change(void *provider, uint32_t device_index,
1129
1156
LOG_ERR ("umfMemoryTrackerIterateAll did not manage to do some change "
1130
1157
"numFailed:%d, numSuccess:%d" ,
1131
1158
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 ;
1133
1161
}
1134
1162
1135
1163
LOG_INFO ("ze_memory_provider_resident_device_change done, numSuccess:%d" ,
0 commit comments