warp icon indicating copy to clipboard operation
warp copied to clipboard

Allow passing `None` to kernels with generic arguments

Open shi-eric opened this issue 11 months ago • 1 comments

Kernels with generic arguments like wp.array(dtype=Any) currently cannot be provided with None for these generic arguments even though it should be possible.

from typing import Any

import warp as wp

wp.init()


@wp.kernel
def foo(
    in_values: wp.array(dtype=Any),
    out: wp.array(dtype=Any),
):
    tid = wp.tid()

    if not in_values:
        return

    out[tid] = in_values[tid]


out = wp.ones(10, dtype=wp.float32)

values = None

wp.launch(foo, dim=out.shape, inputs=(values,), outputs=(out,))

Output:

  File "/home/eshi/code-projects/warp/warp/context.py", line 5490, in launch
    kernel = kernel.add_overload(fwd_types)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eshi/code-projects/warp/warp/context.py", line 715, in add_overload
    raise TypeError(
TypeError: Kernel foo argument 'in_values' cannot be generic, got arraytyping.Any

shi-eric avatar Feb 05 '25 16:02 shi-eric

Adding this enhancement may also allow warp.sim.State and warp.sim.Control to be marked as wp.struct and thus passed directly into kernels?

jc211 avatar Feb 06 '25 18:02 jc211