From e71c230236b222dc630ed269f66cc7008ff80b97 Mon Sep 17 00:00:00 2001 From: Klaas Jan Wierenga Date: Mon, 16 Nov 2026 15:07:48 +0100 Subject: [PATCH] Fix HIP device UUID handling for integrated GPUs Some HIP devices, such as integrated GPUs, report an incomplete UUID buffer. Previously, this would lead to an error when attempting to construct a `uuid.UUID` object from the truncated data. This change modifies the `HipFunctions` backend to check the length of the reported UUID buffer. If the buffer is not the expected full size, the device's UUID environment variable is now set to `None`, gracefully handling devices that do not provide a valid UUID. A new test case has been added to verify this behavior. --- kernel_tuner/backends/hip/hip.py | 5 ++++- test/test_hip_functions.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel_tuner/backends/hip/hip.py b/kernel_tuner/backends/hip/hip.py index 848b4d46b..c32a18e18 100644 --- a/kernel_tuner/backends/hip/hip.py +++ b/kernel_tuner/backends/hip/hip.py @@ -104,7 +104,10 @@ def __init__(self, device=0, iterations=7, compiler_options=None, observers=None env["pci_bus_id"] = props.pciBusID env["pci_domain_id"] = props.pciDomainID env["pci_device_id"] = props.pciDeviceID - env["uuid"] = str(uuid.UUID(bytes=props.uuid.bytes)) + # GPUs without a UUID (e.g. iGPUs) report a placeholder that is shorter than the UUID buffer + env["uuid"] = None + if len(props.uuid.bytes) == props.uuid.c_sizeof(): + env["uuid"] = str(uuid.UUID(bytes=props.uuid.bytes)) env["hip_driver_version"] = hip_check(hip.hipDriverGetVersion()) env["hip_runtime_version"] = hip_check(hip.hipRuntimeGetVersion()) env["device_properties"] = extract_safe_properties(props) diff --git a/test/test_hip_functions.py b/test/test_hip_functions.py index e192223ed..eaaa184ef 100644 --- a/test/test_hip_functions.py +++ b/test/test_hip_functions.py @@ -1,4 +1,6 @@ import ctypes +import uuid + import numpy as np import pytest @@ -159,4 +161,12 @@ def test_smem_args(env): smem_args=dict(size=lambda p: p['block_size_x'] * 4), verbose=True, lang="HIP") tune_params = env[-1] - assert len(result) == len(tune_params["block_size_x"]) \ No newline at end of file + assert len(result) == len(tune_params["block_size_x"]) + +@skip_if_no_hip +def test_device_uuid(): + """The device UUID is either valid or None, for GPUs that do not report one (e.g. iGPUs).""" + dev = kt_hip.HipFunctions(0) + + device_uuid = dev.env["uuid"] + assert device_uuid is None or isinstance(uuid.UUID(device_uuid), uuid.UUID)