Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows can't find SYCL Module #1930

Closed
liam-clink opened this issue Dec 10, 2024 · 16 comments
Closed

Windows can't find SYCL Module #1930

liam-clink opened this issue Dec 10, 2024 · 16 comments

Comments

@liam-clink
Copy link

When I import dpctl on Windows 10, it fails, giving this error:

Python 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dpctl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\dpctl\__init__.py", line 29, in <module>
    from ._device_selection import select_device_with_aspects
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\dpctl\_device_selection.py", line 20, in <module>
    from ._sycl_device import SyclDevice, SyclDeviceCreationError
ImportError: DLL load failed while importing _sycl_device: The specified module could not be found.

I have made sure that oneAPI is properly installed, I can even build C++ programs with it. I have made sure Visual Studio C++ redistributable is installed, and nothing. I make sure to run 'C:\Program Files (x86)\Intel\oneAPI\setvars.bat' before doing this, it doesn't make a difference. It's not an outdated version, it's from October this year (0.18.1), so #1177 is not relevant.

@oleksandr-pavlyk
Copy link
Collaborator

The ImportError is caused by the failure to load dependent libraries. To triage this, specifics of how you installed dpctl are needed. Please provide installation steps you followed. Did you install dpctl using conda or pip? Please provide outputs of pip list of conda list accordingly. If you used pip, how did you install the Python itself?

It is important to understand these details to provide you with the expedient resolution. We also need to know where the dependent libraries needed by dpctl are located in your Python layout (if at all).

Please note a related issue gh-1745, which was fixed in 0.18.3.

@liam-clink
Copy link
Author

liam-clink commented Dec 11, 2024

I installed with pip.

