[PR #3117] [Engine] gpustat: give each Intel card its own VRAM readings #4460

Open
opened 2026-11-07 15:36:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3117
Author: @beyondcr
Created: 10/19/2026
Status: 🔄 Open

Base: main ← Head: pr/gpustat-vram-total


📝 Commits (1)

  • 1e77009 gpustat: read every card, and read each card correctly

📊 Changes

3 files changed (+491 additions, -91 deletions)

View changed files

📝 sycl/serve/xe_telemetry.py (+13 -2)
📝 sycl/tools/gpustat.py (+155 -89)
➕ tools/test_gpustat_vram_total.py (+323 -0)

📄 Description

Problem and result

Two Intel GPUs on one xe host, both behind the chipset's PCIe bridges: an Arc Pro B70 at
0000:0d:00.0, where the engine runs, and an Arc A770 at 0000:11:00.0, driving the desktop.
Resizable BAR is enabled on both, both are visible in lspci, and the engine runs on the B70
through Level Zero, so the hardware side is not in question.

The Monitor's VRAM card read 31.2 of 56.0 GB for the card the engine was on, which has 30.30
GiB usable. The total was almost double the card, and a sample taken with nothing loaded still read
56.0 GB, so it was not transient. Correcting the total alone then made the panel read 105
percent
, which is how the second problem surfaced.

After this change each card reports its own capacity and its own clients, and a card the sampler did
not read reports no memory rather than another card's figures.

#3117 covered the first two readings and was closed by the 0.2.0-beta tracker reset rather than on
review; this is the same problem rebased on main and extended to the rest of it. Issue #2001 is
the mixed NVIDIA/Intel case, where the wrong card is shown; this is two Intel cards and does not
address it.

Approach

The total was a bridge window. /sys/bus/pci/devices/<pci>/resource holds thirteen lines: the
card's six BARs and its ROM at indices 0-6, then the bridge windows the card sits behind at 7-12. A
bridge window is sized for everything behind it and can be far larger than the card, and max()
over every line returned one. On this host, above 1 GiB:

index 0   BAR      0.02 GiB
index 2   BAR     32.00 GiB    BAR2, which maps all of VRAM with resizable BAR
index 7   bridge   0.11 GiB
index 9   bridge  56.00 GiB    what max() returned

Only the card's own BARs describe its memory, so the sizes now come from the first seven lines. The
module already documents the intended value as "the card's largest PCI BAR, which maps all of VRAM
with resizable BAR", and a bridge window is none of those things.

The used figure included the other card. clients() accepted any /dev/dri path in
/proc/*/fdinfo and never looked at drm-pdev, so with two cards fitted the used figure was both
cards summed while the total was one. Measured here before the fix:

B70 (engine)     32161 MiB
A770 (display)    2352 MiB
sampler "used"   34514 MiB   both cards, against a 32768 MiB total

A client now has to name this card in drm-pdev. A client that reports no drm-pdev is still
counted, so a kernel that does not publish it keeps the previous behaviour rather than reporting
nothing.

Every card is sampled, and the reader takes its own entry. find_cards() returns every Intel
GPU on xe, each sampled with its own hwmon directory matched by device path and its own
accumulators, and /proc is scanned once per sample for all of them rather than once per card. The
document keeps one entry per card under cards, keyed by PCI address, and still writes the first
card's fields at the top level, so a reader written before this continues to work.

The reader uses the entry for its own card. It previously applied the flat fields whatever card
wrote them, so on a two-card host one card's capacity and usage were shown for the other. When no
entry belongs to the card being read, it reports nothing for load and VRAM rather than another
card's figures.

The name. card_name() split lspci -mm on a quote-space-quote sequence, which mangled the
device name and swallowed the fields after it. It tokenises the fields now.

GPUSTAT_OUT names the JSON path, so the sampler can be run as a normal user against a scratch file
to check its output without installing it.

Neither the capacity nor the client change is specific to a card model. Both apply to any Intel GPU
whose host fits a second card, which is a property of the platform rather than of the model or the
amount of VRAM.

Compatibility: the JSON keeps its existing keys and the flat top level is unchanged on a single-card
host. No build change; both changed files are Python.

Validation

Passed:

  • Before and after on the same host, same program, at main (e88ee39d) and at this commit: running
    sycl/tools/gpustat.py from main reports vram_total_mb 57344; at this commit it reports
    32768. Both write the same 20 top-level keys, so the change is confined to the values.
  • python3 -m unittest tools.test_gpustat_vram_total, revision 1e770091 on main (e88ee39d),
    Linux 7.2.11, Python 3.14: 18 tests, OK.
  • Each test fails when its fix is removed. Dropping the [:7] slice fails the bridge-window test;
    removing the drm-pdev filter fails the client test; restoring the flat read fails the
    card-matching test; restoring the old lspci split fails the name test; taking the first xe
    hwmon fails the hwmon test.
  • Per-card readings on the same host: 32768 MiB and 16384 MiB for the two cards with different
    package temperatures, and the reader returns each card's own entry on three consecutive samples.
    Busy percent, power and the PCIe link still report.
  • A single-card document, with GPUSTAT_PCI pinning one card, gives that card its entry and the
    other card nothing, rather than lending it the wrong figures.

Failed: none observed.

Not run: no CUDA, HIP, SYCL or Metal build, since the change is Python only and touches no
compiled code. Not run on a single-Intel-GPU host, and not on Windows, where the SYCL serve layer is
not used.

Limits

Every Intel xe card is sampled by default and the document carries one entry per card, so the reader
takes the entry for the card it is reading without any configuration. GPUSTAT_PCI is still there
for a sampler limited to one card; a reader whose card the sampler did not cover reports no load or
VRAM rather than another card's figures.

Load and VRAM stay root-only across users, because another user's /proc/<pid>/fdinfo needs
CAP_SYS_PTRACE; the existing install notes already say so.

Notes

  • serve/telemetry.py is untouched. The sampler's document keeps its existing keys and gains one
    cards map; the flat top level still describes the first card.
  • Busy percent becomes per-card as a side effect of the client filter, which is what it should have
    been.
  • The total remains the card's largest BAR rather than usable VRAM, so it rounds up to the next
    power of two: 32 GiB for 30.30 GiB usable, 16 GiB for 15.11 GiB. That is the module's documented
    intent and this change does not alter it. GPUSTAT_VRAM_MB still overrides everything.
  • #2001 is the mixed NVIDIA/Intel case; this is two Intel cards and does not address it.
  • Written with AI assistance, then measured and reviewed by hand on the hardware above. Every
    number here was checked against the source or against command output, and I can explain every
    changed line. Both cards are fitted here, so further checks can be run on request.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3117 **Author:** [@beyondcr](https://github.com/beyondcr) **Created:** 10/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/gpustat-vram-total` --- ### 📝 Commits (1) - [`1e77009`](https://github.com/Niko1221/Strata/commit/1e7700918573f7ee7f28ed41890aeca36add8b29) gpustat: read every card, and read each card correctly ### 📊 Changes **3 files changed** (+491 additions, -91 deletions) <details> <summary>View changed files</summary> 📝 `sycl/serve/xe_telemetry.py` (+13 -2) 📝 `sycl/tools/gpustat.py` (+155 -89) ➕ `tools/test_gpustat_vram_total.py` (+323 -0) </details> ### 📄 Description ## Problem and result Two Intel GPUs on one xe host, both behind the chipset's PCIe bridges: an Arc Pro B70 at `0000:0d:00.0`, where the engine runs, and an Arc A770 at `0000:11:00.0`, driving the desktop. Resizable BAR is enabled on both, both are visible in `lspci`, and the engine runs on the B70 through Level Zero, so the hardware side is not in question. The Monitor's VRAM card read **31.2 of 56.0 GB** for the card the engine was on, which has 30.30 GiB usable. The total was almost double the card, and a sample taken with nothing loaded still read 56.0 GB, so it was not transient. Correcting the total alone then made the panel read **105 percent**, which is how the second problem surfaced. After this change each card reports its own capacity and its own clients, and a card the sampler did not read reports no memory rather than another card's figures. ## Related discussion #3117 covered the first two readings and was closed by the 0.2.0-beta tracker reset rather than on review; this is the same problem rebased on `main` and extended to the rest of it. Issue #2001 is the mixed NVIDIA/Intel case, where the wrong card is shown; this is two Intel cards and does not address it. ## Approach **The total was a bridge window.** `/sys/bus/pci/devices/<pci>/resource` holds thirteen lines: the card's six BARs and its ROM at indices 0-6, then the bridge windows the card sits behind at 7-12. A bridge window is sized for everything behind it and can be far larger than the card, and `max()` over every line returned one. On this host, above 1 GiB: ``` index 0 BAR 0.02 GiB index 2 BAR 32.00 GiB BAR2, which maps all of VRAM with resizable BAR index 7 bridge 0.11 GiB index 9 bridge 56.00 GiB what max() returned ``` Only the card's own BARs describe its memory, so the sizes now come from the first seven lines. The module already documents the intended value as "the card's largest PCI BAR, which maps all of VRAM with resizable BAR", and a bridge window is none of those things. **The used figure included the other card.** `clients()` accepted any `/dev/dri` path in `/proc/*/fdinfo` and never looked at `drm-pdev`, so with two cards fitted the used figure was both cards summed while the total was one. Measured here before the fix: ``` B70 (engine) 32161 MiB A770 (display) 2352 MiB sampler "used" 34514 MiB both cards, against a 32768 MiB total ``` A client now has to name this card in `drm-pdev`. A client that reports no `drm-pdev` is still counted, so a kernel that does not publish it keeps the previous behaviour rather than reporting nothing. **Every card is sampled, and the reader takes its own entry.** `find_cards()` returns every Intel GPU on xe, each sampled with its own hwmon directory matched by device path and its own accumulators, and `/proc` is scanned once per sample for all of them rather than once per card. The document keeps one entry per card under `cards`, keyed by PCI address, and still writes the first card's fields at the top level, so a reader written before this continues to work. The reader uses the entry for its own card. It previously applied the flat fields whatever card wrote them, so on a two-card host one card's capacity and usage were shown for the other. When no entry belongs to the card being read, it reports nothing for load and VRAM rather than another card's figures. **The name.** `card_name()` split `lspci -mm` on a quote-space-quote sequence, which mangled the device name and swallowed the fields after it. It tokenises the fields now. `GPUSTAT_OUT` names the JSON path, so the sampler can be run as a normal user against a scratch file to check its output without installing it. Neither the capacity nor the client change is specific to a card model. Both apply to any Intel GPU whose host fits a second card, which is a property of the platform rather than of the model or the amount of VRAM. Compatibility: the JSON keeps its existing keys and the flat top level is unchanged on a single-card host. No build change; both changed files are Python. ## Validation **Passed:** - Before and after on the same host, same program, at `main` (e88ee39d) and at this commit: running `sycl/tools/gpustat.py` from `main` reports `vram_total_mb` **57344**; at this commit it reports **32768**. Both write the same 20 top-level keys, so the change is confined to the values. - `python3 -m unittest tools.test_gpustat_vram_total`, revision 1e770091 on `main` (e88ee39d), Linux 7.2.11, Python 3.14: 18 tests, OK. - Each test fails when its fix is removed. Dropping the `[:7]` slice fails the bridge-window test; removing the `drm-pdev` filter fails the client test; restoring the flat read fails the card-matching test; restoring the old `lspci` split fails the name test; taking the first `xe` hwmon fails the hwmon test. - Per-card readings on the same host: 32768 MiB and 16384 MiB for the two cards with different package temperatures, and the reader returns each card's own entry on three consecutive samples. Busy percent, power and the PCIe link still report. - A single-card document, with `GPUSTAT_PCI` pinning one card, gives that card its entry and the other card nothing, rather than lending it the wrong figures. **Failed:** none observed. **Not run:** no CUDA, HIP, SYCL or Metal build, since the change is Python only and touches no compiled code. Not run on a single-Intel-GPU host, and not on Windows, where the SYCL serve layer is not used. ## Limits Every Intel xe card is sampled by default and the document carries one entry per card, so the reader takes the entry for the card it is reading without any configuration. `GPUSTAT_PCI` is still there for a sampler limited to one card; a reader whose card the sampler did not cover reports no load or VRAM rather than another card's figures. Load and VRAM stay root-only across users, because another user's `/proc/<pid>/fdinfo` needs `CAP_SYS_PTRACE`; the existing install notes already say so. ## Notes - `serve/telemetry.py` is untouched. The sampler's document keeps its existing keys and gains one `cards` map; the flat top level still describes the first card. - Busy percent becomes per-card as a side effect of the client filter, which is what it should have been. - The total remains the card's largest BAR rather than usable VRAM, so it rounds up to the next power of two: 32 GiB for 30.30 GiB usable, 16 GiB for 15.11 GiB. That is the module's documented intent and this change does not alter it. `GPUSTAT_VRAM_MB` still overrides everything. - `#2001` is the mixed NVIDIA/Intel case; this is two Intel cards and does not address it. - Written with AI assistance, then measured and reviewed by hand on the hardware above. Every number here was checked against the source or against command output, and I can explain every changed line. Both cards are fitted here, so further checks can be run on request. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4460
No description provided.