I ran this code I read on a CUDA Python intro page:-
import numpy as np
from timeit import default_timer as timer
from numbapro import vectorize
@vectorize(["float32(float32, float32)"], target='gpu')
def VectorAdd(a, b):
return a + b
def main():
N = 32000000
A = np.ones(N, dtype=np.float32)
B = np.ones(N, dtype=np.float32)
C = np.zeros(N, dtype=np.float32)
start = timer()
C = VectorAdd(A, B)
vectoradd_timer = timer() - start
print("C[:5] = " + str(C[:5]))
print("C[-5:] = " + str(C[-5:]))
print("VectorAdd took %f seconds" % vectoradd_timer)
if __name__ == '__main__':
main()
And I am getting the following error on terminal:-
dtn34@dtn34-ubuntu:~/Python$ python asd.py
Traceback (most recent call last):
File "asd.py", line 3, in <module>
from numbapro import vectorize
ImportError: No module named numbapro
It was supposed to run the code using the gpu but I am getting that error. I've installed anaconda, updated conda, installed accelerate using conda, installed cudatoolkit, installed numba using conda. I tried compiling it using both python2 and python3
What do I do?
I tried to run it in both (CPU and GPU) after modifying, the CPU is faster than GPU
first one in CPU:
the time:
the second one in GPU:
the time:
this result depend on the specifications of your CPU.
Got it. As pointed out by WarrenWeckesser and Robert Crovella, NumbaPro has been deprecated and all the features were moved to numba. So instead of numbapro you are supposed to write numba
Also the target needs to be set to 'cuda' instead of 'gpu'