serve telemetry: each card's PCIe link and traffic in "gpus"; the machine's link is the narrowest card's

The app's Monitor takes each GPU tile from that card's own record. "gpus" carried
util, VRAM, temperature and power only, so the tile's PCIe readings (link generation,
width, MB/s) had nothing to show on a two-card PC: the tiles showed "-" and the
caption fell back to the transfer totals. The machine-wide gpu_pcie_gen,
gpu_pcie_gen_max and gpu_pcie_width were the first card's reading, so a Gen4 card in
a Gen3 slot or a x8 card beside a x16 one made the whole machine read high.

Both cards of this PC (RTX 4060 Ti + RTX 4070 SUPER) now report their own Gen3 x8
link and their own rx/tx MB/s.
This commit is contained in:
lamboJw authored and Niko1221 committed 2026-11-16 15:28:38 +01:00
1 parent 4aaec72f88
commit f5c07ddfd9
2 files changed
+31 -2

No files matched your search

+14 -2
View File
@@ -537,7 +537,8 @@ class Telemetry:
"""`extra()` -> dict of more series to record each second (the server's tok/s). `gpu_index`: the card the
engine runs on, numbered as nvidia-smi and NVML number them (by PCI bus); `gpu_indices`: all of them when
the model is split across several (issue #112) - the gpu_* readings are then their total (memory, power,
PCIe traffic), mean (load) or hottest (temperature), and "gpus" has each card's own. `amd`: the AMD backend's
PCIe traffic), mean (load), narrowest (a card's PCIe link, which no machine can be faster than) or hottest
(temperature), and "gpus" has each card's own readings, its link included. `amd`: the AMD backend's
cards, numbered as HIP numbers them, read from sysfs (#301)."""
self.extra = extra
self.lock = threading.Lock()
@@ -619,8 +620,19 @@ class Telemetry:
g["util"] = sum(u) / len(u) if u else None
t = vals("temp")
g["temp"] = max(t) if t else None
# a link is not a sum: the machine is only as fast as its narrowest card, so the gpu_* link figures
# report the narrowest one (they used to be the first card's, which read high when a Gen4 card was
# put in a Gen3 slot, or a x8 card next to a x16 one)
for k in ("pcie_gen", "pcie_gen_max", "pcie_width"):
v = vals(k)
g[k] = min(v) if v else None
# each card's own link and traffic, the way the gpu_* totals have them: "gpus" carried util, VRAM,
# temperature and power only, so the app's per-GPU PCIe tiles had nothing to read on a two-card PC
s["gpus"] = [{"index": i, "name": reader.name(), "util": r.get("util"), "mem_used": r.get("mem_used"),
"mem_total": r.get("mem_total"), "temp": r.get("temp"), "power": r.get("power")}
"mem_total": r.get("mem_total"), "temp": r.get("temp"), "power": r.get("power"),
"pcie_gen": r.get("pcie_gen"), "pcie_gen_max": r.get("pcie_gen_max"),
"pcie_width": r.get("pcie_width"), "pcie_rx_mb": r.get("pcie_rx_mb"),
"pcie_tx_mb": r.get("pcie_tx_mb")}
for (i, r), (_, reader) in zip(reads, self.gpus)]
s.update({f"gpu_{k}": v for k, v in g.items()})
if self.ps:
+17
View File
@@ -5337,6 +5337,23 @@ class AmdTelemetry(unittest.TestCase):
self.assertFalse(telemetry.gpu_reader(0, amd=True).ok())
self.assertIsNone(telemetry.free_vram_mib(0, amd=True))
def test_each_card_has_its_own_link_in_gpus(self):
"""The app reads each GPU tile from that card's record: "gpus" had no PCIe keys, so every PCIe tile in the
Monitor was empty on a two-card PC. The machine's gpu_* link figures are its narrowest card's, not the
first card's (a Gen4 card in a Gen3 slot beside a x16 one used to make the whole machine read Gen4 x16)."""
from serve import telemetry
with tempfile.TemporaryDirectory() as d:
self.tree(d)
for minor, speed, width in (("129", "16.0 GT/s PCIe", "16"), ("128", "8.0 GT/s PCIe", "8")):
dev = Path(d) / f"class/drm/renderD{minor}/device"
(dev / "current_link_speed").write_text(speed + "\n")
(dev / "current_link_width").write_text(width + "\n")
with mock.patch.object(telemetry, "SYSFS", d):
s = telemetry.Telemetry(gpu_index=0, gpu_indices=[0, 1], amd=True).sample()
self.assertEqual([(g["index"], g["pcie_gen"], g["pcie_gen_max"], g["pcie_width"]) for g in s["gpus"]],
[(0, 4, 4, 16), (1, 3, 3, 8)])
self.assertEqual((s["gpu_pcie_gen"], s["gpu_pcie_gen_max"], s["gpu_pcie_width"]), (3, 3, 8))
def test_free_vram_on_hip(self):
from serve import telemetry
tok = ByteTokenizer()