numba-dpex
numba-dpex copied to clipboard
Support for Calling Device Functions from Ufuncs
dpex ufunc kernels cannot be called from other dpex device functions.
Example:
@dppy.func
def a_device_function(a):
return a + 1
@vectorize(nopython=True)
def ufunc_kernel(x, y):
return a_device_function(x) + y
def test_ufunc():
N = 10
dtype = np.float64
A = np.arange(N, dtype=dtype)
B = np.arange(N, dtype=dtype) * 10
context = get_context()
with dpctl.device_context(context):
C = ufunc_kernel(A, B)
print(C)
Output:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name 'a_device_function': cannot determine Numba type of <class 'numba_dppy.compiler.DPPYFunctionTemplate'>
File "numba_dppy/examples/vectorize_func.py", line 14:
def ufunc_kernel(x, y):
return a_device_function(x) + y
^
One possible reason is we are not adding the function template to the typing context of CPU target. DPPY has only one target that represents the dppy device. In case of @njit
calling device functions (through prange, arrary expressions and vectorize) also require a target representing the CPU. It is missing currently. #74.
For this task, the first step is to support @vectorize
using the dppy pipeline. #289 addresses this.
@reazulhoque please take it as task with @vectorize
.