Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 20 additions & 37 deletions bindings/sysman/python/source/pyzes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,9 @@ def _LoadZeLibrary():
# load the library
libName = "ze_loader"
if sys.platform.startswith("linux"):
print("Loading Linux library")
libName = "/usr/lib/x86_64-linux-gnu/lib" + libName + ".so.1"
else:
print("Loading Windows library")
# Try multiple common locations for Windows Intel GPU drivers
import os

possible_paths = [
# Try system PATH first
libName + "64.dll",
Expand All @@ -86,42 +82,29 @@ def _LoadZeLibrary():

library_loaded = False
for path in possible_paths:
try:
if "*" in path:
# Handle wildcard paths for driver store
import glob

matching_paths = glob.glob(path)
for match_path in matching_paths:
try:
print(f"Trying: {match_path}")
gpuLib = CDLL(match_path)
library_loaded = True
print(f"Successfully loaded: {match_path}")
break
except Exception as e:
print(f"Failed to load {match_path}: {e}")
continue
else:
if os.path.exists(path):
print(f"Trying: {path}")
gpuLib = CDLL(path)
library_loaded = True
print(f"Successfully loaded: {path}")
break
else:
print(f"Trying: {path}")
gpuLib = CDLL(path)
library_loaded = True
print(f"Successfully loaded: {path}")
break
except Exception as e:
print(f"Failed to load {path}: {e}")
continue

if library_loaded:
break

if "*" in path:
# Handle wildcard paths for driver store
import glob

matching_paths = glob.glob(path)
for match_path in matching_paths:
try:
gpuLib = CDLL(match_path)
library_loaded = True
break
except OSError:
pass # Try next path
else:
# Try loading the library directly
try:
gpuLib = CDLL(path)
library_loaded = True
except OSError:
pass # Try next path

if not library_loaded:
raise Exception(
f"Failed to load Intel GPU library. Tried paths: {possible_paths}"
Expand Down
16 changes: 5 additions & 11 deletions bindings/sysman/python/test/unit_tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@ def test_GivenLibraryAlreadyLoadedWhenCallingLoadZeLibraryThenReturnsEarly(self)

try:
# This should return early without any library loading
with patch("builtins.print") as mock_print:
self.pyzes._LoadZeLibrary()
# Should not print "Loading Linux library" because it returns early
print_calls = [
call.args[0] for call in mock_print.call_args_list if call.args
]
self.assertNotIn("Loading Linux library", print_calls)
self.pyzes._LoadZeLibrary()
# Verify gpuLib remains unchanged (early return)
self.assertEqual(self.pyzes.gpuLib, mock_lib)
finally:
# Restore original state
self.pyzes.gpuLib = original_gpuLib
Expand Down Expand Up @@ -201,11 +197,10 @@ def test_GivenValidLibraryWhenGettingNewFunctionPointerThenCachesAndReturnsFunct

@patch("sys.platform", "win32")
@patch("pyzes.gpuLib", None)
@patch("builtins.print")
@patch("os.path.exists")
@patch("pyzes.CDLL")
def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded(
self, mock_cdll, mock_exists, mock_print
self, mock_cdll, mock_exists
):
# Test Windows library loading path with deterministic mocking
mock_exists.return_value = True
Expand All @@ -214,10 +209,9 @@ def test_GivenWindowsPlatformWhenLoadingLibraryThenLibraryIsLoaded(

self.pyzes._LoadZeLibrary()

# Verify Windows-specific print was called
mock_print.assert_any_call("Loading Windows library")
# Verify successful library loading
mock_cdll.assert_called()
self.assertIsNotNone(self.pyzes.gpuLib)


if __name__ == "__main__":
Expand Down
Loading