Skip to content

PY-NUMB0001 · kernel_return_value

Count explicit values returned from Numba CUDA kernels.

This is a deterministic rule for python. Read its implementation.

Report a return statement with a value inside a module function compiled by cuda.jit as a kernel. CUDA kernels cannot return values to their host caller. Results must be written through an array or device buffer passed to the kernel.

Each finding identifies the returning statement and its kernel. The value is the number of explicit return values in the kernel.

A bare return is accepted because it only stops the current thread. A function compiled with device=True is also accepted because device functions may return values.

@cuda.jit
def total(values):
return values[cuda.grid(1)]
@cuda.jit
def total(values, output):
output[cuda.grid(1)] = values[cuda.grid(1)]
  • Cites “Numba CUDA documentation”, writing CUDA kernels and kernel declaration. Open reference