pip list output ``` PS C:\Users\liam> pip list Package Version ------------------------- -------------- anndata 0.11.0 anyio 4.6.2.post1 argon2-cffi 23.1.0 argon2-cffi-bindings 21.2.0 array_api_compat 1.9.1 arrow 1.3.0 asttokens 2.4.1 async-lru 2.0.4 attrs 24.2.0 babel 2.16.0 beautifulsoup4 4.12.3 bleach 6.2.0 build 1.2.2.post1 CacheControl 0.14.1 certifi 2024.8.30 cffi 1.17.1 charset-normalizer 3.4.0 cleo 2.1.0 colorama 0.4.6 comm 0.2.2 contourpy 1.3.0 crashtest 0.4.1 cupy 13.3.0 cycler 0.12.1 Cython 3.0.11 debugpy 1.8.8 decorator 5.1.1 defusedxml 0.7.1 distlib 0.3.9 dpcpp-cpp-rt 2025.0.3 dpctl 0.18.1 dpnp 0.16.0 dulwich 0.22.5 executing 2.1.0 fastjsonschema 2.20.0 fastrlock 0.8.2 filelock 3.16.1 fonttools 4.54.1 fqdn 1.5.1 h11 0.14.0 h5py 3.12.1 httpcore 1.0.6 httpx 0.27.2 idna 3.10 installer 0.7.0 intel-cmplr-lib-rt 2025.0.3 intel-cmplr-lib-ur 2025.0.3 intel-cmplr-lic-rt 2025.0.3 intel-opencl-rt 2025.0.3 intel-openmp 2025.0.3 intel-sycl-rt 2025.0.3 ipykernel 6.29.5 ipython 8.29.0 isoduration 20.11.0 jaraco.classes 3.4.0 jaraco.context 6.0.1 jaraco.functools 4.1.0 jedi 0.19.1 Jinja2 3.1.4 joblib 1.4.2 json5 0.9.25 jsonpointer 3.0.0 jsonref 1.1.0 jsonschema 4.23.0 jsonschema-specifications 2024.10.1 jupyter_client 8.6.3 jupyter_core 5.7.2 jupyter-events 0.10.0 jupyter-lsp 2.2.5 jupyter_server 2.14.2 jupyter_server_terminals 0.5.3 jupyterlab 4.3.0 jupyterlab_pygments 0.3.0 jupyterlab_server 2.27.3 keyboard 0.13.5 keyring 25.5.0 kiwisolver 1.4.7 legacy-api-wrap 1.4 llvmlite 0.43.0 MarkupSafe 3.0.2 matplotlib 3.9.2 matplotlib-inline 0.1.7 mistune 3.0.2 mkl 2025.0.0 more-itertools 10.5.0 msgpack 1.1.0 mudata 0.3.1 natsort 8.4.0 nbclient 0.10.0 nbconvert 7.16.4 nbformat 5.10.4 nest-asyncio 1.6.0 networkx 3.4.2 notebook 7.2.2 notebook_shim 0.2.4 numpy 2.2.0 onemkl-sycl-blas 2025.0.0 onemkl-sycl-dft 2025.0.0 onemkl-sycl-lapack 2025.0.0 onemkl-sycl-rng 2025.0.0 onemkl-sycl-stats 2025.0.0 onemkl-sycl-vm 2025.0.0 opencv-python 4.10.0.84 overrides 7.7.0 packaging 24.2 pandas 2.2.3 pandocfilters 1.5.1 parso 0.8.4 patsy 0.5.6 pexpect 4.9.0 pillow 11.0.0 pip 24.3.1 pip-review 1.3.0 pkginfo 1.11.2 platformdirs 4.3.6 plumbum 1.9.0 poetry 1.8.4 poetry-core 1.9.1 poetry-plugin-export 1.8.0 prometheus_client 0.21.0 prompt_toolkit 3.0.48 protobuf 5.28.3 psutil 6.1.0 ptyprocess 0.7.0 pure_eval 0.2.3 PyAudio 0.2.14 pycparser 2.22 pyelftools 0.31 pyft232 0.12 Pygments 2.18.0 pyluxcore 2.9a1.post4 pyluxcoretools 2.9a1.post3 pynndescent 0.5.13 pyparsing 3.2.0 pyproject_hooks 1.2.0 PyQt5 5.15.11 PyQt5-Qt5 5.15.2 PyQt5_sip 12.15.0 PyQt6-Qt6 6.7.3 PyQt6_sip 13.8.0 pyqtgraph 0.13.7 pyserial 3.5 PySide6_Addons 6.8.0.2 PySide6_Essentials 6.8.0.2 python-dateutil 2.9.0.post0 python-json-logger 2.0.7 pytz 2024.2 pyusb 1.2.1 PyVISA 1.14.1 pywin32 308 pywin32-ctypes 0.2.3 pywinpty 2.0.14 PyYAML 6.0.2 pyzmq 26.2.0 RapidFuzz 3.10.1 referencing 0.35.1 requests 2.32.3 requests-toolbelt 1.0.0 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rpds-py 0.21.0 rpyc 6.0.1 scikit-learn 1.5.2 scipy 1.14.1 seaborn 0.13.2 Send2Trash 1.8.3 session_info 1.0.0 setuptools 75.3.0 shellingham 1.5.4 shiboken6 6.8.0.2 six 1.16.0 sniffio 1.3.1 soupsieve 2.6 srsgui 0.4.6 srsinst.rga 0.3.5 stack-data 0.6.3 statsmodels 0.14.4 stdlib-list 0.11.0 tbb 2022.0.0 tcmlib 1.2.0 terminado 0.18.1 thorlabs-apt-device 0.3.8 threadpoolctl 3.5.0 tinycss2 1.4.0 tomlkit 0.13.2 tornado 6.4.1 tqdm 4.67.0 traitlets 5.14.3 trove-classifiers 2024.10.21.16 types-python-dateutil 2.9.0.20241003 typing_extensions 4.12.2 tzdata 2024.2 umf 0.9.1 uri-template 1.3.0 urllib3 2.2.3 virtualenv 20.27.1 wcwidth 0.2.13 webcolors 24.8.0 webencodings 0.5.1 websocket-client 1.8.0 zhinst 24.10.0 zhinst-core 24.10.64896 zhinst-timing-models 24.10.64896 zhinst-toolkit 0.7.0 zhinst-utils 0.5.0 ```

PyPI doesn't have 0.18.3 for some reason, what needs to be done to get that version uploaded? I believe I can download the release here from github to try and see if it works

@liam-clink
Copy link
Author

Ok, I got 0.18.3 by following the README instructions. But I had installed dpctl as a dependency of dpnp, that's why it was installed the default way. However, even after I did this, I still have the problem:

PS C:\Users\liam> python
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dpctl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\dpctl\__init__.py", line 30, in <module>
    from ._device_selection import select_device_with_aspects
  File "C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\dpctl\_device_selection.py", line 20, in <module>
    from ._sycl_device import SyclDevice, SyclDeviceCreationError
ImportError: DLL load failed while importing _sycl_device: The specified module could not be found.
>>>

@liam-clink
Copy link
Author

