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

Method default_device_family

crates/openshell-core/src/gpu.rs:97–136  ·  view source on GitHub ↗
(
        &self,
        allow_all_devices: bool,
    )

Source from the content-addressed store, hash-verified

95 }
96
97 fn default_device_family(
98 &self,
99 allow_all_devices: bool,
100 ) -> Result<Vec<String>, CdiGpuSelectionError> {
101 let mut indexed = self
102 .device_ids
103 .iter()
104 .filter_map(|id| {
105 let suffix = cdi_nvidia_gpu_suffix(id)?;
106 let index = suffix.parse::<u64>().ok()?;
107 Some((index, id.clone()))
108 })
109 .collect::<Vec<_>>();
110 if !indexed.is_empty() {
111 indexed.sort_by(|left, right| left.0.cmp(&right.0).then_with(|| left.1.cmp(&right.1)));
112 return Ok(indexed.into_iter().map(|(_, id)| id).collect());
113 }
114
115 let mut named = self
116 .device_ids
117 .iter()
118 .filter_map(|id| {
119 let suffix = cdi_nvidia_gpu_suffix(id)?;
120 (suffix != CDI_NVIDIA_GPU_ALL_SUFFIX).then(|| id.clone())
121 })
122 .collect::<Vec<_>>();
123 if !named.is_empty() {
124 named.sort();
125 return Ok(named);
126 }
127
128 if self.device_ids.iter().any(|id| id == CDI_GPU_DEVICE_ALL) {
129 if !allow_all_devices {
130 return Err(CdiGpuSelectionError::AllDevicesDefaultUnsupported);
131 }
132 return Ok(vec![CDI_GPU_DEVICE_ALL.to_string()]);
133 }
134
135 Err(CdiGpuSelectionError::NoAvailableDevices)
136 }
137}
138
139#[derive(Debug)]

Callers 1

Calls 2

cdi_nvidia_gpu_suffixFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected