Created
September 1, 2017 07:39
-
-
Save achimnol/3bc59983d78cf0fa9c5b7841699d4879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import ctypes.util | |
_libcuda = ctypes.CDLL(ctypes.util.find_library('cudart')) | |
if __name__ == '__main__': | |
# You should put the path to the CUDA toolkit library into LD_LIBRARY_PATH envvar | |
# or into the system-wide configuration at /etc/ld.so.conf.d/. | |
count = ctypes.c_int(0) | |
# This will initialize a CUDA device context, | |
# which holds the handle to the device until this program exits. | |
ret = _libcuda.cudaGetDeviceCount(ctypes.byref(count)) | |
assert ret == 0, 'cudaGetDeviceCount() has failed (error code {}).'.format(ret) | |
print('Number of GPUs detected: {}'.format(count.value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment