Skip to content

Commit

Permalink
stack limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-hitonami committed Nov 17, 2023
1 parent b26cc11 commit fc9083b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/lang/articles/kernels/kernel_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ Taichi real functions are Taichi functions that are compiled into separate funct
The code inside the Taichi real function are executed serially, which means that you cannot write parallel loop inside it.
However, if the real function is called inside a parallel loop, the real function will be executed in parallel along with other parts of the parallel loop.

If you want to do deep runtime recursion on CUDA, you may need to increase the stack size by passing `cuda_stack_limit` to `ti.init()`.

Taichi real functions are only supported on the LLVM-based backends (CPU and CUDA backends).

### Arguments
Expand Down Expand Up @@ -344,8 +346,11 @@ Return values of a Taichi real function can be scalars, `ti.types.matrix()`, `ti

The example below calls the real function `sum_func` recursively to calculate the sum of `1` to `n`.
Inside the real function, there are two `return` statements, and the recursion depth is not a constant number.
The cuda stack limit is set to `32768` to allow deep runtime recursion.

```python skip-ci:ToyDemo
ti.init(arch=ti.cuda, cuda_stack_limit=32768)

```python
@ti.real_func
def sum_func(n: ti.i32) -> ti.i32:
if n == 0:
Expand All @@ -357,7 +362,6 @@ def sum(n: ti.i32) -> ti.i32:
return sum_func(n)

print(sum(100)) # 5050

```

You can find more examples of the real function in the [repository](https://github.com/taichi-dev/taichi/tree/master/python/taichi/examples/real_func).
Expand Down

0 comments on commit fc9083b

Please sign in to comment.