Fix WARNING: AMD GPUs visible, but data is inaccessible (#58)

* [SWDEV-531834] Fix AMD GPUs visible, but data is inaccessible:
- Scans directories under /sys/bus/pci/drivers/amdgpu
- Verifies each device's runtime_status to determine if it's active
- Returns False if any device is not in active state
- Handles permission errors gracefully with proper debug logging
- Includes comments explaining behavior differences between Instinct / NAVI hardware

The default status is set to True, assuming devices are active unless
proven otherwise, which accommodates hardware like some Instinct ASICS
which do not support runtime power management.

Signed-off-by: Juan Castillo <juan.castillo@amd.com>

[ROCm/rocm_smi_lib commit: 47f80145cb]
This commit is contained in:
Castillo, Juan
2025-05-15 14:30:33 -05:00
committed by GitHub
parent 22777b75b5
commit 08062c0577
@@ -3920,23 +3920,40 @@ def checkAmdGpus(deviceList):
return False
def check_runtime_status()->bool:
"""Check the runtime status of all paths along /sys/bus/pci/drivers/amdgpu/*/power/runtime_status.
def check_runtime_status() -> bool:
"""Check the runtime status of all AMD GPU devices managed by the amdgpu driver.
Returns:
bool: True if any status is "active", False if any status is "unsupported".
This function scans the directories under the specified path to verify the
runtime power management status of each device. It checks the "runtime_status"
file for each device to determine if the device is in an "active" state. If any
device is not in an "active" state it returns False. If the file is inaccessible,
this may be due to a system that does not support runtime power management.
Some GPUs support runtime power management, while others may not. This is why the default status
is set to True.
bool: False if any device is not in "active" state, True otherwise.
"""
base_path = "/sys/bus/pci/drivers/amdgpu"
status = True # Default to True, assuming active unless proven otherwise
for device in os.listdir(base_path):
if os.path.isdir(os.path.join(base_path, device)):
runtime_status_path = os.path.join(base_path, device, "power", "runtime_status")
if os.path.exists(runtime_status_path):
with open(runtime_status_path, 'r') as file:
status = file.read().strip()
if status == "active":
return True
return False
try:
if os.path.exists(runtime_status_path):
with open(runtime_status_path, 'r') as file:
current_status = file.read().strip()
if current_status != "active":
status = False
continue
else:
logging.debug(f"Runtime status for {device}: {current_status}")
except PermissionError as e:
# Handle permission errors gracefully
logging.debug(f"Permission denied while accessing {runtime_status_path} \nError: {e}")
continue
else:
logging.debug(f"Path {os.path.join(base_path, device)} is not a directory.")
return status
def component_str(component):
""" Returns the component String value