New pip list after update to 0.18.3 pip list Package Version ------------------------- -------------- anndata 0.11.0 anyio 4.6.2.post1 argon2-cffi 23.1.0 argon2-cffi-bindings 21.2.0 array_api_compat 1.9.1 arrow 1.3.0 asttokens 2.4.1 async-lru 2.0.4 attrs 24.2.0 babel 2.16.0 beautifulsoup4 4.12.3 bleach 6.2.0 build 1.2.2.post1 CacheControl 0.14.1 certifi 2024.8.30 cffi 1.17.1 charset-normalizer 3.4.0 cleo 2.1.0 colorama 0.4.6 comm 0.2.2 contourpy 1.3.0 crashtest 0.4.1 cupy 13.3.0 cycler 0.12.1 Cython 3.0.11 debugpy 1.8.8 decorator 5.1.1 defusedxml 0.7.1 distlib 0.3.9 dpcpp-cpp-rt 2025.0.3 dpctl 0.18.3 dpnp 0.16.0 dulwich 0.22.5 executing 2.1.0 fastjsonschema 2.20.0 fastrlock 0.8.2 filelock 3.16.1 fonttools 4.54.1 fqdn 1.5.1 h11 0.14.0 h5py 3.12.1 httpcore 1.0.6 httpx 0.27.2 idna 3.10 installer 0.7.0 intel-cmplr-lib-rt 2025.0.3 intel-cmplr-lib-ur 2025.0.3 intel-cmplr-lic-rt 2025.0.3 intel-opencl-rt 2025.0.3 intel-openmp 2025.0.3 intel-sycl-rt 2025.0.3 ipykernel 6.29.5 ipython 8.29.0 isoduration 20.11.0 jaraco.classes 3.4.0 jaraco.context 6.0.1 jaraco.functools 4.1.0 jedi 0.19.1 Jinja2 3.1.4 joblib 1.4.2 json5 0.9.25 jsonpointer 3.0.0 jsonref 1.1.0 jsonschema 4.23.0 jsonschema-specifications 2024.10.1 jupyter_client 8.6.3 jupyter_core 5.7.2 jupyter-events 0.10.0 jupyter-lsp 2.2.5 jupyter_server 2.14.2 jupyter_server_terminals 0.5.3 jupyterlab 4.3.0 jupyterlab_pygments 0.3.0 jupyterlab_server 2.27.3 keyboard 0.13.5 keyring 25.5.0 kiwisolver 1.4.7 legacy-api-wrap 1.4 llvmlite 0.43.0 MarkupSafe 3.0.2 matplotlib 3.9.2 matplotlib-inline 0.1.7 mistune 3.0.2 mkl 2025.0.0 mkl_fft 1.3.11 mkl_random 1.2.8 mkl-service 2.4.2 mkl_umath 0.1.2 more-itertools 10.5.0 msgpack 1.1.0 mudata 0.3.1 natsort 8.4.0 nbclient 0.10.0 nbconvert 7.16.4 nbformat 5.10.4 nest-asyncio 1.6.0 networkx 3.4.2 notebook 7.2.2 notebook_shim 0.2.4 numpy 1.26.4 onemkl-sycl-blas 2025.0.0 onemkl-sycl-dft 2025.0.0 onemkl-sycl-lapack 2025.0.0 onemkl-sycl-rng 2025.0.0 onemkl-sycl-stats 2025.0.0 onemkl-sycl-vm 2025.0.0 opencv-python 4.10.0.84 overrides 7.7.0 packaging 24.2 pandas 2.2.3 pandocfilters 1.5.1 parso 0.8.4 patsy 0.5.6 pexpect 4.9.0 pillow 11.0.0 pip 24.3.1 pip-review 1.3.0 pkginfo 1.11.2 platformdirs 4.3.6 plumbum 1.9.0 poetry 1.8.4 poetry-core 1.9.1 poetry-plugin-export 1.8.0 prometheus_client 0.21.0 prompt_toolkit 3.0.48 protobuf 5.28.3 psutil 6.1.0 ptyprocess 0.7.0 pure_eval 0.2.3 PyAudio 0.2.14 pycparser 2.22 pyelftools 0.31 pyft232 0.12 Pygments 2.18.0 pyluxcoretools 2.9a1.post3 pynndescent 0.5.13 pyparsing 3.2.0 pyproject_hooks 1.2.0 PyQt5 5.15.11 PyQt5-Qt5 5.15.2 PyQt5_sip 12.15.0 PyQt6-Qt6 6.7.3 PyQt6_sip 13.8.0 pyqtgraph 0.13.7 pyserial 3.5 PySide6_Addons 6.8.0.2 PySide6_Essentials 6.8.0.2 python-dateutil 2.9.0.post0 python-json-logger 2.0.7 pytz 2024.2 pyusb 1.2.1 PyVISA 1.14.1 pywin32 308 pywin32-ctypes 0.2.3 pywinpty 2.0.14 PyYAML 6.0.2 pyzmq 26.2.0 RapidFuzz 3.10.1 referencing 0.35.1 requests 2.32.3 requests-toolbelt 1.0.0 rfc3339-validator 0.1.4 rfc3986-validator 0.1.1 rpds-py 0.21.0 rpyc 6.0.1 scikit-learn 1.5.2 scipy 1.14.1 seaborn 0.13.2 Send2Trash 1.8.3 session_info 1.0.0 setuptools 75.3.0 shellingham 1.5.4 shiboken6 6.8.0.2 six 1.16.0 sniffio 1.3.1 soupsieve 2.6 srsgui 0.4.6 srsinst.rga 0.3.5 stack-data 0.6.3 statsmodels 0.14.4 stdlib-list 0.11.0 tbb 2022.0.0 tbb4py 2022.0.0 tcmlib 1.2.0 terminado 0.18.1 thorlabs-apt-device 0.3.8 threadpoolctl 3.5.0 tinycss2 1.4.0 tomlkit 0.13.2 tornado 6.4.1 tqdm 4.67.0 traitlets 5.14.3 trove-classifiers 2024.10.21.16 types-python-dateutil 2.9.0.20241003 typing_extensions 4.12.2 tzdata 2024.2 umf 0.9.0 uri-template 1.3.0 urllib3 2.2.3 virtualenv 20.27.1 wcwidth 0.2.13 webcolors 24.8.0 webencodings 0.5.1 websocket-client 1.8.0 zhinst 24.10.0 zhinst-core 24.10.64896 zhinst-timing-models 24.10.64896 zhinst-toolkit 0.7.0 zhinst-utils 0.5.0

