Skip to content

Commit 111bf65

Browse files
authored
fix: Load the loader dll not the umd lib directly (#484)
Signed-off-by: Aviral Nigam <aviral.nigam@intel.com>
1 parent 27edac6 commit 111bf65

1 file changed

Lines changed: 26 additions & 29 deletions

File tree

bindings/sysman/python/source/pyzes.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# Python bindings for the libze_intel_gpu.so / ze_intel_gpu.dll library
1010
##
1111

12+
import glob
13+
import os
1214
import sys
1315
import threading
1416
from ctypes import *
@@ -69,45 +71,40 @@ def _LoadZeLibrary():
6971
if sys.platform.startswith("linux"):
7072
libName = "/usr/lib/x86_64-linux-gnu/lib" + libName + ".so.1"
7173
else:
72-
# Try multiple common locations for Windows Intel GPU drivers
74+
libName = libName + ".dll"
75+
76+
module_dir = os.path.dirname(os.path.abspath(__file__))
77+
system_root = os.environ.get("SystemRoot", r"C:\Windows")
78+
7379
possible_paths = [
74-
# Try system PATH first
75-
libName + "64.dll",
76-
# Common Intel GPU driver locations
77-
r"C:\Windows\System32\DriverStore\FileRepository\iigd_dch.inf_amd64_*\ze_intel_gpu64.dll",
78-
r"C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_*\ze_intel_gpu64.dll",
79-
# Try current directory
80-
"ze_intel_gpu64.dll",
80+
os.path.join(module_dir, libName),
81+
os.path.join(system_root, "System32", libName),
82+
r"C:\Windows\System32\DriverStore\FileRepository\iigd_dch.inf_amd64_*\ze_loader.dll",
83+
r"C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_*\ze_loader.dll",
84+
libName,
8185
]
8286

8387
library_loaded = False
88+
load_errors = []
8489
for path in possible_paths:
85-
if library_loaded:
86-
break
87-
88-
if "*" in path:
89-
# Handle wildcard paths for driver store
90-
import glob
91-
92-
matching_paths = glob.glob(path)
93-
for match_path in matching_paths:
94-
try:
95-
gpuLib = CDLL(match_path)
96-
library_loaded = True
97-
break
98-
except OSError:
99-
pass # Try next path
100-
else:
101-
# Try loading the library directly
90+
candidate_matches = glob.glob(path) if "*" in path else [path]
91+
if not candidate_matches:
92+
load_errors.append(f"{path}: no matches found")
93+
continue
94+
for match_path in candidate_matches:
10295
try:
103-
gpuLib = CDLL(path)
96+
gpuLib = CDLL(match_path)
10497
library_loaded = True
105-
except OSError:
106-
pass # Try next path
98+
break
99+
except OSError as error:
100+
load_errors.append(f"{match_path}: {error}")
101+
if library_loaded:
102+
break
107103

108104
if not library_loaded:
109105
raise Exception(
110-
f"Failed to load Intel GPU library. Tried paths: {possible_paths}"
106+
"Failed to load Level Zero loader on Windows. "
107+
f"Tried paths: {possible_paths}. Errors: {load_errors}"
111108
)
112109

113110
if sys.platform.startswith("linux"):

0 commit comments

Comments
 (0)