Hello,
my name is Carl and I would like to speed up some code using the GPU with CUDA. First step seems to be a very big one. I’m coding with Python 3.6, having the latest version of numba (with the latest anaconda package). Today I downloaded the newest CUDA driver, since my GPU is listed as a CUDA supported GPU.
Unfortunately the example code, which is adding two vectors is not working. See the code below.
It throws an error, quite long. Last line of the error says: numba.cuda.cudadrv.error.CudaDriverError: CUDA initialized before forking, which is an error telling me that my device is not supported. But it is, I’ve verified that.
Contacting the nvidia support doesn’t help. They say this must be an apple related problem. Apple doesn’t provide CUDA support and now im here. I will list all useful information at the bottom of this post.
I really appreciate any help!
Carl
Versions:
Mac OS 10.13 (17A405)
GPU: NVIDIA GeForce GT 650M
CUDA Driver: 9.0.197 (not the newest since the support told me explicitly to try this older version)
GPU Driver: 10.24.28 355.11.10.10.10.160
Full code, which is throwing the error:
import numpy as np
import time
from numba import vectorize, cuda
@vectorize(['float32(float32, float32)'], target='cuda')
def VectorAdd(a, b):
return a + b
def main():
N = 3200000
A = np.ones(N, dtype=np.float32)
B = np.ones(N, dtype=np.float32)
start = time.time()
C = VectorAdd(A, B)
vector_add_time = time.time() - start
print("C[:5] = " + str(C[:5]))
print("C[-5:] = " + str(C[-5:]))
print("VectorAdd took for % seconds" % vector_add_time)
if __name__ == '__main__':
main()
Full error:
Traceback (most recent call last):
File “/Users/Carl/Library/Mobile Documents/com~apple~CloudDocs/Mastersthesis/exampleScript.py”, line 26, in
main()
File “/Users/Carl/Library/Mobile Documents/com~apple~CloudDocs/Mastersthesis/exampleScript.py”, line 17, in main
C = VectorAdd(A, B)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/dispatcher.py”, line 88, in call
return CUDAUFuncMechanism.call(self.functions, args, kws)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/npyufunc/deviceufunc.py”, line 290, in call
dev_a = cr.to_device(a, stream=stream)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/dispatcher.py”, line 203, in to_device
return cuda.to_device(hostary, stream=stream)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/devices.py”, line 211, in _require_cuda_context
get_context()
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/devices.py”, line 194, in get_context
return _runtime.get_or_create_context(devnum)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/devices.py”, line 162, in get_or_create_context
return self.push_context(self.gpus[devnum])
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/devices.py”, line 40, in getitem
return self.lst[devnum]
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/devices.py”, line 26, in getattr
numdev = driver.get_device_count()
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py”, line 334, in get_device_count
self.cuDeviceGetCount(byref(count))
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py”, line 268, in getattr
self.initialize()
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py”, line 225, in initialize
self.cuInit(0)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py”, line 288, in safe_cuda_api_call
self._check_error(fname, retcode)
File “/Users/Carl/anaconda3/lib/python3.6/site-packages/numba/cuda/cudadrv/driver.py”, line 322, in _check_error
raise CudaDriverError(“CUDA initialized before forking”)
numba.cuda.cudadrv.error.CudaDriverError: CUDA initialized before forking
Process finished with exit code 1