vincefn / pyvkfft

Python interface to VkFFT
MIT License
51 stars 6 forks source link

Cannot import pyvkfft.fft.fftn without OpenCL backends #21

Closed jimmyjamison closed 1 year ago

jimmyjamison commented 1 year ago

I tried install pyvkfft with only cuda backends using VKFFT_BACKEND=CUDA CUDAHOME=/usr/local/cuda pip install pyvkfft

This runs and builds the wheel for pyvkfft without errors. After running, I can import and use the cuda pyvkfft planner without error

$ python
Python 3.9.10 (main, Sep  1 2022, 19:43:27) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvkfft.cuda import VkFFTApp
>>> 

But if I try to import pyvkfft.fft.fftn I get an OSError

$ python
Python 3.9.10 (main, Sep  1 2022, 19:43:27) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvkfft.fft import fftn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../venv/lib/python3.9/site-packages/pyvkfft/fft.py", line 28, in <module>
    from .opencl import VkFFTApp as VkFFTApp_cl, cla, vkfft_version
  File ".../venv/lib/python3.9/site-packages/pyvkfft/opencl.py", line 15, in <module>
    _vkfft_opencl = load_library("_vkfft_opencl")
  File ".../venv/lib/python3.9/site-packages/pyvkfft/base.py", line 117, in load_library
    return ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__) or os.path.curdir, basename + ext))
  File ".../Python-3.9.10/Lib/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File ".../Python-3.9.10/Lib/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: .../venv/lib/python3.9/site-packages/pyvkfft/_vkfft_opencl.cpython-39-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

Looking at the code for pyvkfft.fft it looks like it tries to handle the case where the OpenCL backend isn't installed https://github.com/vincefn/pyvkfft/blob/d75c620d9d1fdd91d06454439a7d731f7166de70/pyvkfft/fft.py#L27-L33 only I get an OSError not ImportError.

If I install pyvkfft with both OpenCL and cuda backends using CUDAHOME=/usr/local/cuda pip install pyvkfft things work

$ python
Python 3.9.10 (main, Sep  1 2022, 19:43:27) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyvkfft.fft import fftn
>>> 

but I'd like to use pyvkfft with only the Cuda backends installed.