From 8c230acf7799d06438b620371b9f0e7f00ad932c Mon Sep 17 00:00:00 2001 From: Hu Di <812791840@qq.com> Date: Mon, 26 Oct 2026 17:14:04 +0800 Subject: [PATCH 1/4] fix(examine): classify an APU from the kernel target when PCI cannot name it On a Strix Halo host `pci.ids` has no entry for 1002:1586, so `lspci` prints the bare word "Device". The PCI scan resolves no target from that name but still records `is_apu: false` -- the failed lookup, not a verdict about the part. The KFD topology then supplies `gfx_target: gfx1151` in `apply_kernel_gpu_membership` without revisiting the flag, so `examine --json` reported "gfx_target": "gfx1151", "is_apu": false, "has_apu": false, "has_discrete_amd": true on a unified-memory APU. Consumers that branch on `has_apu` (APU diagnostics, GTT tuning) therefore skipped exactly the machine they exist for. The node's target is the first real evidence about the device, and `gfx_is_apu_family` answers the family question from it -- the same answer the `rocminfo` path already derives from its agent name. Use it to reclassify when the PCI scan could not resolve a target, and to classify a kernel-only node instead of leaving it `None`. A discrete target still classifies as discrete. Refs #449 Signed-off-by: Hu Di <812791840@qq.com> --- crates/rocm-core/src/examine/linux_gpus.rs | 78 ++++++++++++++++++- tests/e2e-cucumber/features/examine.feature | 18 +++++ tests/e2e-cucumber/tests/e2e/examine_steps.rs | 77 ++++++++++++++++++ 3 files changed, 169 insertions(+), 4 deletions(-) diff --git a/crates/rocm-core/src/examine/linux_gpus.rs b/crates/rocm-core/src/examine/linux_gpus.rs index 5cfa8220da..7a01ffb814 100644 --- a/crates/rocm-core/src/examine/linux_gpus.rs +++ b/crates/rocm-core/src/examine/linux_gpus.rs @@ -562,10 +562,12 @@ 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`. + is_apu: Some(gfx_is_apu_family(&node.gfx_target)), }); continue; }; @@ -578,6 +580,14 @@ 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`. + if gpu.is_apu != Some(true) { + gpu.is_apu = Some(gfx_is_apu_family(&gpu.gfx_target)); + } } gpus.push(gpu); } @@ -786,6 +796,66 @@ 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 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 diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index a5a7d1c52b..4e84291b16 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -793,3 +793,21 @@ 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: `pci.ids` predates 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 `rocminfo` stub is + # load-bearing -- 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 the system in machine-readable form + Then the inspection classifies the kernel-visible 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 a3b34fef3c..3e1d99aff4 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -1205,6 +1205,32 @@ 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 lists the code object manager libraries it found")] async fn assert_comgr_copies_reported(world: &mut E2eWorld) { assert_eq!( @@ -1752,6 +1778,57 @@ 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(), + )); +} + #[when("the user inspects that machine in machine-readable form")] async fn user_inspects_planted_machine(world: &mut E2eWorld) { let (stdout, stderr, rc) = From f8780bde44e8535294b628caa1445ac356ade410 Mon Sep 17 00:00:00 2001 From: Hu Di <812791840@qq.com> Date: Mon, 26 Oct 2026 17:14:09 +0800 Subject: [PATCH 2/4] fix(host_gpu): map PCI device 1586 to gfx1151 `pci.ids` does not name 1002:1586, so any probe that resolves a target from the device id instead of the marketing name has nothing to match. On the Strix Halo machine this was verified on, `lspci -nn` reports the id and the KFD node reports `gfx_target_version 110501` (gfx1151) for the same address, which is the confirmation #507 asked for before adding the row. Refs #507 Signed-off-by: Hu Di <812791840@qq.com> --- crates/rocm-core/src/gfx_target.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/rocm-core/src/gfx_target.rs b/crates/rocm-core/src/gfx_target.rs index 18c4293431..176c2a60ad 100644 --- a/crates/rocm-core/src/gfx_target.rs +++ b/crates/rocm-core/src/gfx_target.rs @@ -234,6 +234,9 @@ 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, and `pci.ids` still has no name for the id. + "1586" => Some("gfx1151"), // Navi 48: Radeon RX 9070 / 9070 XT / 9070 GRE. "7550" => Some("gfx1201"), _ => None, @@ -747,6 +750,7 @@ mod tests { ("164F", "gfx1103"), ("1900", "gfx1103"), ("1114", "gfx1152"), + ("1586", "gfx1151"), // Vega APUs: Renoir, Cezanne, Lucienne, Barcelo. ("1636", "gfx90c"), ("1638", "gfx90c"), From d0f970257143ed7ea9b6f9c89339e8a3bffb5966 Mon Sep 17 00:00:00 2001 From: Hu Di <812791840@qq.com> Date: Tue, 27 Oct 2026 16:42:52 +0800 Subject: [PATCH 3/4] fix(examine): drive the planted host, and keep an undecoded target unknown Review follow-up on #726. The examine-29 When step was "inspects the system", which runs the CLI against the runner itself: `world.command_env` (the stub `lspci`/`rocminfo` and `ROCM_CLI_TEST_HOST_ROOT`) is applied only by the planted-machine step. Every lane therefore inspected the host instead of the fixture -- green on a real Strix Halo whether or not the fix is present, and `gpus: []` with a failed assertion on a lane without a GPU. Switch it to the planted-machine step, which is also the one that skips framework probing. Also: * an empty `gfx_target` is unknown, not discrete. KFD leaves it empty when its `gfx_target_version` does not decode and `gfx_is_apu_family("")` answers false, so both membership branches now keep `None` instead of stamping a "discrete" verdict from a failed decode -- the same mistake this PR fixes for the PCI name, one layer down; * unit tests for what the existing ones never reached: the `is_apu != Some(true)` guard (a resolved APU verdict is never downgraded by a kernel target) and an undecoded target staying unknown; * examine-30 drives the kernel-only branch end to end (stub `lspci` reporting an empty bus), which examine-29 cannot reach because it always has a PCI match; * the 1586 comments no longer claim `pci.ids` has no name for the id -- upstream carries it, older packaged copies do not -- and the row joins `pnp_device_id_table_agrees_about_apus`. Refs #449, #507 Signed-off-by: Hu Di <812791840@qq.com> --- crates/rocm-core/src/examine/linux_gpus.rs | 89 ++++++++++++++++++- crates/rocm-core/src/gfx_target.rs | 5 +- tests/e2e-cucumber/features/examine.feature | 37 +++++--- tests/e2e-cucumber/tests/e2e/examine_steps.rs | 76 ++++++++++++++++ 4 files changed, 194 insertions(+), 13 deletions(-) diff --git a/crates/rocm-core/src/examine/linux_gpus.rs b/crates/rocm-core/src/examine/linux_gpus.rs index 7a01ffb814..4135b7640e 100644 --- a/crates/rocm-core/src/examine/linux_gpus.rs +++ b/crates/rocm-core/src/examine/linux_gpus.rs @@ -567,7 +567,13 @@ fn apply_kernel_gpu_membership(e: &mut Examination, nodes: &[crate::KfdGpuNode]) // carve-out) still needs a name; `has_apu` only needs the // family, so leaving this unset hid kernel-visible APUs on // hosts without `lspci`. - is_apu: Some(gfx_is_apu_family(&node.gfx_target)), + // + // 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; }; @@ -585,7 +591,11 @@ fn apply_kernel_gpu_membership(e: &mut Examination, nodes: &[crate::KfdGpuNode]) // 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`. - if gpu.is_apu != Some(true) { + // + // 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)); } } @@ -856,6 +866,76 @@ mod tests { 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. + 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 @@ -1470,6 +1550,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 176c2a60ad..0c24c6f887 100644 --- a/crates/rocm-core/src/gfx_target.rs +++ b/crates/rocm-core/src/gfx_target.rs @@ -235,7 +235,10 @@ pub(crate) fn gfx_target_from_amd_pci_device_id(device_id: &str) -> Option<&'sta // 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, and `pci.ids` still has no name for the id. + // 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. "1586" => Some("gfx1151"), // Navi 48: Radeon RX 9070 / 9070 XT / 9070 GRE. "7550" => Some("gfx1201"), diff --git a/tests/e2e-cucumber/features/examine.feature b/tests/e2e-cucumber/features/examine.feature index 4e84291b16..7c53474ba7 100644 --- a/tests/e2e-cucumber/features/examine.feature +++ b/tests/e2e-cucumber/features/examine.feature @@ -794,20 +794,37 @@ Feature: GPU detection and system inspection 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: `pci.ids` predates 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. + # #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 `rocminfo` stub is - # load-bearing -- 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. + # 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 the system in machine-readable form + 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 3e1d99aff4..bce7081582 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -1231,6 +1231,37 @@ async fn assert_unnamed_gpu_is_apu(world: &mut E2eWorld) { ); } +#[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!( @@ -1829,6 +1860,51 @@ fn plant_unnamed_apu_fixtures(world: &mut E2eWorld) { )); } +#[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-29: 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) = From f8ba57fd70d5a4cfaf544c727c2b983f86485c37 Mon Sep 17 00:00:00 2001 From: Hu Di <812791840@qq.com> Date: Wed, 28 Oct 2026 10:12:10 +0800 Subject: [PATCH 4/4] docs(examine): say which path reads the 1586 row, and what the guard test pins Review follow-up on #726, comments only. The `1586 => gfx1151` row is reached only through the Windows/PNP path; the Linux `lspci` reader that would consume device ids is the other half of #507 and does not exist yet, so the Linux scenarios for #449 exercise the kernel-target reclassification instead. Saying that at the row stops the two "1586" fixes from reading as one covered by the e2e scenarios. The non-downgrade test fails only when the guard is weakened, not when the whole reclassification is reverted, because the pre-change code never touched `is_apu` in that branch. Naming it a guard-regression test, and pointing at the sibling that does carry revert coverage, keeps the next reader from reading more into a green run than it proves. main gained examine-31 to examine-54 while this branch was open, so the two scenarios here sit at 55 and 56, and the pointer in `plant_kernel_only_apu_fixtures` follows them. Refs #449, #507 Signed-off-by: Hu Di <812791840@qq.com> --- crates/rocm-core/src/examine/linux_gpus.rs | 7 +++++++ crates/rocm-core/src/gfx_target.rs | 6 ++++++ tests/e2e-cucumber/tests/e2e/examine_steps.rs | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/rocm-core/src/examine/linux_gpus.rs b/crates/rocm-core/src/examine/linux_gpus.rs index 4135b7640e..62a3e5327a 100644 --- a/crates/rocm-core/src/examine/linux_gpus.rs +++ b/crates/rocm-core/src/examine/linux_gpus.rs @@ -905,6 +905,13 @@ mod tests { // 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 \ diff --git a/crates/rocm-core/src/gfx_target.rs b/crates/rocm-core/src/gfx_target.rs index 0c24c6f887..685d8be7df 100644 --- a/crates/rocm-core/src/gfx_target.rs +++ b/crates/rocm-core/src/gfx_target.rs @@ -239,6 +239,12 @@ pub(crate) fn gfx_target_from_amd_pci_device_id(device_id: &str) -> Option<&'sta // [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"), diff --git a/tests/e2e-cucumber/tests/e2e/examine_steps.rs b/tests/e2e-cucumber/tests/e2e/examine_steps.rs index bce7081582..85273ff9fa 100644 --- a/tests/e2e-cucumber/tests/e2e/examine_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/examine_steps.rs @@ -1874,7 +1874,7 @@ async fn kernel_only_apu_machine(world: &mut E2eWorld) { /// 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-29: a +/// 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) {