|
12 | 12 | import time |
13 | 13 | import weakref |
14 | 14 | import gc |
| 15 | +import sys |
| 16 | +import subprocess |
15 | 17 | from pathlib import Path |
16 | 18 | from typing import TYPE_CHECKING |
17 | 19 | import numpy as np |
@@ -87,9 +89,44 @@ def __init__(self): |
87 | 89 | self._device = pyxrt.device(0) |
88 | 90 | break |
89 | 91 | 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 | + |
90 | 125 | if attempt == max_retries - 1: |
91 | 126 | raise e |
| 127 | + |
92 | 128 | gc.collect() # Make sure contexts are garbage collected. |
| 129 | + time.sleep(1.0 * (attempt + 1)) # Exponential backoff |
93 | 130 |
|
94 | 131 | self._device_type_str = self._device.get_info(pyxrt.xrt_info_device.name) |
95 | 132 |
|
|
0 commit comments