Skip to content

Commit 3c0e6c6

Browse files
committed
Add more environment information in HIP backend (device UUID, device properties, driver version, etc)
1 parent a728e0c commit 3c0e6c6

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

  • kernel_tuner/backends/hip

kernel_tuner/backends/hip/hip.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import ctypes
44
import ctypes.util
55
import logging
6+
import json
7+
import uuid
68

79
import numpy as np
810

@@ -32,8 +34,35 @@
3234

3335
hipSuccess = 0
3436

37+
38+
def extract_safe_properties(props):
39+
"""Extract those properties that are 'safe' (i.e, json serializable)"""
40+
result = dict()
41+
42+
for key in props.PROPERTIES():
43+
try:
44+
value = getattr(props, key)
45+
if isinstance(value, (str, int, float)):
46+
# These are safe
47+
result[key] = value
48+
elif isinstance(value, (bytes, bytearray)):
49+
# bytes/bytearray is typically a string
50+
result[key] = value.decode("utf-8").rstrip("\x00")
51+
else:
52+
# As last option, try to convert to json
53+
result[key] = json.loads(json.dumps(value))
54+
except Exception:
55+
continue
56+
57+
# Remove the 'reserved' fields as they are just filled with zeros
58+
result.pop("reserved", None)
59+
result.pop("hipReserved", None)
60+
61+
return result
62+
63+
3564
class HipFunctions(GPUBackend):
36-
"""Class that groups the HIP functions on maintains state about the device."""
65+
"""Class that groups the HIP functions and maintains state about the device."""
3766

3867
def __init__(self, device=0, iterations=7, compiler_options=None, observers=None):
3968
"""Instantiate HipFunctions object used for interacting with the HIP device.
@@ -72,6 +101,13 @@ def __init__(self, device=0, iterations=7, compiler_options=None, observers=None
72101
env["device_name"] = self.name
73102
env["iterations"] = self.iterations
74103
env["compiler_options"] = compiler_options
104+
env["pci_bus_id"] = props.pciBusID
105+
env["pci_domain_id"] = props.pciDomainID
106+
env["pci_device_id"] = props.pciDeviceID
107+
env["uuid"] = str(uuid.UUID(bytes=props.uuid.bytes))
108+
env["hip_driver_version"] = hip_check(hip.hipDriverGetVersion())
109+
env["hip_runtime_version"] = hip_check(hip.hipRuntimeGetVersion())
110+
env["device_properties"] = extract_safe_properties(props)
75111
self.env = env
76112

77113
# Create stream and events

0 commit comments

Comments
 (0)