Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(gpu): CUDA_VISIBLE_DEVICES per GPU-UUID statt Index

purple318386a94013
diff --git a/src-tauri/src/commands/gpu.rs b/src-tauri/src/commands/gpu.rs
index 64990051..68b3c8fc 100644
--- a/src-tauri/src/commands/gpu.rs
+++ b/src-tauri/src/commands/gpu.rs
@@ -18,6 +18,7 @@
use crate::state::AppState;
use serde::Serialize;
+use std::collections::HashMap;
use std::process::Command;
use tauri::State;
@@ -57,6 +58,19 @@ pub struct DetectedGpu {
/// name: the mapping from marketing name to gfx target is AMD's to publish
/// and ours to read, never to guess.
pub arch: Option<String>,
+ /// NVIDIA's own `GPU-<uuid>` identifier (from `nvidia-smi -L` / the
+ /// `--query-gpu=uuid` field), when a second, best-effort probe could read
+ /// it. `None` on every non-NVIDIA card, on a driver too old to report it,
+ /// and on a card whose MIG mode is enabled (its physical-GPU UUID does
+ /// not select a MIG instance the way `CUDA_VISIBLE_DEVICES` needs, see
+ /// `parse_nvidia_uuid_csv`). Consumers that want a stable device selector
+ /// use this over `index` when it is `Some` (GPU-UUID Nachzug, review
+ /// 2026-09-18 Runde 2 "UUID statt Index"): `index` is only meaningful
+ /// together with `CUDA_DEVICE_ORDER=PCI_BUS_ID`, and only for as long as
+ /// nothing reorders or hotplugs a card between detection and launch,
+ /// whereas the UUID names one physical card independent of enumeration
+ /// order.
+ pub uuid: Option<String>,
}
fn run_cmd(program: &str, args: &[&str]) -> Option<String> {
@@ -83,7 +97,8 @@ fn detect_nvidia() -> Vec<DetectedGpu> {
Some(s) => s,
None => return vec![],
};
- raw.lines()
+ let mut gpus: Vec<DetectedGpu> = raw
+ .lines()
.filter_map(|line| {
let parts: Vec<&str> = line.split(',').map(|s| s.trim()).collect();
if parts.len() < 3 { return None }
@@ -99,9 +114,127 @@ fn detect_nvidia() -> Vec<DetectedGpu> {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
})
})
- .collect()
+ .collect();
+
+ // Second, separate best-effort probe for GPU-UUID Nachzug (review
+ // 2026-09-18 Runde 2, "UUID statt Index"). Kept apart from the query
+ // above on purpose: if a driver too old to know `uuid` or
+ // `mig.mode.current` rejects the whole `--query-gpu` list (some very old
+ // nvidia-smi builds fail the entire call on one unrecognised field
+ // rather than returning "N/A" for it), the base detection above --
+ // index, name, memory, the fields the picker has relied on since v2.5.0
+ // -- must keep working exactly as before. A failed or partial second
+ // probe just leaves `uuid: None` on every card, which is the documented,
+ // already-handled fallback to `index`.
+ if !gpus.is_empty() {
+ if let Some(uuid_raw) = run_cmd(
+ "nvidia-smi",
+ &["--query-gpu=index,uuid,mig.mode.current", "--format=csv,noheader,nounits"],
+ ) {
+ let by_index = parse_nvidia_uuid_csv(&uuid_raw);
+ for g in gpus.iter_mut() {
+ if let Some(info) = by_index.get(&g.index) {
+ // MIG mode enabled: a physical GPU's `GPU-<uuid>` does not
+ // select a specific MIG instance the way a MIG-mode
+ // `CUDA_VISIBLE_DEVICES` needs (that wants `MIG-<uuid>`,
+ // a different id this probe does not attempt to build).
+ // Leaving `uuid: None` here falls back to `index` for
+ // exactly this card, same as an old driver would.
+ if !info.mig_enabled {
+ g.uuid = Some(info.uuid.clone());
+ }
+ }
+ }
+ }
+ }
+ gpus
+}
+
+/// One `nvidia-smi --query-gpu=index,uuid,mig.mode.current` line's UUID and
+/// MIG state.
+#[derive(Debug)]
+struct NvidiaUuidInfo {
+ uuid: String,
+ mig_enabled: bool,
+}
+
+/// Pure parse of the UUID-enrichment probe, kept separate from `detect_nvidia`
+/// so a fabricated `nvidia-smi` line (this file's usual style for GPU
+/// probes, see `parse_nvidia_vram_csv` / `parse_rocm_smi_csv`) can drive it
+/// directly without a real card or a real driver.
+///
+/// Tolerant of both the modern three-column form and an older driver's
+/// two-column one (no `mig.mode.current` support at all — `mig_enabled`
+/// then defaults to `false`), and treats `N/A` / an empty uuid field the
+/// same as a missing one: skip that index rather than storing a value that
+/// is not a real `GPU-<uuid>`.
+fn parse_nvidia_uuid_csv(raw: &str) -> HashMap<u32, NvidiaUuidInfo> {
+ let mut out = HashMap::new();
+ for line in raw.lines() {
+ let parts: Vec<&str> = line.split(',').map(|s| s.trim()).collect();
+ if parts.len() < 2 { continue }
+ let Ok(index) = parts[0].parse::<u32>() else { continue };
+ let uuid = parts[1];
+ if uuid.is_empty() || uuid.eq_ignore_ascii_case("n/a") || !uuid.starts_with("GPU-") {
+ continue;
+ }
+ let mig_enabled = parts
+ .get(2)
+ .map(|s| s.eq_ignore_ascii_case("enabled"))
+ .unwrap_or(false);
+ out.insert(index, NvidiaUuidInfo { uuid: uuid.to_string(), mig_enabled });
+ }
+ out
+}
+
+/// Build a `CUDA_VISIBLE_DEVICES` value for a set of vendor-scoped NVIDIA
+/// indices, preferring each card's `GPU-<uuid>` form over its bare index
+/// wherever `nvidia` names that index with a known, non-MIG UUID (GPU-UUID
+/// Nachzug, review 2026-09-18 Runde 2 "UUID statt Index").
+///
+/// NVIDIA's own CUDA Programming Guide, section "CUDA Environment
+/// Variables" (docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/
+/// environment-variables.html, checked 2026-09-18), states `CUDA_VISIBLE_
+/// DEVICES` accepts a comma-separated list of device ordinals OR "GPU UUID
+/// strings", and that these "should follow the same format as given by
+/// `nvidia-smi -L`, such as `GPU-8932f937-d72c-4106-c12f-20bd9faed9f6`"
+/// (even abbreviated prefixes are accepted, as long as they stay unique on
+/// the box). The guide does not carve out a Windows/Linux difference: this
+/// is a CUDA runtime setting the driver parses identically everywhere, so
+/// torch/CUDA under native Windows, WSL, or Linux all accept the same
+/// `GPU-xxxxxxxx-...` string. The UUID form identifies one physical card
+/// independent of enumeration order -- exactly the property an index only
+/// has together with `CUDA_DEVICE_ORDER=PCI_BUS_ID`, and even then only for
+/// as long as nothing reorders or hotplugs a card between detection and
+/// launch.
+///
+/// The same page documents MIG instances as a DIFFERENT id shape,
+/// `MIG-<GPU-UUID>/<GPU instance ID>/<compute instance ID>`, not the plain
+/// `GPU-<uuid>` this function builds -- confirming why `parse_nvidia_
+/// uuid_csv` deliberately excludes MIG-enabled cards from `uuid` rather
+/// than sending a physical-GPU UUID a MIG-mode setup would not accept as a
+/// single-instance selector.
+///
+/// Falls back to the bare index per-card when that card's UUID is unknown
+/// (an old driver, or a MIG-enabled card, see `parse_nvidia_uuid_csv`) --
+/// `CUDA_DEVICE_ORDER=PCI_BUS_ID` stays set unconditionally alongside this
+/// by every caller as the fallback net for exactly that case.
+fn cuda_visible_devices_value(indices: &[u32], nvidia: &[DetectedGpu]) -> String {
+ indices
+ .iter()
+ .map(|i| {
+ nvidia
+ .iter()
+ .find(|g| g.index == *i)
+ .and_then(|g| g.uuid.as_deref())
+ .map(|u| u.to_string())
+ .unwrap_or_else(|| i.to_string())
+ })
+ .collect::<Vec<_>>()
+ .join(",")
}
fn detect_amd() -> Vec<DetectedGpu> {
@@ -183,6 +316,7 @@ fn parse_rocm_smi_csv(raw: &str) -> Vec<DetectedGpu> {
note: None,
note_severity: None,
arch,
+ uuid: None,
});
}
}
@@ -310,6 +444,7 @@ fn detect_other_via_lspci_from(
note: note_for(vendor),
note_severity: note_for(vendor).map(|_| "warn".to_string()),
arch: None,
+ uuid: None,
});
*index += 1;
}
@@ -610,6 +745,7 @@ fn detect_macos() -> Vec<DetectedGpu> {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
}]
}
@@ -703,6 +839,7 @@ fn detect_other_via_registry_from(
note: note_for(vendor),
note_severity: note_for(vendor).map(|_| "warn".to_string()),
arch: None,
+ uuid: None,
});
*index += 1;
}
@@ -829,6 +966,7 @@ fn detect_other_via_wmic_from(
note: note_for(vendor),
note_severity: note_for(vendor).map(|_| "warn".to_string()),
arch: None,
+ uuid: None,
});
*index += 1;
}
@@ -1263,6 +1401,7 @@ fn apply_rocm_facts(gpus: &mut Vec<DetectedGpu>, facts: Option<&RocmFacts>) {
note: rocm_note(version, arch.as_deref()),
note_severity: Some("info".to_string()),
arch,
+ uuid: None,
});
}
}
@@ -1492,7 +1631,25 @@ pub fn apply_gpu_env(cmd: &mut Command, selection: &GpuSelection) {
// CUDA_DEVICE_ORDER=PCI_BUS_ID, CUDA's own FASTEST_FIRST default can
// read this index against a different physical card than
// nvidia-smi's PCI-order list promised for Ollama and ComfyUI.
- "nvidia" => { cmd.env("CUDA_DEVICE_ORDER", "PCI_BUS_ID"); cmd.env("CUDA_VISIBLE_DEVICES", &csv); }
+ //
+ // GPU-UUID Nachzug (review 2026-09-18 Runde 2 "UUID statt Index"):
+ // re-detecting here and preferring `cuda_visible_devices_value`'s
+ // UUID form over the bare index closes the same ordering class of
+ // bug PCI_BUS_ID only mitigates, for Ollama/ComfyUI too, not just
+ // the trainer. `CUDA_DEVICE_ORDER` stays set unconditionally as the
+ // fallback net for whichever index this could not resolve to a UUID
+ // (no NVIDIA card detected here at all -- e.g. AMD/Intel-only box,
+ // an old driver, or a MIG-enabled card falls back to its index).
+ "nvidia" => {
+ let nvidia: Vec<DetectedGpu> = detect_gpus()
+ .unwrap_or_default()
+ .into_iter()
+ .filter(|g| g.vendor == "nvidia")
+ .collect();
+ let value = cuda_visible_devices_value(&selection.indices, &nvidia);
+ cmd.env("CUDA_DEVICE_ORDER", "PCI_BUS_ID");
+ cmd.env("CUDA_VISIBLE_DEVICES", &value);
+ }
"amd" => {
// HIP_VISIBLE_DEVICES is the official ROCm name; ROCR_VISIBLE_DEVICES
// is the lower-level Runtime equivalent that some older builds
@@ -1762,6 +1919,104 @@ End of search: 3 match(es) found.
assert!(rocr, "ROCR_VISIBLE_DEVICES should be set");
}
+ // ── GPU-UUID Nachzug: parse_nvidia_uuid_csv, mocked nvidia-smi output ────
+
+ #[test]
+ fn uuid_csv_parses_a_normal_two_card_line() {
+ let raw = "0, GPU-aaaaaaaa-0000-0000-0000-000000000000, Disabled\n\
+ 1, GPU-bbbbbbbb-0000-0000-0000-000000000000, Disabled\n";
+ let by_index = parse_nvidia_uuid_csv(raw);
+ assert_eq!(by_index.get(&0).map(|i| i.uuid.as_str()), Some("GPU-aaaaaaaa-0000-0000-0000-000000000000"));
+ assert_eq!(by_index.get(&1).map(|i| i.uuid.as_str()), Some("GPU-bbbbbbbb-0000-0000-0000-000000000000"));
+ assert!(!by_index[&0].mig_enabled);
+ }
+
+ #[test]
+ fn uuid_csv_tolerates_an_old_driver_with_no_mig_column() {
+ // Pre-MIG nvidia-smi builds never had a `mig.mode.current` field.
+ let raw = "0, GPU-cccccccc-0000-0000-0000-000000000000\n";
+ let by_index = parse_nvidia_uuid_csv(raw);
+ assert_eq!(by_index.get(&0).map(|i| i.uuid.as_str()), Some("GPU-cccccccc-0000-0000-0000-000000000000"));
+ assert!(!by_index[&0].mig_enabled, "missing column must default to false, not panic");
+ }
+
+ #[test]
+ fn uuid_csv_marks_a_mig_enabled_card() {
+ let raw = "0, GPU-dddddddd-0000-0000-0000-000000000000, Enabled\n";
+ let by_index = parse_nvidia_uuid_csv(raw);
+ assert!(by_index[&0].mig_enabled);
+ }
+
+ #[test]
+ fn uuid_csv_skips_an_unsupported_or_blank_uuid() {
+ let raw = "0, N/A, Disabled\n1, , Disabled\n2, [Unknown Error], Disabled\n";
+ let by_index = parse_nvidia_uuid_csv(raw);
+ assert!(by_index.is_empty(), "N/A / blank / non-GPU- uuid must never be stored: {by_index:?}");
+ }
+
+ // ── GPU-UUID Nachzug: cuda_visible_devices_value ─────────────────────────
+
+ fn nvidia_card(index: u32, uuid: Option<&str>) -> DetectedGpu {
+ DetectedGpu {
+ index,
+ vendor: "nvidia".into(),
+ name: format!("card {index}"),
+ memory_mib: Some(8192),
+ source: "nvidia-smi".into(),
+ note: None,
+ note_severity: None,
+ arch: None,
+ uuid: uuid.map(|u| u.to_string()),
+ }
+ }
+
+ #[test]
+ fn cuda_value_prefers_uuid_over_index_when_known() {
+ let nvidia = vec![
+ nvidia_card(0, Some("GPU-aaaa")),
+ nvidia_card(1, Some("GPU-bbbb")),
+ ];
+ assert_eq!(cuda_visible_devices_value(&[0, 1], &nvidia), "GPU-aaaa,GPU-bbbb");
+ }
+
+ /// The two-card, swapped-order case the review named explicitly:
+ /// nvidia-smi's list order (here, the slice `nvidia` is built in) must
+ /// not matter -- only the `index` field decides which card an entry in
+ /// `indices` names, so a selection or a detection sweep that returns
+ /// its cards in a different order than they were requested still maps
+ /// each index to ITS OWN uuid, never its neighbour's.
+ #[test]
+ fn cuda_value_maps_by_index_not_by_list_position_when_order_is_swapped() {
+ // Detection lists card 1 BEFORE card 0 -- e.g. FASTEST_FIRST changed
+ // nvidia-smi's own enumeration on this box, or the two GPUs were
+ // hot-plugged in the other order.
+ let nvidia = vec![
+ nvidia_card(1, Some("GPU-bbbb")),
+ nvidia_card(0, Some("GPU-aaaa")),
+ ];
+ // The selection still asks for [0, 1] in THAT order.
+ assert_eq!(
+ cuda_visible_devices_value(&[0, 1], &nvidia),
+ "GPU-aaaa,GPU-bbbb",
+ "index 0 must resolve to card 0's own uuid regardless of list position"
+ );
+ }
+
+ #[test]
+ fn cuda_value_falls_back_to_index_when_uuid_is_unknown() {
+ // Card 1 has no uuid (old driver, or excluded as MIG-enabled) --
+ // only that one card falls back, card 0 still gets its uuid.
+ let nvidia = vec![nvidia_card(0, Some("GPU-aaaa")), nvidia_card(1, None)];
+ assert_eq!(cuda_visible_devices_value(&[0, 1], &nvidia), "GPU-aaaa,1");
+ }
+
+ #[test]
+ fn cuda_value_falls_back_to_index_when_the_card_is_not_detected_at_all() {
+ // Empty nvidia list: no nvidia-smi, or a non-NVIDIA box. Must behave
+ // exactly like the pre-UUID code, a bare index CSV.
+ assert_eq!(cuda_visible_devices_value(&[0, 2], &[]), "0,2");
+ }
+
#[test]
fn apply_gpu_env_sets_oneapi_for_intel() {
let sel = GpuSelection { vendor: "intel".into(), indices: vec![0, 1] };
diff --git a/src-tauri/src/commands/trainer.rs b/src-tauri/src/commands/trainer.rs
index 5af95e4e..652d910e 100644
--- a/src-tauri/src/commands/trainer.rs
+++ b/src-tauri/src/commands/trainer.rs
@@ -562,6 +562,12 @@ pub(crate) struct TrainerGpuChoice {
pub(crate) name: String,
pub(crate) memory_mib: Option<u64>,
pub(crate) source: &'static str,
+ /// The card's `GPU-<uuid>` when `detect_gpus()` could name it (never for
+ /// the "CUDA_VISIBLE_DEVICES already set" branch, whose card may not be
+ /// in `nvidia` at all). GPU-UUID Nachzug, review 2026-09-18 Runde 2 "UUID
+ /// statt Index": `pin_trainer_gpu` prefers this over `index` the same
+ /// way `gpu.rs::cuda_visible_devices_value` does for Ollama/ComfyUI.
+ pub(crate) uuid: Option<String>,
}
/// Narrow `nvidia` down to the one card every trainer child runs on. Pure on
@@ -597,18 +603,37 @@ pub(crate) fn choose_trainer_gpu(
index: g.index,
name: g.name.clone(),
memory_mib: g.memory_mib,
+ uuid: g.uuid.clone(),
source: "the Hardware tab's GPU selection",
});
}
}
if let Some(existing) = existing_cuda_visible_devices {
- let indices: Vec<u32> = existing.split(',').filter_map(|s| s.trim().parse().ok()).collect();
+ // Tokens may be plain indices OR `GPU-<uuid>` forms -- a user who set
+ // this themselves outside LU is just as entitled to the UUID form
+ // this module now prefers internally (GPU-UUID Nachzug, review
+ // 2026-09-18 Runde 2). Try a uuid match per token first, then a
+ // numeric index, so either spelling of the user's own choice is
+ // honoured the same way.
+ let indices: Vec<u32> = existing
+ .split(',')
+ .map(|s| s.trim())
+ .filter(|s| !s.is_empty())
+ .filter_map(|tok| {
+ nvidia
+ .iter()
+ .find(|g| g.uuid.as_deref() == Some(tok))
+ .map(|g| g.index)
+ .or_else(|| tok.parse::<u32>().ok())
+ })
+ .collect();
if !indices.is_empty() {
if let Some(g) = best_of(&indices) {
return Some(TrainerGpuChoice {
index: g.index,
name: g.name.clone(),
memory_mib: g.memory_mib,
+ uuid: g.uuid.clone(),
source: "the CUDA_VISIBLE_DEVICES already set for this process",
});
}
@@ -618,6 +643,7 @@ pub(crate) fn choose_trainer_gpu(
index: indices[0],
name: format!("device {}", indices[0]),
memory_mib: None,
+ uuid: None,
source: "the CUDA_VISIBLE_DEVICES already set for this process",
});
}
@@ -626,6 +652,7 @@ pub(crate) fn choose_trainer_gpu(
index: g.index,
name: g.name.clone(),
memory_mib: g.memory_mib,
+ uuid: g.uuid.clone(),
source: "the card with the most memory",
})
}
@@ -655,9 +682,21 @@ pub(crate) fn resolve_trainer_gpu(selection: &crate::commands::gpu::GpuSelection
/// index is matched against `detect_gpus()`'s PCI-order list, so the index
/// this function writes back out needs the same ordering to mean what it
/// says.
+///
+/// GPU-UUID Nachzug (review 2026-09-18 Runde 2, "UUID statt Index"): prefers
+/// `choice.uuid` (a `GPU-<uuid>` string `detect_gpus()` could name) over the
+/// bare index whenever it is known, the same env var value NVIDIA's own
+/// CUDA_VISIBLE_DEVICES documentation and `nvidia-smi -L` both describe, and
+/// identical on Windows and Linux. This survives a driver renumbering cards
+/// between detection and launch, the PCI-order/FASTEST_FIRST mismatch
+/// `CUDA_DEVICE_ORDER` only patches over for the index form. `CUDA_DEVICE_
+/// ORDER=PCI_BUS_ID` is still set unconditionally as the fallback net for
+/// whenever `choice.uuid` is `None` (an old driver, a MIG-enabled card, or
+/// the "stale index, probe did not run" branch of `choose_trainer_gpu`).
fn pin_trainer_gpu(cmd: &mut Command, choice: &TrainerGpuChoice) {
+ let selector = choice.uuid.clone().unwrap_or_else(|| choice.index.to_string());
cmd.env("CUDA_DEVICE_ORDER", "PCI_BUS_ID");
- cmd.env("CUDA_VISIBLE_DEVICES", choice.index.to_string());
+ cmd.env("CUDA_VISIBLE_DEVICES", selector);
}
/// Every site-packages of the trainer venv. Windows puts one at
@@ -3360,6 +3399,7 @@ mod tests {
index: 1,
name: "RTX 3090 Ti".to_string(),
memory_mib: Some(24564),
+ uuid: None,
source: "the Hardware tab's GPU selection",
};
super::pin_trainer_gpu(&mut cmd, &choice);
@@ -3375,6 +3415,37 @@ mod tests {
);
}
+ /// GPU-UUID Nachzug (review 2026-09-18 Runde 2, "UUID statt Index"): when
+ /// `detect_gpus()` could name the chosen card's uuid, the child must see
+ /// THAT, not the bare index -- the whole point being independence from
+ /// detection order, which a plain index re-introduces the moment
+ /// anything hotplugs or gets renumbered between detection and launch.
+ /// `CUDA_DEVICE_ORDER` stays set regardless, as the fallback net.
+ #[test]
+ fn pin_trainer_gpu_prefers_the_uuid_over_the_index_when_known() {
+ let mut cmd = std::process::Command::new("python");
+ let choice = super::TrainerGpuChoice {
+ index: 1,
+ name: "RTX 3090 Ti".to_string(),
+ memory_mib: Some(24564),
+ uuid: Some("GPU-3eb045fd-0000-0000-0000-000000000000".to_string()),
+ source: "the Hardware tab's GPU selection",
+ };
+ super::pin_trainer_gpu(&mut cmd, &choice);
+ let envs = env_of(&cmd);
+ assert!(
+ envs.contains(&(
+ "CUDA_VISIBLE_DEVICES".into(),
+ Some("GPU-3eb045fd-0000-0000-0000-000000000000".into())
+ )),
+ "the uuid form must win over the bare index: {envs:?}",
+ );
+ assert!(
+ envs.contains(&("CUDA_DEVICE_ORDER".into(), Some("PCI_BUS_ID".into()))),
+ "CUDA_DEVICE_ORDER must stay set even when a uuid is used: {envs:?}",
+ );
+ }
+
/// Trainer-3.0.1-Folgeauftrag B1: every foreign program trainer.rs starts
/// (python, pip, winget, the venv it builds) now goes through
/// `foreign_system_command`, the same AppImage-cleanup adapter the
@@ -3402,6 +3473,7 @@ mod tests {
index: 1,
name: "RTX 3090 Ti".to_string(),
memory_mib: Some(24564),
+ uuid: None,
source: "the Hardware tab's GPU selection",
};
super::pin_trainer_gpu(&mut cmd, &choice);
@@ -3546,6 +3618,7 @@ mod tests {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
},
crate::commands::gpu::DetectedGpu {
index: 1,
@@ -3556,6 +3629,7 @@ mod tests {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
},
];
let selection = crate::commands::gpu::GpuSelection { vendor: "nvidia".into(), indices: vec![1] };
@@ -3579,6 +3653,7 @@ mod tests {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
},
crate::commands::gpu::DetectedGpu {
index: 1,
@@ -3589,6 +3664,7 @@ mod tests {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
},
];
let selection = crate::commands::gpu::GpuSelection::default();
@@ -3597,6 +3673,63 @@ mod tests {
assert_eq!(choice.source, "the CUDA_VISIBLE_DEVICES already set for this process");
}
+ /// GPU-UUID Nachzug: a user who set `CUDA_VISIBLE_DEVICES` to a
+ /// `GPU-<uuid>` themselves (outside LU) is honoured exactly the same as
+ /// one who used a plain index -- the uuid form is not a second, unread
+ /// spelling.
+ #[test]
+ fn choose_trainer_gpu_matches_an_existing_cuda_visible_devices_given_as_a_uuid() {
+ let cards = vec![
+ crate::commands::gpu::DetectedGpu {
+ index: 0,
+ vendor: "nvidia".into(),
+ name: "Tesla P100 (display)".into(),
+ memory_mib: Some(4096),
+ source: "nvidia-smi".into(),
+ note: None,
+ note_severity: None,
+ arch: None,
+ uuid: Some("GPU-aaaa".into()),
+ },
+ crate::commands::gpu::DetectedGpu {
+ index: 1,
+ vendor: "nvidia".into(),
+ name: "Tesla P100".into(),
+ memory_mib: Some(16384),
+ source: "nvidia-smi".into(),
+ note: None,
+ note_severity: None,
+ arch: None,
+ uuid: Some("GPU-bbbb".into()),
+ },
+ ];
+ let selection = crate::commands::gpu::GpuSelection::default();
+ let choice = super::choose_trainer_gpu(&cards, &selection, Some("GPU-bbbb")).expect("a card was chosen");
+ assert_eq!(choice.index, 1);
+ assert_eq!(choice.uuid.as_deref(), Some("GPU-bbbb"));
+ assert_eq!(choice.source, "the CUDA_VISIBLE_DEVICES already set for this process");
+ }
+
+ /// The normal (no existing env var, no user override) priority also
+ /// carries the uuid through, so `pin_trainer_gpu` can prefer it.
+ #[test]
+ fn choose_trainer_gpu_carries_the_uuid_through_on_the_hardware_tab_pick() {
+ let cards = vec![crate::commands::gpu::DetectedGpu {
+ index: 0,
+ vendor: "nvidia".into(),
+ name: "RTX 3060".into(),
+ memory_mib: Some(12288),
+ source: "nvidia-smi".into(),
+ note: None,
+ note_severity: None,
+ arch: None,
+ uuid: Some("GPU-cccc".into()),
+ }];
+ let selection = crate::commands::gpu::GpuSelection { vendor: "nvidia".into(), indices: vec![0] };
+ let choice = super::choose_trainer_gpu(&cards, &selection, None).expect("a card was chosen");
+ assert_eq!(choice.uuid.as_deref(), Some("GPU-cccc"));
+ }
+
/// Neither a Hardware-tab pick nor an existing env var: the card with the
/// most memory wins, not index 0. CUDA without `CUDA_DEVICE_ORDER` sorts
/// fastest-first, which is not the same promise.
@@ -3612,6 +3745,7 @@ mod tests {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
},
crate::commands::gpu::DetectedGpu {
index: 1,
@@ -3622,6 +3756,7 @@ mod tests {
note: None,
note_severity: None,
arch: None,
+ uuid: None,
},
];
let selection = crate::commands::gpu::GpuSelection::default();