(device_ids: &[String], allow_all_devices: bool)
| 203 | } |
| 204 | |
| 205 | fn default_cdi_gpu_device_id(device_ids: &[String], allow_all_devices: bool) -> Option<String> { |
| 206 | let mut indexed = device_ids |
| 207 | .iter() |
| 208 | .filter_map(|device_id| { |
| 209 | let suffix = device_id.strip_prefix(CDI_GPU_DEVICE_PREFIX)?; |
| 210 | let index = suffix.parse::<u64>().ok()?; |
| 211 | Some((index, device_id.clone())) |
| 212 | }) |
| 213 | .collect::<Vec<_>>(); |
| 214 | if !indexed.is_empty() { |
| 215 | indexed.sort_by(|left, right| left.0.cmp(&right.0).then_with(|| left.1.cmp(&right.1))); |
| 216 | return indexed.into_iter().map(|(_, device_id)| device_id).next(); |
| 217 | } |
| 218 | |
| 219 | let mut named = device_ids |
| 220 | .iter() |
| 221 | .filter(|device_id| { |
| 222 | device_id.starts_with(CDI_GPU_DEVICE_PREFIX) && device_id.as_str() != CDI_GPU_DEVICE_ALL |
| 223 | }) |
| 224 | .cloned() |
| 225 | .collect::<Vec<_>>(); |
| 226 | if !named.is_empty() { |
| 227 | named.sort(); |
| 228 | return named.into_iter().next(); |
| 229 | } |
| 230 | |
| 231 | (allow_all_devices |
| 232 | && device_ids |
| 233 | .iter() |
| 234 | .any(|device_id| device_id == CDI_GPU_DEVICE_ALL)) |
| 235 | .then(|| CDI_GPU_DEVICE_ALL.to_string()) |
| 236 | } |
| 237 | |
| 238 | fn has_cdi_gpu_device(device_id: &str) -> bool { |
| 239 | discovered_cdi_gpu_device_ids() |
no test coverage detected