@liam-clink
Copy link
Author

Python 3.12 was installed using the standard windows installer from python.org

The dependent libraries, as found by https://github.com/lucasg/Dependencies for C:\Users\liam\AppData\Roaming\Python\Python312\site-packages\dpctl\DPCTLSyclInterface.dll are

C:\Windows\system32\kernel32.dll
C:\Windows\system32\MSVCP140.dll
C:\Program Files (x86)\Intel\oneAPI\2025.0\bin\libmmd.dll
C:\Program Files (x86)\Intel\oneAPI\2025.0\bin\sycl8.dll
C:\Windows\system32\VCRUNTIME140.dll
C:\Windows\system32\ucrtbase.dll

@oleksandr-pavlyk
Copy link
Collaborator

@liam-clink Please try the following code, to check if the fix would work. Save the following snippet into a script "test.py"

import os
import os.path

as.add_dll_directory(os.path.join("C:", "Program Files (x86)", "Intel", "oneAPI", "2025.0", "bin"))

import dpctl
dpctl.lspltform(verbosity=1)

and execute python test.py. It should run without errors. Please report one way or the other.

It would be helpful if you could verify whether "C:\Users\liam\AppData\Roaming\Python\Library\bin" directory exists, and contains sycl8.dll. If it does not exist, could you please use File Explorer to identify the directory under "C:\Users\liam\AppData\Roaming\Python" that contains "sycl8.dll" library.

Thank you

@oleksandr-pavlyk
Copy link
Collaborator

@liam-clink Did the suggested solution help, if you've got a chance to try it?

@liam-clink
Copy link
Author

I had to fix typos, but this was the output:

