Skip to content

A GPU task manager for Windows, Linux, and WSL: per-process VRAM, GPU activity, and LLM model/KV-cache insights (Windows AMD and NVIDIA).

Python

Release v0.3.1

Scott Hanselman2e8b447e0d03
diff --git a/pyproject.toml b/pyproject.toml
index 394363d..7f653e3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "gputaskman"
-version = "0.3.0"
+version = "0.3.1"
description = "An htop for what's inside your GPU: per-process VRAM, engine load, and LLM weights / KV cache breakdown"
readme = "README.md"
license = "MIT"
diff --git a/src/gputaskman/drm.py b/src/gputaskman/drm.py
index 261ec55..e18d9d2 100644
--- a/src/gputaskman/drm.py
+++ b/src/gputaskman/drm.py
@@ -104,13 +104,14 @@ def parse_fdinfo(text: str) -> dict | None:
return parse_size(fields.get(resident, fields.get(legacy)))
# drm-shared-<region> counts buffers with more than one handle by their *preferred* region, resident or not,
- # while drm-resident-<region> counts by where buffers are now, so the two can't be subtracted. The total is
- # still exact evidence of whether this client shares any buffer at all. None when a region is missing
- # (older amdgpu, before the generic DRM memory stats) or unparseable: unknown, not 0.
- shared_keys = [k for k in ("drm-shared-vram", "drm-shared-gtt") if k in fields]
+ # while drm-resident-<region> counts by where buffers are now, so the two can't be subtracted. A shared
+ # system-memory buffer can therefore be resident in GTT. Count every reported shared region, including CPU;
+ # missing or unparseable standard regions mean unknown, not 0.
+ required_shared_keys = ("drm-shared-vram", "drm-shared-gtt", "drm-shared-cpu")
+ shared_keys = [k for k in fields if k.startswith("drm-shared-")]
shared_values = [parse_size(fields[k]) for k in shared_keys]
- # Only VRAM and GTT matter here: drm-shared-cpu counts system-memory buffers this tool doesn't charge.
- shared = sum(shared_values) if len(shared_keys) == 2 and None not in shared_values else None
+ shared = (sum(shared_values) if all(k in fields for k in required_shared_keys)
+ and shared_keys and None not in shared_values else None)
engines: dict[str, int] | None = {}
for key, value in fields.items():
@@ -393,7 +394,7 @@ _DEFERRED = object() # _scan_pid: the scan budget ran out partway through this
_PRUNE_NS = 60 * 1_000_000_000 # forget engine baselines for clients not seen for a minute
# Why a row's DRM memory is n/a instead of measured (ProcGpu.drm_reason)
-REASON_LEGACY = "legacy" # older amdgpu: no drm-shared-vram/gtt, so private and shared bytes can't be told apart
+REASON_LEGACY = "legacy" # missing or unparseable shared stats: private and shared bytes can't be told apart
REASON_SHARED_CLIENT = "shared_client" # one DRM client held by several processes (fd passing, fork)
REASON_SHARED_BUFFERS = "shared_buffers" # the client holds buffers shared with other clients (dma-buf)
REASON_PRIMARY = "primary" # opened via /dev/dri/card*, whose root-held copies (logind) a normal user can't see
diff --git a/src/gputaskman/report.py b/src/gputaskman/report.py
index 8deae02..f0f0062 100644
--- a/src/gputaskman/report.py
+++ b/src/gputaskman/report.py
@@ -59,8 +59,8 @@ ORDER_NOTE = ("? order guess: the size is exact but several owners fit, so newer
DRM_NOTES = {
- "legacy": ("VRAM n/a: this kernel's amdgpu fdinfo has no drm-shared-* keys, so resident memory may include "
- "buffers imported from other processes and would be counted once per importer."),
+ "legacy": ("VRAM n/a: this kernel's amdgpu fdinfo has incomplete or unparseable drm-shared-* stats, so resident "
+ "memory may include buffers imported from other processes and would be counted once per importer."),
"shared_client": ("VRAM and GPU% n/a: this process holds a DRM client other processes hold too (fd passing, "
"fork). fdinfo counts the client once and doesn't say which of them uses it."),
"shared_buffers": ("VRAM n/a: this process's DRM client shares buffers with other clients (dma-buf, e.g. "
diff --git a/tests/test_drm.py b/tests/test_drm.py
index 1a4baaa..987eff8 100644
--- a/tests/test_drm.py
+++ b/tests/test_drm.py
@@ -79,7 +79,7 @@ def _write_fd(proc: Path, pid, fd, text, target="/dev/dri/renderD128") -> None:
os.symlink(target, link)
-def _fdinfo(client, pdev, gfx=0, vram=0, gtt=0, shared_vram=0, shared_gtt=0) -> str:
+def _fdinfo(client, pdev, gfx=0, vram=0, gtt=0, shared_vram=0, shared_gtt=0, shared_cpu=0) -> str:
return (
"pos:\t0\n"
"drm-driver:\tamdgpu\n"
@@ -89,7 +89,7 @@ def _fdinfo(client, pdev, gfx=0, vram=0, gtt=0, shared_vram=0, shared_gtt=0) ->
f"drm-resident-vram:\t{vram} KiB\n"
f"drm-shared-gtt:\t{shared_gtt} KiB\n"
f"drm-resident-gtt:\t{gtt} KiB\n"
- "drm-shared-cpu:\t0\n"
+ f"drm-shared-cpu:\t{shared_cpu} KiB\n"
"drm-resident-cpu:\t0\n"
f"drm-engine-gfx:\t{gfx} ns\n"
f"drm-engine-capacity-gfx:\t1\n"
@@ -153,21 +153,23 @@ class ParseTests(unittest.TestCase):
def test_parse_fdinfo_prefers_resident_keys(self):
info = drm.parse_fdinfo("drm-driver:\tamdgpu\ndrm-resident-vram:\t8 KiB\ndrm-memory-vram:\t9 KiB\n"
- "drm-shared-vram:\t0\ndrm-shared-gtt:\t4 KiB\n")
+ "drm-shared-vram:\t0\ndrm-shared-gtt:\t4 KiB\ndrm-shared-cpu:\t0\n")
self.assertEqual(info["vram"], 8 * 1024)
self.assertEqual(info["shared"], 4 * 1024)
- def test_parse_fdinfo_shared_needs_vram_and_gtt(self):
+ def test_parse_fdinfo_shared_needs_all_memory_regions(self):
info = drm.parse_fdinfo("drm-driver:\tamdgpu\ndrm-memory-vram:\t300 MiB\ndrm-shared-vram:\t0\n")
self.assertIsNone(info["shared"]) # no drm-shared-gtt: whether GTT buffers are shared is unknown
+ info = drm.parse_fdinfo("drm-driver:\tamdgpu\ndrm-shared-vram:\t0\ndrm-shared-gtt:\t0\n")
+ self.assertIsNone(info["shared"]) # no drm-shared-cpu: a shared CPU-preferred buffer may be resident in GTT
- def test_parse_fdinfo_shared_cpu_is_ignored(self):
+ def test_parse_fdinfo_shared_cpu_counts_toward_private_gate(self):
info = drm.parse_fdinfo("drm-driver:\tamdgpu\ndrm-shared-vram:\t0\ndrm-shared-gtt:\t0\n"
"drm-shared-cpu:\t64 KiB\n")
- self.assertEqual(info["shared"], 0) # a shared system-memory buffer doesn't make VRAM/GTT unprivate
+ self.assertEqual(info["shared"], 64 * 1024)
info = drm.parse_fdinfo("drm-driver:\tamdgpu\ndrm-shared-vram:\t0\ndrm-shared-gtt:\t0\n"
"drm-shared-cpu:\tlots\n")
- self.assertEqual(info["shared"], 0)
+ self.assertIsNone(info["shared"])
def test_parse_fdinfo_unparseable_is_unknown(self):
info = drm.parse_fdinfo("drm-driver:\tamdgpu\ndrm-resident-vram:\tlots\ndrm-shared-vram:\t0\n"
@@ -394,7 +396,7 @@ class DrmEdgeCaseTests(unittest.TestCase):
def test_any_shared_buffer_leaves_the_process_unattributed(self):
# drm-shared-* counts by preferred placement and drm-resident-* by current placement, so resident minus
# shared is not this process's private memory. Any sharing at all: n/a, never a subtraction.
- for extra in ({"shared_vram": 2}, {"shared_gtt": 4}):
+ for extra in ({"shared_vram": 2}, {"shared_gtt": 4}, {"shared_cpu": 6}):
with self.subTest(extra), tempfile.TemporaryDirectory() as tmp:
card, _, counters = self._counters(Path(tmp), [(100, 5, _fdinfo(7, "PDEV", vram=3, gtt=10, **extra))])
g = counters.sample()[0][card.key][100]
diff --git a/uv.lock b/uv.lock
index 25c8279..c1efe2e 100644
--- a/uv.lock
+++ b/uv.lock
@@ -13,7 +13,7 @@ wheels = [
[[package]]
name = "gputaskman"
-version = "0.3.0"
+version = "0.3.1"
source = { editable = "." }
dependencies = [
{ name = "nvidia-ml-py" },