@@ -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
9911016struct 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
10491074static umf_result_t
10501075ze_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" ,
0 commit comments