numba-dpex
numba-dpex copied to clipboard
Consider allowing global variables inside numba-dpex kernel
I have a kernel doing polynomial interpolation of a cubic spline. I want spline coefficients to be a global "constant" COEFFICIENTS, which are read-only in dpnp array.
Instead of passing these COEFFICIENTS as a kernel argument please consider these visible inside kernel. As an extra precaution the check may be implemented that these coefficients are read only inside the kernel. Proper documentation will also say that if another async kernel modifies this global values there is no guarantee that these will be properly updated in this kernel
@ndpex.kernel()
def kernel_polynomial(x, y):
c = ndpex.private.array(DEGREE+1, dtype=float32)
z = ndpex.private.array(1, dtype=float32)
lid = ndpex.get_local_id(0)
c = COEFFICIENTS[lid] # Each work group works with own cubic polynomial
for i in range(lid*N_POINTS_PER_WORK_ITEM, (lid+1)*N_POINTS_PER_WORK_ITEM, 1):
y[i] = ((c[0]*z + c[1])*x + c[2])*x + c[3]
```