|
9 | 9 | # Python bindings for the libze_intel_gpu.so / ze_intel_gpu.dll library |
10 | 10 | ## |
11 | 11 |
|
| 12 | +import glob |
| 13 | +import os |
12 | 14 | import sys |
13 | 15 | import threading |
14 | 16 | from ctypes import * |
@@ -69,45 +71,40 @@ def _LoadZeLibrary(): |
69 | 71 | if sys.platform.startswith("linux"): |
70 | 72 | libName = "/usr/lib/x86_64-linux-gnu/lib" + libName + ".so.1" |
71 | 73 | 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 | + |
73 | 79 | 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, |
81 | 85 | ] |
82 | 86 |
|
83 | 87 | library_loaded = False |
| 88 | + load_errors = [] |
84 | 89 | 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: |
102 | 95 | try: |
103 | | - gpuLib = CDLL(path) |
| 96 | + gpuLib = CDLL(match_path) |
104 | 97 | 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 |
107 | 103 |
|
108 | 104 | if not library_loaded: |
109 | 105 | 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}" |
111 | 108 | ) |
112 | 109 |
|
113 | 110 | if sys.platform.startswith("linux"): |
|
0 commit comments