-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Frontend kernel/function structure checking #536
Comments
If I want to add multi-return support, is there any suggestions? |
Oh that would be great! We might need to think about types: @ti.func
def foo(x):
if x > 0:
return int(x)
else:
return float(x) What should be the return type in this case? We should do some type checking to prevent the ambiguity from happening. One solution could be using type hints: @ti.func
def foo(x) -> float:
if x > 0:
return int(x)
else:
return float(x) Note that we need an AST transform that translates the function above into @ti.func
def foo(x) -> float:
ret = float(0)
if x > 0:
ret = int(x)
else:
ret = float(x)
return ret Note that we probably also need to support |
In the following case, @ti.all_archs
def test_return():
@ti.kernel
def kernel():
@ti.func
def func():
return 233
print(func())
return 1
print(kernel()) we will visit both |
Please disallow function definition within taichi kernels as well :-) |
fix TI_PRINT_PROCESSED no visit_Return from taichi-dev#536
fix TI_PRINT_PROCESSED no visit_Return from taichi-dev#536
I think a solution may be first to check if the function has multi-return with different types, and if the answer is yes, raise an error to tell the user to convert these types explicitly. |
An example of allowing different return types with implicit conversions (only between subclasses and superclasses, disallowing conversion between basic types like |
Ideally, we can support the following two cases at the same time: @ti.func
def foo(x) -> float:
if x > 0:
return int(x)
else:
return float(x) @ti.func
def foo(x):
if x > 0:
return float(int(x))
else:
return float(x) |
I would actually challenge you guys to think about a bigger problem: how to support function definition/calls in Taichi IR. Currently, the function ( |
Does IR have goto statements? If so, we can simulate function call stacks. Also sloved the problem that GLSL doesn't support recursion.( |
No, no goto support needed. Simulating function call stacks is pretty advanced :-) For the first step, we should simply consider supporting CPU/CUDA where recursion is supported by the backend compiler. It's more like a program representation issue within Taichi IR. For example, you might need to implement
|
Correct. Let's simply make recursion a limitation for OpenGL backend for now. And FuncDefStmt is something like OffloadStmt? |
Yeah sort of. We may also need a new IRNode (something like |
Yes, actually I suggest that we make functions inline by default unless marked as |
I believe main function ( |
I guess it's fairly easy to support |
Exactly. LLVM already handles that. Nothing to worry about in that direction :-) |
Warning: The issue has been out-of-update for 50 days, marking |
The text was updated successfully, but these errors were encountered: