Hello.
I’m a newbie with Python and Numba, and I’m quite stuck trying to use even the most basic functions in Numpy (things like empty, zeros or ones). This very simple code, for example:
from numba import cuda
import numba
import numpy as np
@cuda.jit
def my_kernel(G):
G = np.zeros((128, 128), dtype=np.float64)
G_shape = (128, 128)
G = np.empty(G_shape)
d_G = cuda.device_array(G_shape, dtype=np.float64)
threadsperblock=32
blockspergrid = (G.size + (threadsperblock - 1))
my_kernel[blockspergrid, threadsperblock](d_G)
cuda.synchronize()
d_G.copy_to_host(G)
If I try to run it, Numba refuses to compile with this error:
Traceback (most recent call last):
File "test.py", line 18, in <module>
my_kernel[blockspergrid, threadsperblock](d_G)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/cuda/compiler.py", line 798, in __call__
kernel = self.specialize(*args)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/cuda/compiler.py", line 809, in specialize
kernel = self.compile(argtypes)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/cuda/compiler.py", line 825, in compile
**self.targetoptions)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/cuda/compiler.py", line 61, in compile_kernel
cres = compile_cuda(pyfunc, types.void, args, debug=debug, inline=inline)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/cuda/compiler.py", line 50, in compile_cuda
locals={})
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/compiler.py", line 551, in compile_extra
return pipeline.compile_extra(func)
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/compiler.py", line 331, in compile_extra
return self._compile_bytecode()
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/compiler.py", line 393, in _compile_bytecode
return self._compile_core()
File "/home/marc/anaconda3/envs/mudpy/lib/python2.7/site-packages/numba/compiler.py", line 373, in _compile_core
raise e
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Use of unsupported NumPy function 'numpy.zeros' or unsupported use of the function.
File "test.py", line 9:
def my_kernel(G):
G = np.zeros(shape=(128, 128), dtype=np.float64)
^
[1] During: typing of get attribute at test.py (9)
File "test.py", line 9:
def my_kernel(G):
G = np.zeros(shape=(128, 128), dtype=np.float64)
^
According to the documentation, these methods are supported and should work. I’ve tried with and without dtype, I’ve tried with different types (both from Numba and NumPy), different sizes… Nothing seems to work. What am I doing wrong? Can anybody help me, please?
By the way, I’m using Numba 0.47, becauseI’m working with a Python 2.7 code base.
Marc