Skip to content

Commit

Permalink
Merge branch 'ccrouzet/fix-while-cond-eval' into 'main'
Browse files Browse the repository at this point in the history
Fix Conditional Evaluation in `while` Statement

See merge request omniverse/warp!743
  • Loading branch information
christophercrouzet committed Sep 23, 2024
2 parents 38e083b + a14f627 commit 54363a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- Fix handling of `stream` argument in `array.__dlpack__()`.
- Fix a bug related to reloading CPU modules.
- Fix a crash when kernel functions are not found in CPU modules.
- Fix conditions not being evaluated as expected in `while` statements.

## [1.3.3] - 2024-09-04

Expand Down
1 change: 1 addition & 0 deletions warp/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,7 @@ def begin_while(adj, cond):
cond_block.body_forward.append(f"start_{cond_block.label}:;")

c = adj.eval(cond)
c = adj.load(c)

cond_block.body_forward.append(f"if (({c.emit()}) == false) goto end_{cond_block.label};")

Expand Down
14 changes: 14 additions & 0 deletions warp/tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,19 @@ def test_shadow_builtin():
wp.expect_eq(sum(wp.vec3(1.0)), 3.0)


@wp.struct
class Iterator:
valid: wp.bool


@wp.kernel(enable_backward=False)
def test_while_condition_eval():
it = Iterator()
it.valid = True
while it.valid:
it.valid = False


class TestCodeGen(unittest.TestCase):
pass

Expand Down Expand Up @@ -657,6 +670,7 @@ class TestCodeGen(unittest.TestCase):

add_kernel_test(TestCodeGen, name="test_call_syntax", kernel=test_call_syntax, dim=1, devices=devices)
add_kernel_test(TestCodeGen, name="test_shadow_builtin", kernel=test_shadow_builtin, dim=1, devices=devices)
add_kernel_test(TestCodeGen, name="test_while_condition_eval", kernel=test_while_condition_eval, dim=1, devices=devices)


if __name__ == "__main__":
Expand Down

0 comments on commit 54363a8

Please sign in to comment.