Skip to content

Commit e1d19f9

Browse files
authored
Try to debug "device not found" error (#2848)
1 parent 1f3d14e commit e1d19f9

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

python/utils/hostruntime/xrtruntime/hostruntime.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import time
1313
import weakref
1414
import gc
15+
import sys
16+
import subprocess
1517
from pathlib import Path
1618
from typing import TYPE_CHECKING
1719
import numpy as np
@@ -87,9 +89,44 @@ def __init__(self):
8789
self._device = pyxrt.device(0)
8890
break
8991
except RuntimeError as e:
92+
print(
93+
f"XRTHostRuntime: Failed to acquire device (attempt {attempt+1}/{max_retries}): {e}",
94+
file=sys.stderr,
95+
)
96+
97+
# Debugging info
98+
try:
99+
if os.path.exists("/dev/accel/accel0"):
100+
print("/dev/accel/accel0 exists", file=sys.stderr)
101+
# Stat it
102+
st = os.stat("/dev/accel/accel0")
103+
print(f"Stat: {st}", file=sys.stderr)
104+
else:
105+
print("/dev/accel/accel0 does not exist", file=sys.stderr)
106+
107+
# Try running xrt-smi examine
108+
# We need to find xrt-smi. It might be in PATH or /opt/xilinx/xrt/bin
109+
xrt_bin = (
110+
os.environ.get("XILINX_XRT", "/opt/xilinx/xrt") + "/bin/xrt-smi"
111+
)
112+
if os.path.exists(xrt_bin):
113+
print(f"Running {xrt_bin} examine", file=sys.stderr)
114+
result = subprocess.run(
115+
[xrt_bin, "examine"],
116+
timeout=5,
117+
capture_output=True,
118+
text=True,
119+
)
120+
print(f"xrt-smi stdout:\n{result.stdout}", file=sys.stderr)
121+
print(f"xrt-smi stderr:\n{result.stderr}", file=sys.stderr)
122+
except Exception as debug_e:
123+
print(f"Failed to run debug checks: {debug_e}", file=sys.stderr)
124+
90125
if attempt == max_retries - 1:
91126
raise e
127+
92128
gc.collect() # Make sure contexts are garbage collected.
129+
time.sleep(1.0 * (attempt + 1)) # Exponential backoff
93130

94131
self._device_type_str = self._device.get_info(pyxrt.xrt_info_device.name)
95132

0 commit comments

Comments
 (0)