axelera: enumerate devices explicitly and fail with an actionable error

Context.list_devices() keys off the lspci BDF and needs the colon-form
node to be present, so surface an empty enumeration at init with the
fix-it hint instead of a bare device_connect(None) ConnectionError
several frames deeper. Uses the DeviceInfo the runtime enumerated
rather than relying on the pick-first implicit path.
This commit is contained in:
patrykorwat 2026-09-05 05:47:39 +00:00
parent f50a2dc1ed
commit c3085eb58d

View File

@ -436,10 +436,20 @@ class _AxeleraRuntimeInference:
model_dir = os.path.dirname(model_json)
self._ctx = runtime_factory()
model = self._ctx.load_model(model_json)
# enumerate and connect to the DeviceInfo explicitly rather than
# letting the runtime pick: it surfaces the lspci/device-node
# mismatch as an empty list instead of a late connect failure
devices = self._ctx.list_devices()
if not devices:
raise RuntimeError(
"axelera: no Metis device enumerated; check that the "
"/dev/metis-<bus>:<dev>:<fn> node (colon form) is passed "
"into the container and the metis driver is loaded"
)
# hold the device connection on self: the runtime releases the device
# when the connection object is garbage collected, so it must outlive
# init for as long as the model instance uses it
self._conn = self._ctx.device_connect(None, num_sub_devices=1)
self._conn = self._ctx.device_connect(devices[0], num_sub_devices=1)
self._instance = self._conn.load_model_instance(
model, num_sub_devices=1, aipu_cores=1
)