ACER Laptop with RTX3070. Installed CUDA, cuDNN, Tensorflow.
Tensorflow detecting GPU.
CUDA test script detecting GPU and shows GPU stats.
Trying to run this jit script to test GPU computing but getting errors. Any help will truly be appreciated.
Script:
from numba import jit, cuda
import numpy as np
# to measure exec time
from timeit import default_timer as timer
# normal function to run on cpu
def func(a):
for i in range(10000000):
a[i] += 1
# function optimized to run on gpu
@jit(target_backend='cuda')
def func2(a):
for i in range(10000000):
a[i] += 1
if __name__ == "__main__":
n = 10000000
a = np.ones(n, dtype=np.float64)
start = timer()
func(a)
print("without GPU:", timer() - start)
start = timer()
func2(a)
print("with GPU:", timer() - start)
Error:
"C:Program FilesPython310python.exe" E:ProgrammingProjectsCUDATestingGPU.py
without GPU: 1.1927146000000448
Traceback (most recent call last):
File "E:ProgrammingProjectsCUDATestingGPU.py", line 30, in <module>
func2(a)
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoredispatcher.py", line 442, in _compile_for_args
raise e
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoredispatcher.py", line 375, in _compile_for_args
return_val = self.compile(tuple(argtypes))
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoredispatcher.py", line 905, in compile
cres = self._compiler.compile(args, return_type)
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoredispatcher.py", line 80, in compile
status, retval = self._compile_cached(args, return_type)
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoredispatcher.py", line 94, in _compile_cached
retval = self._compile_core(args, return_type)
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoredispatcher.py", line 103, in _compile_core
self.targetdescr.options.parse_as_flags(flags, self.targetoptions)
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoreoptions.py", line 41, in parse_as_flags
opt._apply(flags, options)
File "C:UsersFaheemAppDataRoamingPythonPython310site-packagesnumbacoreoptions.py", line 66, in _apply
raise KeyError(m)
KeyError: "Unrecognized options: {'target_backend'}. Known options are dict_keys(['_dbg_extend_lifetimes', '_dbg_optnone', '_nrt', 'boundscheck', 'debug', 'error_model', 'fastmath', 'forceinline', 'forceobj', 'inline', 'looplift', 'no_cfunc_wrapper', 'no_cpython_wrapper', 'no_rewrites', 'nogil', 'nopython', 'parallel'])"
Process finished with exit code 1
3
Thanks for the reply. I looked at url you provided about setting target / target_backend. In my case i simply removed the target completely and it worked. Here is code:
Previous Code
@jit(target_backend=cuda)
def func2(a):
for i in range(100000000):
a[i] += 1
Modified Code
@jit
def func2(a):
for i in range(100000000):
a[i] += 1
It worked. The CPU and GPU computation outputs are:
without GPU: 11.673872300001676
with GPU: 0.19822520000161603
Process finished with exit code 0
4