Hi,
i wondered wether i can use numpy within a cuda kernel?
@cuda.jit
def matmul(A, B, C):
"""Perform square matrix multiplication of C = A * B
"""
i, j = cuda.grid(2)
if i < C.shape[0] and j < C.shape[1]:
tmp = 0.
for k in range(A.shape[1]):
tmp += A[i, k] * B[k, j]
C[i, j] = tmp
a = math.sin(1.23456)
b = np.sin(1.23456)
I added the last two lines, it workes fine with "a = math.sin(1.23456)" but i get an error for b = np.sin(1.23456)
numba.errors.UntypedAttributeError: Failed at nopython (nopython frontend)
Unknown attribute 'sin' of type Module(<module 'numpy' from 'C:\\Python\\WinPython-64bit-3.4.4.1\\python-3.4.4.amd64\\lib\\site-packages\\numpy\\__init__.py'>)
File "test numba.py", line 80
[1] During: typing of get attribute at C:\...\test numba.py (80)
I want to work with arrays within a kernel or within a divice. It should look like this:
@cuda.jit(device=True)
def cross(a, b):
c = np.empty((3,))
c[0] = a[1]*b[2] - a[2]*b[1]
c[1] = a[2]*b[0] - a[0]*b[2]
c[2] = a[0]*b[1] - a[1]*b[0]
return c
This gives me an error for "c = np.empty((3,))"
As far as i understood, all the variables (like tmp) will be in the 32-bit registers.
Is it possible to put (numpy) arrays on the registers, like
@cuda.jit
def test(A, B, C):
a = np.ones((3, 3)) #array in the register
Many thanks!