From b9248b278256e4728859ae5ace926e1a6b3e9a8a Mon Sep 17 00:00:00 2001 From: Lukasz Wawrzyniak Date: Fri, 27 Sep 2024 13:08:54 -0700 Subject: [PATCH] Fix initialization error when setting struct members --- CHANGELOG.md | 1 + warp/codegen.py | 3 +++ warp/tests/test_implicit_init.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5d0c47d..8922abcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ - Fix conditions not being evaluated as expected in `while` statements. - Fix printing Boolean and 8-bit integer values. - Fix array interface type strings used for Boolean and 8-bit integer values. +- Fix initialization error when setting struct members. ## [1.3.3] - 2024-09-04 diff --git a/warp/codegen.py b/warp/codegen.py index 235d0616..03732010 100644 --- a/warp/codegen.py +++ b/warp/codegen.py @@ -409,6 +409,9 @@ def __init__(self, cls, key, module): elif issubclass(var.type, ctypes.Array): fields.append((label, var.type)) else: + # HACK: fp16 requires conversion functions from warp.so + if var.type is warp.float16: + warp.init() fields.append((label, var.type._type_)) class StructType(ctypes.Structure): diff --git a/warp/tests/test_implicit_init.py b/warp/tests/test_implicit_init.py index e9daef58..6d06ac31 100644 --- a/warp/tests/test_implicit_init.py +++ b/warp/tests/test_implicit_init.py @@ -347,6 +347,34 @@ class TestImplicitInitIsPeerAccessSupported(unittest.TestCase): ) +# Structs +# ------------------------------------------------------------------------------ + + +def test_struct_member_init(test, device): + @wp.struct + class S: + # fp16 requires conversion functions from warp.so + x: wp.float16 + v: wp.vec3h + + s = S() + s.x = 42.0 + s.v = wp.vec3h(1.0, 2.0, 3.0) + + +class TestImplicitInitStructMemberInit(unittest.TestCase): + pass + + +add_function_test( + TestImplicitInitStructMemberInit, + "test_struct_member_init", + test_struct_member_init, + check_output=False, +) + + if __name__ == "__main__": # Do not clear the kernel cache or call anything that would initialize Warp # since these tests are specifically aiming to catch issues where Warp isn't