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

add additional checks for cuda library #16

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generate_cuda.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e
clang2py /usr/include/cuda.h /usr/include/nvrtc.h -o gpuctypes/cuda.py -l /usr/lib/x86_64-linux-gnu/libcuda.so -l /usr/lib/x86_64-linux-gnu/libnvrtc.so
sed -i "s\import ctypes\import ctypes, ctypes.util\g" gpuctypes/cuda.py
sed -i "s\import ctypes\import ctypes, ctypes.util, gpuctypes.check_cuda\g" gpuctypes/cuda.py
sed -i "s\ctypes.CDLL('/usr/lib/x86_64-linux-gnu/libcuda.so')\ctypes.CDLL(ctypes.util.find_library('cuda'))\g" gpuctypes/cuda.py
sed -i "s\ctypes.CDLL('/usr/lib/x86_64-linux-gnu/libnvrtc.so')\ctypes.CDLL(ctypes.util.find_library('nvrtc'))\g" gpuctypes/cuda.py
grep FIXME_STUB gpuctypes/cuda.py || true
24 changes: 24 additions & 0 deletions gpuctypes/check_cuda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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!")

is_cuda_available()

2 changes: 1 addition & 1 deletion gpuctypes/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# POINTER_SIZE is: 8
# LONGDOUBLE_SIZE is: 16
#
import ctypes, ctypes.util
import ctypes, ctypes.util, gpuctypes.check_cuda


class AsDictMixin:
Expand Down