Validate a compute-driver GPU request against driver-owned specific devices. Drivers call this when a sandbox request combines portable GPU requirements with exact device identifiers in `driver_config`. # Errors Returns an error when the sandbox GPU request is absent, when `gpu.count` is zero, when device IDs are duplicated, or when the effective GPU count does not equal the number of specific d
(
gpu: Option<&DriverGpuResourceRequirements>,
specific_devices: &[String],
driver_config_field: &str,
)
| 312 | /// is zero, when device IDs are duplicated, or when the effective GPU count |
| 313 | /// does not equal the number of specific devices. |
| 314 | pub fn validate_specific_gpu_device_request( |
| 315 | gpu: Option<&DriverGpuResourceRequirements>, |
| 316 | specific_devices: &[String], |
| 317 | driver_config_field: &str, |
| 318 | ) -> Result<(), String> { |
| 319 | let device_count = specific_devices.len(); |
| 320 | if device_count == 0 { |
| 321 | return Ok(()); |
| 322 | } |
| 323 | |
| 324 | let mut seen = HashSet::with_capacity(device_count); |
| 325 | for device in specific_devices { |
| 326 | if !seen.insert(device.as_str()) { |
| 327 | return Err(format!( |
| 328 | "{driver_config_field} contains duplicate device ID '{device}'" |
| 329 | )); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | let Some(count) = effective_driver_gpu_count(gpu)? else { |
| 334 | return Err(format!("{driver_config_field} requires a gpu request")); |
| 335 | }; |
| 336 | |
| 337 | if usize::try_from(count).ok() != Some(device_count) { |
| 338 | return Err(format!( |
| 339 | "gpu count ({count}) must match {driver_config_field} length ({device_count})" |
| 340 | )); |
| 341 | } |
| 342 | |
| 343 | Ok(()) |
| 344 | } |
| 345 | |
| 346 | #[cfg(test)] |
| 347 | mod tests { |