NVIDIA / warp

A Python framework for high performance GPU simulation and graphics
https://nvidia.github.io/warp/
Other
4.28k stars 243 forks source link

[BUG] from __future__ import annotations breaks warp #256

Closed koen-v closed 4 months ago

koen-v commented 4 months ago

Bug Description

When I add from __future__ import annotations

to a warp script, the kernel wont compile, the first thing I hit is in: python\warp\types.py

;'str' object has no attribute '__module__'

removing the annotations import makes it go away

Thanks, Koen

System Information

Windows 11, Python 3.10

shi-eric commented 4 months ago

A quick look at the issue shows that the type annotations get turned into strings with from __future__ import annotations (postponed evaluation of annotations), which interferes with the Warp Var.type variables created for the kernel parameters. Here's a minimal example :

from __future__ import annotations

import warp as wp

wp.init()

@wp.kernel
def test_kernel(a: wp.array(dtype=wp.float32)):
    i = wp.tid()

test_array = wp.empty(shape=(10,), dtype=wp.float32)

wp.launch(test_kernel, test_array.shape, inputs=[test_array])

wp.synchronize()

@christophercrouzet: Can you look into if we can support this use case?

christophercrouzet commented 4 months ago

Hi @koen-v, thanks for reporting this issue!

We've just merged some changes in e10a583 to add support for from __future__ import annotations. It's available in the branch main for now and will be part of the next release.

koen-v commented 4 months ago

great, thank you!