Python 3.12.8 (tags/v3.12.8:2dc476b, Dec  3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.add_dll_directory("C:\\Program Files (x86)\\Intel\\oneAPI\\2025.0\\bin")
<AddedDllDirectory('C:\\Program Files (x86)\\Intel\\oneAPI\\2025.0\\bin')>
>>> import dpctl
>>> dpctl.lspltform(verbosity=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'dpctl' has no attribute 'lspltform'. Did you mean: 'lsplatform'?
>>> dpctl.lsplatform(verbosity=1)
Platform  0 ::
    Name        Intel(R) oneAPI Unified Runtime over Level-Zero
    Version     1.6
    Vendor      Intel(R) Corporation
    Backend     ext_oneapi_level_zero
    Num Devices 1
Platform  1 ::
    Name        Intel(R) OpenCL Graphics
    Version     OpenCL 3.0
    Vendor      Intel(R) Corporation
    Backend     opencl
    Num Devices 1
>>>

@oleksandr-pavlyk
Copy link
Collaborator

Ok, so the work-around worked. I am glad to hear it.

I will reproduce the issue locally and see if it can be made to work out of the box.

Meanwhile, dpctl==0.18.3 should work out of the box in virtual env (it contains the fix of gh-1745).

@oleksandr-pavlyk
Copy link
Collaborator

Here is the result of my investigation.

Environment

I installed Python 3.12 downloaded from Python Software Foundation website, and installed into %HOMEPATH%\Python_PSF\Python312 folder.

I installed dpctl using

Python_PSF\Python312\Scripts\pip3.exe install --index https://software.repos.intel.com/python/pypi dpctl==0.18.3
Output of pip list
C:\Users\opavlyk>Python_PSF\Python312\Scripts\pip3.exe list
Package            Version
------------------ --------
dpctl              0.18.3
intel-cmplr-lib-rt 2025.0.3
intel-cmplr-lib-ur 2025.0.3
intel-cmplr-lic-rt 2025.0.3
intel-openmp       2025.0.3
intel-sycl-rt      2025.0.3
mkl                2025.0.0
mkl_fft            1.3.11
mkl_random         1.2.8
mkl-service        2.4.2
mkl_umath          0.1.2
numpy              1.26.4
pip                24.3.1
tbb                2022.0.0
tbb4py             2022.0.0
tcmlib             1.2.0
umf                0.9.0

Work-around for being able to import dpctl

Since the Python bare layout does not contain <prefix>\Library\bin folder, Python interpreter is not looking into that folder for possible native extensions' dependencies. Hence in order to make dpctl importable, we must use os.add_dll_directory to add that folder to the search path:

C:\Users\opavlyk>.\Python_PSF\Python312\python.exe
Python 3.12.8 (tags/v3.12.8:2dc476b, Dec  3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> os.add_dll_directory(os.path.join(sys.exec_prefix, "Library", "bin"))
<AddedDllDirectory('C:\\Users\\opavlyk\\Python_PSF\\Python312\\Library\\bin')>
>>> import dpctl
>>> dpctl.__version__
'0.18.3'
>>> dpctl.lsplatform(verbosity=1)
Platform  0 ::
    Name        Intel(R) OpenCL
    Version     OpenCL 3.0 WINDOWS
    Vendor      Intel(R) Corporation
    Backend     opencl
    Num Devices 1
Platform  1 ::
    Name        Intel(R) FPGA Emulation Platform for OpenCL(TM)
    Version     OpenCL 1.2 Intel(R) FPGA SDK for OpenCL(TM), Version 20.3
    Vendor      Intel(R) Corporation
    Backend     opencl
    Num Devices 1
>>> quit()

The machine where these commands were executed does not have GPU, so only a CPU and FPGA emulator devices are visible.

@oleksandr-pavlyk
Copy link
Collaborator

Just to make it clear, that oneAPI installation was not necessary to make dpctl work. All run-time dependencies were installed in the prefix already.

@liam-clink Feel free to close if you issue has been resolved.

@liam-clink
Copy link
Author

What about using a GPU with one of codeplay's addons? I believe those require an installation like this

@oleksandr-pavlyk
Copy link
Collaborator

@liam-clink Yes, library ur_adapter_cuda.dll provided by CodePlay's oneAPI for NVidia would need to be copied into <prefix>\Library\bin folder.

If it makes it easier to use dpctl by supplying all DPC++ runtime libraries from oneAPI installation, that is valid mode of usage (the one I use myself for development).

@liam-clink
Copy link
Author

One last question, why doesn't dpctl search this Python path by default? Since this is a normal recommended way to install dpctl

@oleksandr-pavlyk
Copy link
Collaborator

This is a very good question to ask. For security reasons, Python searches for DLLs needed by native Python extensions in a restricted number of folders since version 3.8.

DPC++ runtime libraries are installed in a common folder in Python prefix so that they can be reused by other extensions using DPC++, but this common location is not searched by Python itself by default, hence the need to use add_dll_directory.

Please refer to https://bugs.python.org/issue43173

Note, that for conda, CPython is modified to look into $CONDA_PREFIX\Library\bin. For virtual environment, the fix for gh-1745 adds the needed directory using add_dll_library automatically.

@oleksandr-pavlyk
Copy link
Collaborator

oleksandr-pavlyk commented Dec 16, 2024

One more thing, @liam-clink . If you intend to use dpctl to target CUDA devices, the project has to be built for nvptx64-nvidia-cuda SYCL target.

Bits currently available in PyPI only target SPIR64 devices, i.e., Intel GPUs and x86-64 CPUs.

Since you have the oneAPI installed, and assuming you also installed oneAPI for NVidia as well it is pretty straightforward to build dpctl yourself to target CUDA devices.

Please let me know and I would provide further details. But meanwhile, see #1124

The command to build dpctl on Windows would be identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants