MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / default_cdi_gpu_device_id

Function default_cdi_gpu_device_id

e2e/rust/tests/gpu/device_selection.rs:205–236  ·  view source on GitHub ↗
(device_ids: &[String], allow_all_devices: bool)

Source from the content-addressed store, hash-verified

203}
204
205fn 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
238fn has_cdi_gpu_device(device_id: &str) -> bool {
239 discovered_cdi_gpu_device_ids()

Calls 3

is_emptyMethod · 0.45
nextMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected