diff --git a/crates/rocm-core/src/examine/linux_gpus.rs b/crates/rocm-core/src/examine/linux_gpus.rs index 5cfa8220d..62a3e5327 100644 --- a/crates/rocm-core/src/examine/linux_gpus.rs +++ b/crates/rocm-core/src/examine/linux_gpus.rs @@ -562,10 +562,18 @@ fn apply_kernel_gpu_membership(e: &mut Examination, nodes: &[crate::KfdGpuNode]) gfx_target: node.gfx_target.clone(), pci_id: node.pci_id.clone(), is_amd: true, - // Left unset rather than guessed, for the same reason - // `probe_gpus_sysfs_fallback` leaves it unset: KFD gives the - // target, not the packaging. - is_apu: None, + // The target is enough to answer the family question, and every + // gfx115x part is an APU. Packaging (which SKU, which VRAM + // carve-out) still needs a name; `has_apu` only needs the + // family, so leaving this unset hid kernel-visible APUs on + // hosts without `lspci`. + // + // An empty target is unknown, not discrete. KFD leaves it empty + // when its `gfx_target_version` does not decode, and answering + // `Some(false)` there would stamp a confident "discrete" verdict + // from a failed lookup -- the same mistake this change fixes for + // the PCI name, one layer down. + is_apu: (!node.gfx_target.is_empty()).then(|| gfx_is_apu_family(&node.gfx_target)), }); continue; }; @@ -578,6 +586,18 @@ fn apply_kernel_gpu_membership(e: &mut Examination, nodes: &[crate::KfdGpuNode]) // there is nothing to compare it against. if gpu.gfx_target.is_empty() { gpu.gfx_target = node.gfx_target.clone(); + // `lspci` did not resolve a target from the name, so the `is_apu` + // carried over from the PCI scan was a failed name lookup, not a + // verdict about the part. KFD's target is the first real evidence, + // and `gfx_is_apu_family` answers for the family -- on gfx1151 the + // old path reported an APU with `has_apu: false`. + // + // Only when the node actually names one: an empty target is unknown, + // and a verdict the name already resolved (`Some(true)`) is never + // downgraded by it. + if gpu.is_apu != Some(true) && !gpu.gfx_target.is_empty() { + gpu.is_apu = Some(gfx_is_apu_family(&gpu.gfx_target)); + } } gpus.push(gpu); } @@ -786,6 +806,143 @@ mod tests { ); } + #[test] + fn a_kernel_target_classifies_an_unnamed_apu() { + // Strix Halo: `pci.ids` does not know 1002:1586, so lspci prints + // "... [AMD/ATI] Device", `classify_amd_marketing_name` resolves no + // target, and the PCI scan stamped `is_apu: false` from that failed + // lookup. KFD still names the part. Before this, `examine` reported + // `gfx_target: gfx1151` next to `has_apu: false`. + let mut e = Examination { + gpus: vec![Gpu { + name: "Advanced Micro Devices, Inc. [AMD/ATI] Device".to_owned(), + gfx_target: String::new(), + pci_id: "0000:c5:00.0".to_owned(), + is_amd: true, + is_apu: Some(false), + }], + ..Examination::default() + }; + apply_kernel_gpu_membership( + &mut e, + &[crate::KfdGpuNode { + pci_id: "0000:c5:00.0".to_owned(), + gfx_target: "gfx1151".to_owned(), + }], + ); + + assert_eq!(e.gpus[0].gfx_target, "gfx1151"); + assert_eq!( + e.gpus[0].is_apu, + Some(true), + "the kernel target is the first real evidence when the name resolved none" + ); + } + + #[test] + fn a_kernel_only_apu_node_is_classified_from_its_target() { + // The same host without `lspci`: the membership pass is the only probe + // that sees the GPU, so it must not leave the verdict unset. + let mut e = Examination::default(); + apply_kernel_gpu_membership( + &mut e, + &[crate::KfdGpuNode { + pci_id: "0000:c5:00.0".to_owned(), + gfx_target: "gfx1151".to_owned(), + }], + ); + + assert_eq!(e.gpus.len(), 1); + assert_eq!(e.gpus[0].is_apu, Some(true)); + // ... while a discrete target still lands on the other side. + let mut d = Examination::default(); + apply_kernel_gpu_membership( + &mut d, + &[crate::KfdGpuNode { + pci_id: "0000:03:00.0".to_owned(), + gfx_target: "gfx1100".to_owned(), + }], + ); + assert_eq!(d.gpus[0].is_apu, Some(false)); + } + + #[test] + fn an_unparseable_kernel_target_leaves_the_family_unknown() { + // KFD leaves `gfx_target` empty when its `gfx_target_version` does not + // decode, and `gfx_is_apu_family("")` answers `false`. Reading that as a + // verdict would call an unidentifiable APU a discrete card on exactly the + // host shape `examine` exists for: no `lspci`, no ROCm installed. + let mut e = Examination::default(); + apply_kernel_gpu_membership( + &mut e, + &[crate::KfdGpuNode { + pci_id: "0000:c5:00.0".to_owned(), + gfx_target: String::new(), + }], + ); + + assert_eq!( + e.gpus.len(), + 1, + "the card is usable and must still be listed" + ); + assert_eq!( + e.gpus[0].is_apu, None, + "an undecoded target is unknown, not a discrete verdict" + ); + summarise_gpu_categories(&mut e); + assert!(!e.has_apu); + assert!( + !e.has_discrete_amd, + "nothing established that this is a discrete card: {:#?}", + e.gpus + ); + } + + #[test] + fn a_resolved_apu_verdict_is_not_downgraded_by_a_kernel_target() { + // The name already answered the family question (`Some(true)`), and the + // node's target is outside the APU list. `lspci` naming an APU is a + // statement about the part, so the membership pass must not turn it into + // "discrete" -- it only fills the target in. + // + // This is a guard-regression test, not a feature-presence one: with the + // whole reclassification removed, `is_apu` stays `Some(true)` here too, + // because the pre-change code never touched it in this branch. It fails + // only when the guard itself is weakened (e.g. to `if true`). Revert + // coverage for the fix is carried by + // `a_kernel_target_classifies_an_unnamed_apu` above. + let mut e = Examination { + gpus: vec![Gpu { + name: "Strix Halo [Radeon Graphics / Radeon 8050S Graphics / Radeon 8060S \ + Graphics]" + .to_owned(), + gfx_target: String::new(), + pci_id: "0000:c5:00.0".to_owned(), + is_amd: true, + is_apu: Some(true), + }], + ..Examination::default() + }; + apply_kernel_gpu_membership( + &mut e, + &[crate::KfdGpuNode { + pci_id: "0000:c5:00.0".to_owned(), + gfx_target: "gfx1200".to_owned(), + }], + ); + + assert_eq!( + e.gpus[0].gfx_target, "gfx1200", + "the empty field is still filled in" + ); + assert_eq!( + e.gpus[0].is_apu, + Some(true), + "a resolved APU verdict is never downgraded by the kernel target" + ); + } + #[test] fn each_kernel_node_labels_its_own_card_and_leaves_other_vendors_alone() { // An APU + a discrete card. Reading the target per node is what makes @@ -1400,6 +1557,11 @@ mod tests { // RDNA3 / RDNA3.5 iGPUs: Phoenix and Strix. ("PCI\\VEN_1002&DEV_15BF&SUBSYS_55555555", "gfx1103", true), ("PCI\\VEN_1002&DEV_1114&SUBSYS_66666666", "gfx1152", true), + // Strix Halo. Upstream `pci.ids` names it "Strix Halo [Radeon + // Graphics / Radeon 8050S Graphics / Radeon 8060S Graphics]"; older + // packaged copies predate that entry, which is why the id table has + // to know the target on its own. + ("PCI\\VEN_1002&DEV_1586&SUBSYS_00001028", "gfx1151", true), // Discrete cards through the same door, so a blanket `true` fails // here too: Navi 21 / 22 / 23 / 24 and Navi 48. ("PCI\\VEN_1002&DEV_73A0&SUBSYS_77777777", "gfx1030", false), diff --git a/crates/rocm-core/src/gfx_target.rs b/crates/rocm-core/src/gfx_target.rs index 18c429343..685d8be7d 100644 --- a/crates/rocm-core/src/gfx_target.rs +++ b/crates/rocm-core/src/gfx_target.rs @@ -234,6 +234,18 @@ pub(crate) fn gfx_target_from_amd_pci_device_id(device_id: &str) -> Option<&'sta "15bf" | "164f" | "1900" | "1901" => Some("gfx1103"), // RDNA3.5 APUs with public PCI IDs that map cleanly to one gfx target. "1114" => Some("gfx1152"), + // Strix Halo: KFD reports gfx_target_version 110501 (gfx1151) for + // device 1586. Upstream `pci.ids` now carries the id as "Strix Halo + // [Radeon Graphics / Radeon 8050S Graphics / Radeon 8060S Graphics]", + // but older packaged copies predate that entry, which is why this table + // answers without reading one. + // + // Only the Windows/PNP path reads this row today + // (`gfx_target_from_pnp_device_id`); the Linux `lspci` reader that would + // consume it is the other half of #507 and does not exist yet. The Linux + // e2e scenarios for #449 exercise the kernel-target reclassification in + // `apply_kernel_gpu_membership`, not this row. + "1586" => Some("gfx1151"), // Navi 48: Radeon RX 9070 / 9070 XT / 9070 GRE. "7550" => Some("gfx1201"), _ => None, @@ -747,6 +759,7 @@ mod tests { ("164F", "gfx1103"), ("1900", "gfx1103"), ("1114", "gfx1152"), + ("1586", "gfx1151"), // Vega APUs: Renoir, Cezanne, Lucienne, Barcelo. ("1636", "gfx90c"), ("1638", "gfx90c"), diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index a5a7d1c52..7c53474ba 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -793,3 +793,38 @@ Feature: GPU detection and system inspection Given the active runtime is a nightly runtime installed for one exact GPU When the user inspects the system Then the runtime state names the channel, package source, source layout and exact GPU target that runtime was installed from + + # #449: older packaged copies of `pci.ids` predate Strix Halo, so `lspci` + # prints the bare word "Device" and the PCI scan cannot resolve a target -- + # but it still stamped `is_apu: false` from that failed name lookup. The + # kernel's own topology names the part (gfx1151), and a kernel target is + # enough to answer the family question, so the machine came out as + # `has_apu: false` + `has_discrete_amd: true` on a unified-memory APU. + # + # Simulated host rather than `@requires-gpu`: the premise is a *kernel* node + # plus a PCI name the id table does not know, both planted under the scenario's + # own root, so every Linux lane can drive it. The When step has to be the + # planted-host one: it runs the CLI through the scenario environment, which is + # what puts the stub `lspci`/`rocminfo` on PATH and points the probes at that + # root. The plain "inspects the system" step ignores that environment and asks + # the runner itself, which has no APU and answers `gpus: []`. The `rocminfo` + # stub is load-bearing too -- on a runner with ROCm installed the real probe + # resolves the APU on its own (it already classifies by target) and would mask + # the defect. + @id:examine-classifies-an-apu-the-pci-name-cannot @requires-os:linux + Scenario: examine-55 - A GPU whose PCI name is unrecognised is still classified as an APU + Given a machine whose PCI name for its APU is unrecognised + When the user inspects that machine in machine-readable form + Then the inspection classifies the kernel-visible GPU as an APU + + # The other half of #449: the GPU is only in the kernel topology because the + # PCI scan sees nothing at all (no `lspci`, or one that enumerates an empty + # bus). That branch decides `is_apu` from the node's target alone, and before + # this change it left the verdict unset -- so a gfx1151 host with no PCI tools + # still reported `has_apu: false`. examine-55 always has a PCI match and never + # reaches the branch, so nothing covered it. + @id:examine-classifies-a-kernel-only-apu @requires-os:linux + Scenario: examine-56 - An APU the PCI scan never sees is still classified as an APU + Given a machine whose kernel exposes an APU the PCI scan cannot see + When the user inspects that machine in machine-readable form + Then the inspection classifies the kernel-only GPU as an APU diff --git a/tests/e2e-cucumber/tests/e2e/examine_steps.rs b/tests/e2e-cucumber/tests/e2e/examine_steps.rs index a3b34fef3..85273ff9f 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -1205,6 +1205,63 @@ async fn assert_gpus_match_kfd_nodes(world: &mut E2eWorld) { } } +#[then("the inspection classifies the kernel-visible GPU as an APU")] +async fn assert_unnamed_gpu_is_apu(world: &mut E2eWorld) { + let json = parsed_json(world); + assert_eq!( + json.get("has_apu").and_then(serde_json::Value::as_bool), + Some(true), + "the kernel names an APU, so the summary must not call it a discrete card:\n{json:#}" + ); + let gpu = json + .get("gpus") + .and_then(serde_json::Value::as_array) + .and_then(|gpus| gpus.first()) + .unwrap_or_else(|| panic!("the inspection listed no GPU:\n{json:#}")); + assert_eq!( + gpu.get("is_apu").and_then(serde_json::Value::as_bool), + Some(true), + "the PCI name resolved no target, so the kernel's target is the only evidence \ + about the family:\n{gpu:#}" + ); + assert_eq!( + gpu.get("gfx_target").and_then(serde_json::Value::as_str), + Some("gfx1151"), + "the kernel's target has to reach the entry it classifies:\n{gpu:#}" + ); +} + +#[then("the inspection classifies the kernel-only GPU as an APU")] +async fn assert_kernel_only_gpu_is_apu(world: &mut E2eWorld) { + let json = parsed_json(world); + assert_eq!( + json.get("has_apu").and_then(serde_json::Value::as_bool), + Some(true), + "with no PCI entry the kernel target is the only evidence, and it names an APU:\n{json:#}" + ); + assert_eq!( + json.get("has_discrete_amd") + .and_then(serde_json::Value::as_bool), + Some(false), + "an APU must not be tallied as a discrete card:\n{json:#}" + ); + let gpu = json + .get("gpus") + .and_then(serde_json::Value::as_array) + .and_then(|gpus| gpus.first()) + .unwrap_or_else(|| panic!("the inspection listed no GPU:\n{json:#}")); + assert_eq!( + gpu.get("is_apu").and_then(serde_json::Value::as_bool), + Some(true), + "the entry the kernel topology supplied has to carry the verdict:\n{gpu:#}" + ); + assert_eq!( + gpu.get("gfx_target").and_then(serde_json::Value::as_str), + Some("gfx1151"), + "the node's target has to reach the entry it classifies:\n{gpu:#}" + ); +} + #[then("the inspection lists the code object manager libraries it found")] async fn assert_comgr_copies_reported(world: &mut E2eWorld) { assert_eq!( @@ -1752,6 +1809,102 @@ async fn assert_no_amdgpu_fault_evidence(world: &mut E2eWorld) { } } +#[given("a machine whose PCI name for its APU is unrecognised")] +async fn unnamed_apu_machine(world: &mut E2eWorld) { + plant_unnamed_apu_fixtures(world); +} + +/// #449's host: `pci.ids` predates Strix Halo, so `lspci` names the device only +/// as "Device" while the kernel still reports gfx1151. Both stubs are part of +/// the premise: +/// +/// - `lspci` must answer with the real bus entry, so the PCI scan places the card +/// and resolves no target from its name -- that failed lookup is what stamped +/// `is_apu: false`. +/// - `rocminfo` must answer with nothing, because a runner with ROCm installed +/// would otherwise resolve the APU through its own probe, which already +/// classified by target and would hide the defect under test. +/// +/// The node's address is `0000:c5:00.0`: `location_id 50432` is `0xc500`, the +/// same encoding a real KFD node uses (`(bus << 8) | devfn`). +fn plant_unnamed_apu_fixtures(world: &mut E2eWorld) { + let root = world + .isolated_root + .as_ref() + .expect("no isolated root") + .path() + .to_owned(); + let node = root.join("host-root/sys/class/kfd/kfd/topology/nodes/1"); + std::fs::create_dir_all(&node).expect("failed to create planted KFD node"); + std::fs::write( + node.join("properties"), + "cpu_cores_count 0\nsimd_count 80\ngfx_target_version 110501\n\ + domain 0\nlocation_id 50432\n", + ) + .expect("failed to write planted KFD node properties"); + put_fake_executables_on_path( + world, + &[ + ( + "lspci", + "#!/bin/sh\n\ + echo '0000:c5:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. \ + [AMD/ATI] Device [1002:1586] (rev cb)'\n", + ), + ("rocminfo", "#!/bin/sh\nexit 0\n"), + ], + ); + world.command_env.push(( + "ROCM_CLI_TEST_HOST_ROOT", + root.join("host-root").into_os_string(), + )); +} + +#[given("a machine whose kernel exposes an APU the PCI scan cannot see")] +async fn kernel_only_apu_machine(world: &mut E2eWorld) { + plant_kernel_only_apu_fixtures(world); +} + +/// The host shape `rocm examine` exists for: ROCm is not installed yet, so there +/// is no `lspci` entry to read and the kernel's own topology is the only place +/// the GPU appears. +/// +/// The stub `lspci` deliberately reports an empty bus. A real one on the runner +/// would either add a probe failure of its own or, on a GPU lane, print an entry +/// that matches nothing here -- and the branch under test is the one taken when +/// no PCI entry matched at all. +/// +/// The `rocminfo` stub is load-bearing for the same reason as in examine-55: a +/// runner with ROCm installed resolves the APU through its own probe first and +/// would mask the verdict this scenario is about. +fn plant_kernel_only_apu_fixtures(world: &mut E2eWorld) { + let root = world + .isolated_root + .as_ref() + .expect("no isolated root") + .path() + .to_owned(); + let node = root.join("host-root/sys/class/kfd/kfd/topology/nodes/1"); + std::fs::create_dir_all(&node).expect("failed to create planted KFD node"); + std::fs::write( + node.join("properties"), + "cpu_cores_count 0\nsimd_count 80\ngfx_target_version 110501\n\ + domain 0\nlocation_id 50432\n", + ) + .expect("failed to write planted KFD node properties"); + put_fake_executables_on_path( + world, + &[ + ("lspci", "#!/bin/sh\nexit 0\n"), + ("rocminfo", "#!/bin/sh\nexit 0\n"), + ], + ); + world.command_env.push(( + "ROCM_CLI_TEST_HOST_ROOT", + root.join("host-root").into_os_string(), + )); +} + #[when("the user inspects that machine in machine-readable form")] async fn user_inspects_planted_machine(world: &mut E2eWorld) { let (stdout, stderr, rc) =