Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 166 additions & 4 deletions crates/rocm-core/src/examine/linux_gpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
13 changes: 13 additions & 0 deletions crates/rocm-core/src/gfx_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -747,6 +759,7 @@ mod tests {
("164F", "gfx1103"),
("1900", "gfx1103"),
("1114", "gfx1152"),
("1586", "gfx1151"),
// Vega APUs: Renoir, Cezanne, Lucienne, Barcelo.
("1636", "gfx90c"),
("1638", "gfx90c"),
Expand Down
35 changes: 35 additions & 0 deletions tests/e2e-cucumber/features/examine.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading