Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing None to kernels with generic arguments #498

Open
shi-eric opened this issue Feb 5, 2025 · 1 comment
Open

Allow passing None to kernels with generic arguments #498

shi-eric opened this issue Feb 5, 2025 · 1 comment

Comments

@shi-eric
Copy link
Contributor

shi-eric commented Feb 5, 2025

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
@jc211
Copy link

jc211 commented Feb 6, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants