pycuda icon indicating copy to clipboard operation
pycuda copied to clipboard

PyCuda can't find DLL

Open Leterax opened this issue 3 years ago • 5 comments

I'm trying to do some interop between pycuda and OpenGL, however, if I try to create a context using import pycuda.gl.autoinit It fails with this error message:

    import pycuda._driver as _drv
ImportError: DLL load failed while importing _driver: The specified module could not be found.

System specs:

> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Feb_14_22:08:44_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.2, V11.2.152
Build cuda_11.2.r11.2/compiler.29618528_0

Windows 10, Python 3.9 Newest Nvidia drivers.

Cuda added itself to PATH, CUDA_PATH, and CUDA_PATH_V11_2

Leterax avatar Mar 26 '21 12:03 Leterax

If i just try to import import pycuda.gl as cuda_gl It tells me PyCUDA was compiled without GL extension support Do i have to build from source to enable GL?

Leterax avatar Mar 26 '21 12:03 Leterax

This seems to have something to do with #213. The suggested fix of adding CUDA_PATH to the dll directory seems to work. Maybe pycuda can do this automatically?

Leterax avatar Mar 26 '21 13:03 Leterax

Maybe pycuda can do this automatically?

It certainly tries to:

https://github.com/inducer/pycuda/blob/29466d4e93ec20a81ce2534327aed24903c3a2e2/pycuda/driver.py#L13-L59

Could you investigate what's happening with that code on your system?

inducer avatar Mar 26 '21 22:03 inducer

This seems to be a problem with the order in which things are executed. When you call from pycuda.gl import autoinit it will first call the init.py file, before anything else! init.py tries to import this: import pycuda._driver as _drv however since neither autoinit from pycuda nor autoinit from pycuda.gl have run it fails. Either by calling from pycuda import autoinit or calling _add_cuda_libdir_to_dll_path in __init__.py this would probably be fixed. Working example here:

>>> import moderngl
>>> ctx = moderngl.create_standalone_context()
>>> from pycuda import autoinit
>>> from pycuda.gl import autoinit
>>> 

Leterax avatar Apr 05 '21 15:04 Leterax

I ran into the same issue today. Can pycuda import autoinit by default?

erwincoumans avatar Apr 18 '23 19:04 erwincoumans