diff --git a/gpuctypes/check_cuda.py b/gpuctypes/check_cuda.py new file mode 100644 index 0000000..1e8367e --- /dev/null +++ b/gpuctypes/check_cuda.py @@ -0,0 +1,22 @@ +import ctypes + +def is_libnvrtc_available(): + try: + ctypes.CDLL("libnvrtc.so") + return True + except OSError: + return False + +def is_libcuda_available(): + try: + ctypes.CDLL("libcuda.so") + return True + except OSError: + return False + +def is_cuda_available(): + if is_libcuda_available() and is_libnvrtc_available(): + pass + else: + raise ImportError("libcuda.so or libnvrtc.so is not available. Please check your CUDA installation!") + diff --git a/gpuctypes/cuda.py b/gpuctypes/cuda.py index acba81c..383a3b0 100644 --- a/gpuctypes/cuda.py +++ b/gpuctypes/cuda.py @@ -6,7 +6,8 @@ # LONGDOUBLE_SIZE is: 16 # import ctypes, ctypes.util - +from gpuctypes.check_cuda import is_cuda_available +is_cuda_available() class AsDictMixin: @classmethod