{"record":{"id":"0d588b8ec83ab937","repo":"invoke-ai/InvokeAI","slug":"fn-name-failed","errorCode":null,"errorMessage":"{fn_name} failed","messagePattern":"(.+?) failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"invokeai/backend/util/level_zero.py","lineNumber":173,"sourceCode":"\n    Level Zero's enumeration order is only meaningfully comparable to torch's ``xpu:N`` ordering\n    when both see the same set. If the counts disagree (``ZE_AFFINITY_MASK``, a flat/composite\n    tile hierarchy, a non-Intel Level Zero driver in the list), decline to answer rather than risk\n    mislabelling a device.\n    \"\"\"\n    devices: list[ctypes.c_void_p] = []\n    for driver in _enumerate(lib, driver_get):\n        devices += _enumerate(lib, device_get, driver)\n    return devices if len(devices) == torch.xpu.device_count() else None\n\n\ndef _enumerate(lib: ctypes.CDLL, fn_name: str, parent: Optional[ctypes.c_void_p] = None) -> list[ctypes.c_void_p]:\n    \"\"\"Level Zero's two-call enumeration: ask for the count, then fill an array.\"\"\"\n    fn = getattr(lib, fn_name)\n    count = ctypes.c_uint32(0)\n    head = [parent] if parent is not None else []\n    if fn(*head, ctypes.byref(count), None) != 0:\n        raise RuntimeError(f\"{fn_name} failed\")\n    if count.value == 0:\n        return []\n    arr = (ctypes.c_void_p * count.value)()\n    if fn(*head, ctypes.byref(count), arr) != 0:\n        raise RuntimeError(f\"{fn_name} failed\")\n    return list(arr[: count.value])\n\n\ndef _probe_integrated_flags() -> Optional[dict[int, bool]]:\n    lib = _load_loader()\n    if lib is None:\n        return None\n    try:\n        if lib.zeInit(0) != 0:\n            return None\n        devices = _enumerate_devices(lib, \"zeDriverGet\", \"zeDeviceGet\")\n        if devices is None:\n            return None","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/util/level_zero.py#L155-L191","documentation":"_enumerate implements Level Zero's two-call enumeration pattern: first ask for the device count, then fill an array. A non-zero result code from the first (count) call raises this RuntimeError, indicating the zeDevice/zeSysman enumeration function itself failed (driver error, uninitialized loader, or permission problem).","triggerScenarios":"The first ze*Enumerate* call returns a non-zero result code — e.g. driver not initialized, zeInit not performed, GPU inaccessible, or Level Zero driver failure during _enumerate_devices/_init_sysman.","commonSituations":"Intel GPU driver crashes or being reset; running in containers without /dev/dri device access; incompatible level-zero loader/driver pairs.","solutions":["Check GPU driver health (dmesg for i915/xe errors) and reload or update the Intel GPU driver","Ensure the container/host exposes GPU devices (/dev/dri/*) and renders group access","Confirm the level-zero loader version matches the installed driver"],"exampleFix":"// before (docker)\ndocker run invokeai\n// after\ndocker run --device /dev/dri --group-add $(getent group render | cut -d: -f3) invokeai","handlingStrategy":"retry","validationCode":"import ctypes\nlib = ctypes.CDLL(\"libze_loader.so.1\")\nif not hasattr(lib, fn_name):\n    raise RuntimeError(\"loader missing fn\")\n# check GPU present first:\nimport os\nif not os.path.exists(\"/dev/dri\"):\n    raise RuntimeError(\"no GPU devices exposed\")","typeGuard":"def gpu_accessible():\n    import os\n    return any(p.startswith(\"card\") for p in os.listdir(\"/dev/dri\")) if os.path.isdir(\"/dev/dri\") else False","tryCatchPattern":"for attempt in range(3):\n    try:\n        devices = enumerate_devices(lib)\n        break\n    except RuntimeError as e:\n        logger.warning(\"enumeration attempt %d failed: %s\", attempt, e)\n        time.sleep(1)\nelse:\n    devices = []","preventionTips":["Expose /dev/dri and render group in containers","Monitor dmesg for GPU resets","Retry transient enumeration failures before giving up"],"tags":["runtimeerror","intel-gpu","level-zero","device-enumeration"],"backgroundTag":"gpu-device-enumeration-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}