lebedov / scikit-cuda

Python interface to GPU-powered libraries
http://scikit-cuda.readthedocs.org/
Other
975 stars 179 forks source link

switch back to using ctypes.util.find_library to find library paths to fix LD_LIBRARY_PATH handling #293

Open lebedov opened 4 years ago

lebedov commented 4 years ago

In Python 3.7.*, ctypes.util.find_library appears to be able to find full library paths even when LD_LIBRARY_PATH is used whereas the code in 4781f2e2aa317c3218f9ce1e226a09d7be81af59 (based on ctypes from an earlier version of Python) can't always use directory info in LD_LIBRARY_PATH properly.

ccoulombe commented 4 years ago

On linux with python 3.7.4, only the filename is returned:

~ $ python -V
Python 3.7.4
~ $ python -c "from ctypes.util import find_library; print(find_library('cudart'))"
libcudart.so.10.1

That is also what the doc says :

It returns the filename of the library file. https://docs.python.org/3.7/library/ctypes.html#finding-shared-libraries

A suggestion would be to use the CUDA_ROOT environment variable that is defined :

ctypes.cdll.LoadLibrary(os.path.join(os.environ['CUDA_ROOT'], 'lib64', find_library('cudart')))

This would work on different system including HPC systems where CUDA is not necessarily installed in a standard location.