(
&self,
inventory: &CdiGpuInventory,
count: u32,
consume: bool,
allow_all_devices: bool,
)
| 226 | } |
| 227 | |
| 228 | fn selected_default_device_ids( |
| 229 | &self, |
| 230 | inventory: &CdiGpuInventory, |
| 231 | count: u32, |
| 232 | consume: bool, |
| 233 | allow_all_devices: bool, |
| 234 | ) -> Result<Vec<String>, CdiGpuSelectionError> { |
| 235 | let devices = inventory.default_device_family(allow_all_devices)?; |
| 236 | let count = |
| 237 | usize::try_from(count).map_err(|_| CdiGpuSelectionError::InsufficientDevices { |
| 238 | requested: count, |
| 239 | available: u32::try_from(devices.len()).unwrap_or(u32::MAX), |
| 240 | })?; |
| 241 | let available = devices.len(); |
| 242 | if count > available { |
| 243 | return Err(CdiGpuSelectionError::InsufficientDevices { |
| 244 | requested: u32::try_from(count).unwrap_or(u32::MAX), |
| 245 | available: u32::try_from(available).unwrap_or(u32::MAX), |
| 246 | }); |
| 247 | } |
| 248 | let base = if consume { |
| 249 | self.next.fetch_add(count, Ordering::Relaxed) |
| 250 | } else { |
| 251 | self.next.load(Ordering::Relaxed) |
| 252 | }; |
| 253 | Ok((0..count) |
| 254 | .map(|offset| devices[(base + offset) % available].clone()) |
| 255 | .collect()) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /// CDI GPU selection failed. |
no test coverage detected