Skip to content

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

@Sam-Izdat

Description

@Sam-Izdat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions