Skip to content
Merged
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
7 changes: 4 additions & 3 deletions crates/rocm-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ workspace = true
e2e-test-hooks = []
# Compiles test helpers so a dependent crate's tests can use them: the
# `foreign_temp_probe` probe, `atomic_write::stage_owner_only_file_unpublished`
# (the leftover a killed owner-only store leaves) and, on Windows,
# `owner_only_file::owner_only_dacl_mismatch` (reads a file's DACL back).
# Enabled only from a `[dev-dependencies]` entry; never in a shipped build.
# (the leftover a killed owner-only store leaves), the examine scenarios'
# planted `lspci` lines (`rocm_core::examine::TEST_FIXTURE_LSPCI_LINE_*`) and,
# on Windows, `owner_only_file::owner_only_dacl_mismatch` (reads a file's DACL
# back). Enabled only from a `[dev-dependencies]` entry; never in a shipped build.
test-support = []

[build-dependencies]
Expand Down
15 changes: 12 additions & 3 deletions crates/rocm-core/src/examine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ pub(crate) use host_env::{probe_cpu_windows_with, record_cpu};
pub(crate) use library_copies::comgr_matches_runtime;
use library_copies::probe_comgr;
use linux_driver::{probe_devices, probe_modules, probe_secure_boot, probe_user};
pub use linux_gpus::gfx_is_apu_family;
use linux_gpus::{
GpuProbeSources, probe_gpus_after_lspci, probe_gpus_lspci, summarise_gpu_categories,
};
pub use linux_gpus::{KERNEL_TOPOLOGY_GPU_NAME, gfx_is_apu_family};
#[cfg(any(test, feature = "test-support"))]
pub use linux_gpus::{
TEST_FIXTURE_LSPCI_LINE_NAME_TABLE_READS_AS_GFX1103,
TEST_FIXTURE_LSPCI_LINE_NAME_TABLE_READS_AS_NOTHING,
};
use rocm_install_probe::probe_rocm_install;
pub(crate) use windows::parse_dotted_version;
use windows::{
Expand All @@ -54,8 +59,12 @@ use windows::{
use wsl::probe_wsl;
pub use wsl::{parse_wsl_distro_list, probe_wsl_distro_from_host};

/// A single GPU as enumerated by `lspci`/`rocminfo` (Linux) or the display
/// inventory (Windows).
/// A single GPU, as the examination enumerated it.
///
/// On Linux from `lspci`, the kernel's KFD topology (or its sysfs fallback)
/// and `rocminfo`; on Windows from the display inventory. `is_apu` is `None`
/// when nothing said which package it is; see `examine::linux_gpus`'s
/// `apu_verdict_from_target` for the Linux rules.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct Gpu {
pub name: String,
Expand Down
1,867 changes: 1,770 additions & 97 deletions crates/rocm-core/src/examine/linux_gpus.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/rocm-core/src/host_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use linux::detect_linux_amdgpu_driver_version;
use linux::detect_linux_primary_gpu_name;
pub(crate) use linux::detect_linux_sysfs_gfx_target;
pub use linux::is_amdgpu_device;
pub(crate) use linux::pci_bus_device_function;
#[cfg(any(target_os = "linux", test))]
pub(crate) use linux::{KfdGpuNode, kfd_gpu_nodes_in};
pub(crate) use windows_inventory::detect_windows_amd_driver_info;
Expand Down
58 changes: 50 additions & 8 deletions crates/rocm-core/src/host_gpu/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,49 @@ pub(crate) fn kfd_gpu_nodes_in(nodes_dir: &Path) -> Option<Vec<KfdGpuNode>> {
/// 12032, 17920, 23808, 35584, 43520, 49664 and 55808, which decode to exactly
/// the eight addresses `lspci -D` lists for its accelerators (EAI-8449).
///
/// `None` when the property is absent or zero. Zero is refused rather than
/// `None` when the property is absent, zero, or wider than 16 bits (which
/// `pci_dev_id()` cannot produce; see [`pci_bus_device_function`]). Zero is
/// refused rather than
/// decoded: `0000:00:00.0` is the host bridge, so emitting it would be a
/// wrong-but-plausible address that could match an unrelated PCI entry.
#[cfg(any(target_os = "linux", test))]
fn kfd_node_pci_id(properties: &str) -> Option<String> {
let location = kfd_property_value(properties, "location_id")?
.parse::<u32>()
.ok()?;
if location == 0 {
return None;
}
let domain = kfd_property_value(properties, "domain")
.and_then(|value| value.parse::<u32>().ok())
.unwrap_or(0);
let bus = (location >> 8) & 0xff;
let device = (location >> 3) & 0x1f;
let function = location & 0x7;
Some(format!("{domain:04x}:{bus:02x}:{device:02x}.{function}"))
let bdf = pci_bus_device_function(location)?;
Some(format!("{domain:04x}:{bdf}"))
}

/// The `bus:device.function` part of a PCI address, spelled as `lspci` spells
/// it, from the kernel's `pci_dev_id()` encoding: `(bus << 8) | devfn`, with
/// `devfn` packing the device number in bits 3..8 and the function in bits
/// 0..3. So `4352` (`0x1100`) is `11:00.0`.
///
/// Two readings carry an address in this encoding, and both decode through
/// here so they cannot disagree about a card: the KFD topology's `location_id`
/// (`kfd_node_pci_id`, which adds the `domain` property in front) and
/// `rocminfo`'s per-agent `BDFID`, which has no domain at all
/// (`examine::linux_gpus`, which matches each `rocminfo` agent onto the GPU
/// with this address).
///
/// `None` for zero, for the reason `kfd_node_pci_id` gives: `00:00.0` is the
/// host bridge, and `rocminfo` prints `BDFID: 0` for its CPU agents, so a zero
/// is "no address" rather than an address that could match an unrelated entry.
/// `None` above `0xffff` too, which the encoding cannot produce.
pub(crate) fn pci_bus_device_function(dev_id: u32) -> Option<String> {
// Above 16 bits is no `pci_dev_id()`: decoding only the low 16 would turn
// it into an address that could belong to another card.
if dev_id == 0 || dev_id > 0xffff {
return None;
}
let bus = (dev_id >> 8) & 0xff;
let device = (dev_id >> 3) & 0x1f;
let function = dev_id & 0x7;
Some(format!("{bus:02x}:{device:02x}.{function}"))
}

/// The KFD-topology read, against a caller-supplied nodes directory.
Expand Down Expand Up @@ -694,6 +719,23 @@ mod tests {
assert_eq!(kfd_node_pci_id("gfx_target_version 90402\n"), None);
}

#[test]
fn a_dev_id_decodes_every_function_bit_and_refuses_zero_and_wider_values() {
// The decode both the KFD topology and `rocminfo`'s `BDFID` go through,
// pinned to literal addresses: a test that only compares the two sides
// stays green when the shared decode is wrong on both. Functions 5 and
// 7 use the function's high bit, which a two-bit mask would drop.
assert_eq!(pci_bus_device_function(0x1c7).as_deref(), Some("01:18.7"));
assert_eq!(pci_bus_device_function(0x305).as_deref(), Some("03:00.5"));
assert_eq!(pci_bus_device_function(49_920).as_deref(), Some("c3:00.0"));
assert_eq!(pci_bus_device_function(0xfffe).as_deref(), Some("ff:1f.6"));
assert_eq!(pci_bus_device_function(0), None);
// Past 16 bits is not this encoding; its low 16 bits (0x0300, a real
// card's address) must not be read as one.
assert_eq!(pci_bus_device_function(0x1_0300), None);
assert_eq!(pci_bus_device_function(0xffff).as_deref(), Some("ff:1f.7"));
}

#[test]
fn kfd_properties_win_over_a_standalone_file() -> Result<()> {
// Both present: `properties` is what the kernel maintains, so it decides.
Expand Down
257 changes: 257 additions & 0 deletions crates/rocm-core/tests/fixtures/rocminfo_gfx1151_apu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
ROCk module is loaded
=====================
HSA System Attributes
=====================
Runtime Version: 1.21
Runtime Ext Version: 1.32
System Timestamp Freq.: 1000.000000MHz
Sig. Max Wait Duration: 18446744073709551615 (0xFFFFFFFFFFFFFFFF) (timestamp count)
Machine Model: LARGE
System Endianness: LITTLE
Mwaitx: ENABLED
XNACK enabled: NO
DMAbuf Support: YES
VMM Support: YES
Fabric Support: NO

==========
HSA Agents
==========
*******
Agent 1
*******
Name: AMD RYZEN AI MAX+ PRO 395 w/ Radeon 8060S
Uuid: CPU-XX
Marketing Name: AMD RYZEN AI MAX+ PRO 395 w/ Radeon 8060S
Vendor Name: CPU
Feature: None specified
Profile: FULL_PROFILE
Float Round Mode: NEAR
Max Queue Number: 0(0x0)
Queue Min Size: 0(0x0)
Queue Max Size: 0(0x0)
Queue Type: MULTI
Node: 0
Device Type: CPU
Cache Info:
L1: 49152(0xc000) KB
Chip ID: 0(0x0)
ASIC Revision: 0(0x0)
Cacheline Size: 64(0x40)
Max Clock Freq. (MHz): 5187
BDFID: 0
Internal Node ID: 0
Compute Unit: 32
SIMDs per CU: 0
Shader Engines: 0
Shader Arrs. per Eng.: 0
WatchPts on Addr. Ranges:1
Memory Properties:
Features: None
Pool Info:
Pool 1
Segment: GLOBAL; FLAGS: FINE GRAINED
Size: 98634044 (0x5e1093c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:4KB
Alloc Alignment: 4KB
Accessible by all: TRUE
Pool 2
Segment: GLOBAL; FLAGS: EXTENDED FINE GRAINED
Size: 98634044 (0x5e1093c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:4KB
Alloc Alignment: 4KB
Accessible by all: TRUE
Pool 3
Segment: GLOBAL; FLAGS: KERNARG, FINE GRAINED
Size: 98634044 (0x5e1093c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:4KB
Alloc Alignment: 4KB
Accessible by all: TRUE
Pool 4
Segment: GLOBAL; FLAGS: COARSE GRAINED
Size: 98634044 (0x5e1093c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:4KB
Alloc Alignment: 4KB
Accessible by all: TRUE
ISA Info:
*******
Agent 2
*******
Name: gfx1151
Uuid: GPU-XX
Marketing Name: AMD Radeon 8060S Graphics
Vendor Name: AMD
Feature: KERNEL_DISPATCH
Profile: BASE_PROFILE
Float Round Mode: NEAR
Max Queue Number: 128(0x80)
Queue Min Size: 64(0x40)
Queue Max Size: 131072(0x20000)
Queue Type: MULTI
Node: 1
Device Type: GPU
Cache Info:
L1: 32(0x20) KB
L2: 2048(0x800) KB
L3: 32768(0x8000) KB
Chip ID: 5510(0x1586)
ASIC Revision: 0(0x0)
Cacheline Size: 128(0x80)
Max Clock Freq. (MHz): 2900
BDFID: 49920
Internal Node ID: 1
Compute Unit: 40
SIMDs per CU: 2
Shader Engines: 2
Shader Arrs. per Eng.: 2
WatchPts on Addr. Ranges:4
Coherent Host Access: FALSE
Memory Properties: APU
Features: KERNEL_DISPATCH
Fast F16 Operation: TRUE
Wavefront Size: 32(0x20)
Workgroup Max Size: 1024(0x400)
Workgroup Max Size per Dimension:
x 1024(0x400)
y 1024(0x400)
z 1024(0x400)
Max Waves Per CU: 32(0x20)
Max Work-item Per CU: 1024(0x400)
Grid Max Size: 2147483647(0x7fffffff)
Grid Max Size per Dimension:
x 2147483647(0x7fffffff)
y 65535(0xffff)
z 65535(0xffff)
Max fbarriers/Workgrp: 32
Packet Processor uCode:: 34
SDMA engine uCode:: 18
IOMMU Support:: None
Pool Info:
Pool 1
Segment: GLOBAL; FLAGS: COARSE GRAINED
Size: 49317020 (0x2f0849c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:2048KB
Alloc Alignment: 4KB
Accessible by all: FALSE
Pool 2
Segment: GLOBAL; FLAGS: EXTENDED FINE GRAINED
Size: 49317020 (0x2f0849c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:2048KB
Alloc Alignment: 4KB
Accessible by all: FALSE
Pool 3
Segment: GROUP
Size: 64 (0x40) KB
Allocatable: FALSE
Alloc Granule: 0KB
Alloc Recommended Granule:0KB
Alloc Alignment: 0KB
Accessible by all: FALSE
ISA Info:
ISA 1
Name: amdgcn-amd-amdhsa--gfx1151
Machine Models: HSA_MACHINE_MODEL_LARGE
Profiles: HSA_PROFILE_BASE
Default Rounding Mode: NEAR
Default Rounding Mode: NEAR
Fast f16: TRUE
Workgroup Max Size: 1024(0x400)
Workgroup Max Size per Dimension:
x 1024(0x400)
y 1024(0x400)
z 1024(0x400)
Grid Max Size: 18446744073709551615 (0xffffffffffffffff)
Grid Max Size per Dimension:
x 2147483647(0x7fffffff)
y 65535(0xffff)
z 65535(0xffff)
FBarrier Max Size: 32
ISA 2
Name: amdgcn-amd-amdhsa--gfx11-generic
Machine Models: HSA_MACHINE_MODEL_LARGE
Profiles: HSA_PROFILE_BASE
Default Rounding Mode: NEAR
Default Rounding Mode: NEAR
Fast f16: TRUE
Workgroup Max Size: 1024(0x400)
Workgroup Max Size per Dimension:
x 1024(0x400)
y 1024(0x400)
z 1024(0x400)
Grid Max Size: 18446744073709551615 (0xffffffffffffffff)
Grid Max Size per Dimension:
x 2147483647(0x7fffffff)
y 65535(0xffff)
z 65535(0xffff)
FBarrier Max Size: 32
*******
Agent 3
*******
Name: aie2p
Uuid: AIE-XX
Marketing Name: RyzenAI-npu5
Vendor Name: AMD
Feature: AGENT_DISPATCH
Profile: BASE_PROFILE
Float Round Mode: NEAR
Max Queue Number: 1(0x1)
Queue Min Size: 64(0x40)
Queue Max Size: 64(0x40)
Queue Type: SINGLE
Node: 0
Device Type: DSP
Cache Info:
L2: 2048(0x800) KB
L3: 32768(0x8000) KB
Chip ID: 0(0x0)
ASIC Revision: 0(0x0)
Cacheline Size: 0(0x0)
Max Clock Freq. (MHz): 0
BDFID: 0
Internal Node ID: 0
Compute Unit: 0
SIMDs per CU: 0
Shader Engines: 0
Shader Arrs. per Eng.: 0
WatchPts on Addr. Ranges:0
Memory Properties:
Features: AGENT_DISPATCH
Pool Info:
Pool 1
Segment: GLOBAL; FLAGS: KERNARG, COARSE GRAINED
Size: 98634044 (0x5e1093c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:4KB
Alloc Alignment: 4KB
Accessible by all: TRUE
Pool 2
Segment: GLOBAL; FLAGS: COARSE GRAINED
Size: 65536 (0x10000) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:0KB
Alloc Alignment: 4KB
Accessible by all: TRUE
Pool 3
Segment: GLOBAL; FLAGS: COARSE GRAINED
Size: 98634044 (0x5e1093c) KB
Allocatable: TRUE
Alloc Granule: 4KB
Alloc Recommended Granule:4KB
Alloc Alignment: 4KB
Accessible by all: TRUE
ISA Info:
*** Done ***
Loading
Loading