From 012c832b0d4e6157af6c133732c54a964d3cbfee Mon Sep 17 00:00:00 2001 From: "Wei (Will) Feng" <134637289+weifengpy@users.noreply.github.com> Date: Tue, 10 Nov 2026 18:02:21 -0800 Subject: [PATCH 1/2] pyzes: load the Level Zero loader by SONAME on Linux _LoadZeLibrary hardcoded /usr/lib/x86_64-linux-gnu/libze_loader.so.1 on Linux. When a different (e.g. newer) loader is the one the Level Zero runtime resolves through the standard search path - common when oneAPI or a locally built loader is installed under /usr/local or /opt - pyzes pins the distro copy instead. A zesInit issued through that mismatched loader leaves the process in a state where the Unified Runtime no longer enumerates the Level Zero platform, which breaks downstream consumers that query Sysman before initializing the runtime. torch.xpu.device_count() is one such consumer: after it runs, torch.xpu.get_device_properties() fails with "No XPU devices are available" on a healthy Intel Arc B580 system. Load libze_loader.so.1 by SONAME instead, so the dynamic linker picks the same loader copy as every other consumer. The distro location remains reachable through the standard search path. This commit was authored with the assistance of an AI coding tool. Signed-off-by: Wei (Will) Feng <134637289+weifengpy@users.noreply.github.com> --- bindings/sysman/python/source/pyzes/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bindings/sysman/python/source/pyzes/__init__.py b/bindings/sysman/python/source/pyzes/__init__.py index 823f73f3..c675c960 100644 --- a/bindings/sysman/python/source/pyzes/__init__.py +++ b/bindings/sysman/python/source/pyzes/__init__.py @@ -69,7 +69,14 @@ def _LoadZeLibrary(): # load the library libName = "ze_loader" if sys.platform.startswith("linux"): - libName = "/usr/lib/x86_64-linux-gnu/lib" + libName + ".so.1" + # Load by SONAME so the dynamic linker resolves the loader + # through the standard search path (LD_LIBRARY_PATH, the + # ld.so cache, default directories). Hardcoding one distro + # location can pin an older loader than the one the Level + # Zero runtime itself uses when several loaders coexist, + # and a zesInit through the mismatched copy can break + # device enumeration for the whole process. + libName = "lib" + libName + ".so.1" else: libName = libName + ".dll" From 87d9bb9c28ce15856eb3e7ca21a6d0b95078e57c Mon Sep 17 00:00:00 2001 From: "Wei (Will) Feng" <134637289+weifengpy@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:48:46 -0800 Subject: [PATCH 2/2] pyzes: resolve the loader SONAME dynamically on Linux The previous change hardcoded the major version in libze_loader.so.1, which would break when Level Zero moves to major version 2, as pointed out in review of #559. Resolve the SONAME at runtime with ctypes.util.find_library(), which queries the system ldconfig cache and returns the current SONAME (libze_loader.so.1 today, the .so.2 name after a major bump). Fall back to the unversioned libze_loader.so if find_library() returns nothing. Loading still happens by SONAME through the standard search path, so the loader copy the runtime uses still wins over a pinned distro copy. The suggested helper.py get_major_ver() parses a $X_MAKE_VERSION(...) spec string at code-generation time; that input is not available to pyzes at runtime, so find_library() is the runtime equivalent of dynamic extraction. This commit was authored with the assistance of an AI coding tool. Signed-off-by: Wei (Will) Feng <134637289+weifengpy@users.noreply.github.com> --- .../sysman/python/source/pyzes/__init__.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bindings/sysman/python/source/pyzes/__init__.py b/bindings/sysman/python/source/pyzes/__init__.py index c675c960..f8649213 100644 --- a/bindings/sysman/python/source/pyzes/__init__.py +++ b/bindings/sysman/python/source/pyzes/__init__.py @@ -9,6 +9,7 @@ # Python bindings for the libze_intel_gpu.so / ze_intel_gpu.dll library ## +import ctypes.util import glob import os import sys @@ -69,14 +70,25 @@ def _LoadZeLibrary(): # load the library libName = "ze_loader" if sys.platform.startswith("linux"): - # Load by SONAME so the dynamic linker resolves the loader - # through the standard search path (LD_LIBRARY_PATH, the - # ld.so cache, default directories). Hardcoding one distro + # Resolve the loader SONAME dynamically and load by that + # SONAME, so the dynamic linker resolves the loader through + # the standard search path (LD_LIBRARY_PATH, the ld.so + # cache, default directories). Hardcoding one distro # location can pin an older loader than the one the Level # Zero runtime itself uses when several loaders coexist, # and a zesInit through the mismatched copy can break # device enumeration for the whole process. - libName = "lib" + libName + ".so.1" + # find_library() asks the system (ldconfig) for the current + # SONAME, so no major version is hardcoded here and this + # keeps working across a Level Zero major version bump. + # This is the runtime equivalent of extracting the major + # version dynamically: the build-time helper in + # scripts/templates/helper.py (get_major_ver) parses a + # $X_MAKE_VERSION(...) spec string, which is not available + # to pyzes at runtime. + # Fall back to the unversioned name, which the dynamic + # linker can still resolve through the same search path. + libName = ctypes.util.find_library(libName) or "lib" + libName + ".so" else: libName = libName + ".dll"