Describe the bug
Hello, I seem to find a dangeous trap while using a infinite loop in taichi's function.
I was used to use "return" to break an infinite loop and return what I want simultaneously, however, when it comes to taichi's function, my system CRASHED! It seems that, statement "return" don't break the loop, and finally run out the memory.
To test my guess, every time I ran my program in VScode, my system crashed and I had to restart my computer, therefore, I could not got the error message.
To Reproduce
I make two examples here. Please BE CAUTIOUS, It may run out your memory and your computer may crash
@ti.kernel
def foo1():
foo2()
@ti.func
def foo2():
a = 1
while 1:
a += 1
if a > 10: # when this number is small, my system got extremely slow and taichi would simply quit and print "None"; when a big number, my system crashed.
print(a)# no output
return a
print(foo1())# print "None"
If we put a "break" there, the loop ends normally, but no return value.
@ti.kernel
def foo1():
foo2()
@ti.func
def foo2():
a = 1
while 1:
a += 1
if a > 10:
print(a)# print "11"
break
return a
print(foo1())# print "None"
Environment
I wonder if it is a bug exactly, or simply out of my poor understanding for taichi? Thanks for checking.
Best regards.
This is one of the gotchas in Taichi. Right now you can only have a single, top-level return stmt at the end of a @ti.func, see https://taichi.graphics/docs/develop/documentation/basic/syntax.html#advanced-arguments-2. During the python AST transformation, all functions are inlined, so it's a bit difficult for Taichi's function to support advanced return control flows...
Ok I got it thank you XD.