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

Fall back to the CPU package temperature on Intel without a GPU sensor

Martin Pluskala0d181fdb380
diff --git a/README.md b/README.md
index e2f1083..b07dd9a 100644
--- a/README.md
+++ b/README.md
@@ -245,7 +245,7 @@ covered by unit tests only and **not yet validated on AMD hardware**.
| | Source |
|---|---|
-| Device temperature, power, GT clock | `hwmon` and `gt/gt0` under `/sys/class/drm/card*`. Power is the rate of the cumulative energy counter between two refreshes, so it is `n/a` on the first |
+| Device temperature, power, GT clock | `hwmon` and `gt/gt0` under `/sys/class/drm/card*`. Power is the rate of the cumulative energy counter between two refreshes, so it is `n/a` on the first. Without a GPU temperature sensor (an integrated GPU has no `hwmon` of its own), the temperature falls back to the CPU package sensor (`coretemp`), labelled as shared with the CPU |
| Device VRAM total | The size of the local-memory PCI window (`resource2`), an **estimate**: kernel-owned memory is missing from the sysfs view, resizable BAR rounds to a power of two, and a partial window can be smaller than the card, so the total can differ from the card's memory. A window under 1 GiB (an integrated GPU, or a discrete card without resizable BAR) shows `N/A` (`null` in JSON). Free memory is never shown for Intel |
| Device VRAM used | The sum of its clients' resident local memory: i915 has no device-wide counter, so buffers shared between processes can be counted twice, and kernel-owned memory and processes gputaskman can't inspect are missing. The UI, `--once`, `--json` (`memory_note`) and `gputaskman diff` all say so. `n/a` when any client's local memory is unknown |
| Integrated or discrete | An iGPU has no `local0`, so a card with a local-memory window of 1 GiB or more is discrete, and so is any card whose fdinfo reports local memory, even when its window is smaller |
diff --git a/src/gputaskman/app.py b/src/gputaskman/app.py
index dcc2031..a394ef1 100644
--- a/src/gputaskman/app.py
+++ b/src/gputaskman/app.py
@@ -584,14 +584,15 @@ class GpuTaskManager(App):
clock_label = (f"gfx {format_metric(nv.gfx_clock)} MHz" if nv.source.startswith("AMD ") else
f"SM {format_metric(nv.sm_clock)}/{format_metric(nv.sm_clock_max)} MHz")
power_kind = f" {nv.power_kind}" if nv.power_kind else ""
+ temp_kind = f" ({nv.temp_kind})" if nv.temp_kind else ""
if self.monitoring:
clock = nv.gfx_clock if nv.source.startswith("AMD ") else nv.sm_clock
label = "gfx" if nv.source.startswith("AMD ") else "SM"
- st = Text(f"{format_metric(nv.temp, unit='°C')} "
+ st = Text(f"{format_metric(nv.temp, unit='°C')}{temp_kind} "
f"{format_metric(nv.power_w, '.0f')} W{power_kind} "
f"{label} {format_metric(clock)} MHz", style="grey70")
else:
- st = Text(f"{format_metric(nv.temp, unit='°C')} {format_metric(nv.power_w, '.0f')}/"
+ st = Text(f"{format_metric(nv.temp, unit='°C')}{temp_kind} {format_metric(nv.power_w, '.0f')}/"
f"{format_metric(nv.power_limit_w, '.0f')} W{power_kind} {pstate} "
f"{clock_label} "
f"mem {format_metric(nv.mem_clock)} MHz video {format_metric(nv.video_clock)} MHz "
diff --git a/src/gputaskman/drm.py b/src/gputaskman/drm.py
index e1e03ec..82cdbf4 100644
--- a/src/gputaskman/drm.py
+++ b/src/gputaskman/drm.py
@@ -373,6 +373,35 @@ def _hwmon_temp(hwmon: str) -> int | None:
return _milli(os.path.join(hwmon, "temp1_input"))
+def _cpu_package_temp(hwmon_root: str = "/sys/class/hwmon") -> int | None:
+ """The CPU package temperature from coretemp, for an integrated GPU with no sensor of its own.
+
+ The CPU and GPU share a die, so this is a stand-in, never presented as the GPU's own reading
+ (callers set temp_kind). Prefers "Package id 0"; None when coretemp or its package sensor is missing.
+ """
+ try:
+ hwmons = sorted(os.listdir(hwmon_root))
+ except OSError:
+ return None
+ fallback = None
+ for hwmon in hwmons:
+ path = os.path.join(hwmon_root, hwmon)
+ if _read(os.path.join(path, "name")) != "coretemp":
+ continue
+ try:
+ names = sorted(os.listdir(path))
+ except OSError:
+ continue
+ for name in names:
+ if name.startswith("temp") and name.endswith("_label"):
+ label = _read(os.path.join(path, name))
+ if label == "Package id 0":
+ return _milli(os.path.join(path, f"{name[:-len('_label')]}_input"))
+ if label and label.startswith("Package id") and fallback is None:
+ fallback = _milli(os.path.join(path, f"{name[:-len('_label')]}_input"))
+ return fallback
+
+
def _hwmon_clock(hwmon: str, label: str) -> int | None:
try:
names = sorted(os.listdir(hwmon))
@@ -452,6 +481,14 @@ def read_device(card: DrmCard, index: int) -> DeviceTelemetry:
except (ValueError, IndexError):
pass
dev.pcie_width = _int(os.path.join(d, "current_link_width"))
+ if card.intel and dev.temp is None:
+ # No GPU temperature sensor (an integrated GPU has no hwmon of its own, and a discrete card's
+ # hwmon may still lack one): the CPU package shares the die, so its temperature stands in,
+ # labelled as such (temp_kind), never presented as the GPU's own reading.
+ package = _cpu_package_temp()
+ if package is not None:
+ dev.temp = package
+ dev.temp_kind = "CPU package"
return dev
diff --git a/src/gputaskman/report.py b/src/gputaskman/report.py
index 5bb75ce..ef87afa 100644
--- a/src/gputaskman/report.py
+++ b/src/gputaskman/report.py
@@ -202,8 +202,9 @@ def to_text(s: Snapshot, limit: int = 30) -> str:
clock = (f"gfx {format_metric(nv.gfx_clock)}" if nv.source.startswith("AMD ") else
f"SM {format_metric(nv.sm_clock)}")
power_kind = f" ({nv.power_kind})" if nv.power_kind else ""
+ temp_label = f" ({nv.temp_kind})" if nv.temp_kind else ""
out.append(f"{label} {format_metric(nv.util_gpu, unit='%')} mem-bandwidth {format_metric(nv.util_mem, unit='%')} "
- f"{format_metric(nv.temp, unit='C')} {format_metric(nv.power_w, '.0f')}/"
+ f"{format_metric(nv.temp, unit='C')}{temp_label} {format_metric(nv.power_w, '.0f')}/"
f"{format_metric(nv.power_limit_w, '.0f')} W{power_kind} {pstate} "
f"{clock} MHz "
f"video {format_metric(nv.video_clock)} MHz "
diff --git a/src/gputaskman/telemetry.py b/src/gputaskman/telemetry.py
index ee2ce21..a936000 100644
--- a/src/gputaskman/telemetry.py
+++ b/src/gputaskman/telemetry.py
@@ -19,6 +19,7 @@ class DeviceTelemetry:
enc: float | None = None
dec: float | None = None
temp: float | None = None
+ temp_kind: str = "" # where a fallback temperature comes from ("CPU package"), else its own sensor
power_w: float | None = None
power_kind: str = ""
power_limit_w: float | None = None
diff --git a/tests/test_drm.py b/tests/test_drm.py
index 9086362..da36e3f 100644
--- a/tests/test_drm.py
+++ b/tests/test_drm.py
@@ -10,6 +10,7 @@ from gputaskman import drm
GiB = 1 << 30
MiB = 1 << 20
+KiB = 1 << 10
FDINFO = """pos:\t0
flags:\t02100002
@@ -421,6 +422,60 @@ class ReadDeviceTests(unittest.TestCase):
self.assertIsNone(d.enc)
self.assertIsNone(d.dec)
+ def test_cpu_package_temp_prefers_package_id_0(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ nvme = root / "hwmon0"
+ nvme.mkdir()
+ (nvme / "name").write_text("nvme\n")
+ cpu = root / "hwmon1"
+ cpu.mkdir()
+ (cpu / "name").write_text("coretemp\n")
+ (cpu / "temp1_label").write_text("Package id 0\n")
+ (cpu / "temp1_input").write_text("55000\n")
+ (cpu / "temp2_label").write_text("Core 0\n")
+ (cpu / "temp2_input").write_text("99000\n") # a core is not the package
+ self.assertEqual(drm._cpu_package_temp(str(root)), 55)
+
+ def test_cpu_package_temp_missing_is_unknown(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ cpu = root / "hwmon0"
+ cpu.mkdir()
+ (cpu / "name").write_text("coretemp\n")
+ (cpu / "temp1_label").write_text("Core 0\n") # no package sensor: no guessing from cores
+ (cpu / "temp1_input").write_text("99000\n")
+ self.assertIsNone(drm._cpu_package_temp(str(root)))
+ self.assertIsNone(drm._cpu_package_temp(str(root / "no-such-dir")))
+
+ def test_read_device_intel_falls_back_to_cpu_package_temp(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ card_sysfs = Path(tmp) / "card1"
+ dev = card_sysfs / "device"
+ dev.mkdir(parents=True)
+ card = drm.DrmCard(key=32, pdev="0000:00:02.0", sysfs=str(dev), driver="i915",
+ vendor_id=0x8086, device_id=0xA7AD, name="Intel Intel Graphics",
+ vram_total=0, integrated=True, intel=True)
+ with patch.object(drm, "_cpu_package_temp", return_value=55):
+ d = drm.read_device(card, 0)
+ self.assertEqual((d.temp, d.temp_kind), (55, "CPU package"))
+
+ def test_read_device_intel_gpu_sensor_wins_over_cpu_package(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ card_sysfs = Path(tmp) / "card1"
+ dev = card_sysfs / "device"
+ dev.mkdir(parents=True)
+ hwmon = dev / "hwmon" / "hwmon0"
+ hwmon.mkdir(parents=True)
+ (hwmon / "temp1_label").write_text("edge\n")
+ (hwmon / "temp1_input").write_text("61000\n")
+ card = drm.DrmCard(key=32, pdev="0000:00:02.0", sysfs=str(dev), driver="i915",
+ vendor_id=0x8086, device_id=0xA7AD, name="Intel Intel Graphics",
+ vram_total=0, integrated=True, intel=True)
+ with patch.object(drm, "_cpu_package_temp", return_value=55):
+ d = drm.read_device(card, 0)
+ self.assertEqual((d.temp, d.temp_kind), (61, ""))
+
class DrmCountersTests(unittest.TestCase):
def test_drm_counters(self):