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

All conditional statements ignored in @ti.func called from @ti.real_func #8514

Open
Sam-Izdat opened this issue Apr 17, 2024 · 1 comment
Open

Comments

@Sam-Izdat
Copy link

Sam-Izdat commented Apr 17, 2024

Describe the bug
All conditional statements are ignored in any @ti.func called from any @ti.real_func. Code is executed as though all conditions evaluate to True. This happens on both Linux and Windows, both on gpu and cpu backends.

To Reproduce

A minimal reproducer:

import taichi as ti

ti.init(arch=ti.cpu)

@ti.func
def f_test() -> float:
	foo = 0.
	if False: foo = 1.
	return foo

@ti.real_func
def rf_test() -> float:
	return f_test()


@ti.kernel
def kern_test() -> float:
	return rf_test()

print(kern_test()) # Prints 1.0

Log/Screenshots

$ python my_sample_code.py
[Taichi] version 1.7.0, llvm 15.0.4, commit 2fd24490, linux, python 3.8.13
[Taichi] Starting on arch=x64
...
[Taichi] version 1.7.0, llvm 15.0.1, commit 2fd24490, win, python 3.8.17
[Taichi] Starting on arch=cuda
...

Additional comments
I assume this is a bug, unless I've badly misunderstood what is and is not UB. I still feel like I'm somehow responsible for this, but I haven't found anything to indicate that what I'm doing is forbidden. The code in this example calls func from real_func:

https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/real_func/graph/stable_fluid_graph.py

@Sam-Izdat
Copy link
Author

Interestingly, ternary operators behave as expected:

@ti.func
def f_test1() -> float:
	foo = 1. if False else 0.
	return foo # returns 0.

@ti.func
def f_test2() -> float:
	foo = 1. if True else 0.
	return foo # returns 1.

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

No branches or pull requests

1 participant