numba-dpex icon indicating copy to clipboard operation
numba-dpex copied to clipboard

Support for Calling Device Functions from Ufuncs

Open PokhodenkoSA opened this issue 4 years ago • 3 comments

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
    ^

PokhodenkoSA avatar Jan 22 '21 08:01 PokhodenkoSA

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.

reazulhoque avatar Mar 03 '21 20:03 reazulhoque

For this task, the first step is to support @vectorize using the dppy pipeline. #289 addresses this.

reazulhoque avatar Mar 16 '21 20:03 reazulhoque

@reazulhoque please take it as task with @vectorize.

PokhodenkoSA avatar Apr 05 '21 09:04 PokhodenkoSA