Skip to content

Commit f87458e

Browse files
Use os.add_dll_directory on Windows
This makes DPCTLSyclInterface.dll library findable with Python 3.10 Python 3.10 modifies the behavior on how it looks for DLLs to make it more secure. Library provides must add it to DLL search path using 'add_dll_directory' utility for Python's internal dynamic library opener to be able to find it. This affects loading of native extensions as well, since if native extension depends on the DLL which can not be found by Python's library loader, ModuleNotFoundError is raised
1 parent ecec512 commit f87458e

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

dpctl/__init__.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@
3232
"""
3333
__author__ = "Intel Corp."
3434

35-
from dpctl._sycl_context import SyclContext, SyclContextCreationError
36-
from dpctl._sycl_device import (
35+
import os
36+
import os.path
37+
38+
from ._device_selection import select_device_with_aspects
39+
from ._sycl_context import SyclContext, SyclContextCreationError
40+
from ._sycl_device import (
3741
SyclDevice,
3842
SyclDeviceCreationError,
3943
SyclSubDeviceCreationError,
4044
)
41-
from dpctl._sycl_device_factory import (
45+
from ._sycl_device_factory import (
4246
get_devices,
4347
get_num_devices,
4448
has_accelerator_devices,
@@ -51,15 +55,15 @@
5155
select_gpu_device,
5256
select_host_device,
5357
)
54-
from dpctl._sycl_event import SyclEvent
55-
from dpctl._sycl_platform import SyclPlatform, get_platforms, lsplatform
56-
from dpctl._sycl_queue import (
58+
from ._sycl_event import SyclEvent
59+
from ._sycl_platform import SyclPlatform, get_platforms, lsplatform
60+
from ._sycl_queue import (
5761
SyclKernelInvalidRangeError,
5862
SyclKernelSubmitError,
5963
SyclQueue,
6064
SyclQueueCreationError,
6165
)
62-
from dpctl._sycl_queue_manager import (
66+
from ._sycl_queue_manager import (
6367
device_context,
6468
get_current_backend,
6569
get_current_device_type,
@@ -69,8 +73,6 @@
6973
nested_context_factories,
7074
set_global_queue,
7175
)
72-
73-
from ._device_selection import select_device_with_aspects
7476
from ._sycl_timer import SyclTimer
7577
from ._version import get_versions
7678
from .enum_types import (
@@ -145,6 +147,10 @@
145147
"utils",
146148
]
147149

150+
if hasattr(os, "add_dll_directory"):
151+
# Include folder containing DPCTLSyclInterface.dll to search path
152+
os.add_dll_directory(os.path.dirname(__file__))
153+
148154

149155
def get_include():
150156
r"""
@@ -153,8 +159,6 @@ def get_include():
153159
Extension modules that need to be compiled against dpctl should use
154160
this function to locate the appropriate include directory.
155161
"""
156-
import os.path
157-
158162
return os.path.join(os.path.dirname(__file__), "include")
159163

160164

0 commit comments

Comments
 (0)