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

Address review: integrated-only temp fallback, robust sensor scan

Martin Pluskal4bf17cfab68c
diff --git a/src/gputaskman/drm.py b/src/gputaskman/drm.py
index 82cdbf4..27e428c 100644
--- a/src/gputaskman/drm.py
+++ b/src/gputaskman/drm.py
@@ -395,10 +395,13 @@ def _cpu_package_temp(hwmon_root: str = "/sys/class/hwmon") -> int | None:
for name in names:
if name.startswith("temp") and name.endswith("_label"):
label = _read(os.path.join(path, name))
+ value = _milli(os.path.join(path, f"{name[:-len('_label')]}_input"))
+ if value is None:
+ continue # torn or unparseable reading: try the other sensors
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 value
+ if label is not None and label.startswith("Package id") and fallback is None:
+ fallback = value
return fallback
@@ -481,10 +484,10 @@ 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.
+ if card.intel and card.integrated and dev.temp is None:
+ # No GPU temperature sensor (an integrated GPU has no hwmon of its own): the CPU package shares
+ # the die, so its temperature stands in, labelled as such (temp_kind), never presented as the
+ # GPU's own reading. A discrete card keeps N/A: the package is not its temperature.
package = _cpu_package_temp()
if package is not None:
dev.temp = package
diff --git a/tests/test_drm.py b/tests/test_drm.py
index da36e3f..793e50e 100644
--- a/tests/test_drm.py
+++ b/tests/test_drm.py
@@ -448,6 +448,18 @@ class ReadDeviceTests(unittest.TestCase):
self.assertIsNone(drm._cpu_package_temp(str(root)))
self.assertIsNone(drm._cpu_package_temp(str(root / "no-such-dir")))
+ def test_cpu_package_temp_skips_torn_readings(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("Package id 0\n")
+ (cpu / "temp1_input").write_text("lots\n") # torn: try the other sensors
+ (cpu / "temp2_label").write_text("Package id 1\n")
+ (cpu / "temp2_input").write_text("48000\n")
+ self.assertEqual(drm._cpu_package_temp(str(root)), 48)
+
def test_read_device_intel_falls_back_to_cpu_package_temp(self):
with tempfile.TemporaryDirectory() as tmp:
card_sysfs = Path(tmp) / "card1"
@@ -476,6 +488,20 @@ class ReadDeviceTests(unittest.TestCase):
d = drm.read_device(card, 0)
self.assertEqual((d.temp, d.temp_kind), (61, ""))
+ def test_read_device_discrete_intel_without_sensor_stays_unknown(self):
+ # The CPU package shares a die with an integrated GPU only; on a discrete card it is
+ # not the GPU's temperature, so there is no fallback.
+ with tempfile.TemporaryDirectory() as tmp:
+ card_sysfs = Path(tmp) / "card1"
+ dev = card_sysfs / "device"
+ dev.mkdir(parents=True)
+ card = drm.DrmCard(key=12288, pdev="0000:03:00.0", sysfs=str(dev), driver="i915",
+ vendor_id=0x8086, device_id=0x56A0, name="Intel Arc A770",
+ vram_total=16 * GiB, integrated=False, 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), (None, ""))
+
class DrmCountersTests(unittest.TestCase):
def test_drm_counters(self):