Skip to content

Commit

Permalink
new FAQ
Browse files Browse the repository at this point in the history
  • Loading branch information
Olinaaaloompa committed Nov 17, 2022
1 parent d734ccd commit 1b4b46f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/lang/articles/faqs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,24 @@ for i in x:
You can call `ti.sync()`, which is similar to CUDA's `cudaStreamSynchronize()`, in Taichi to synchronize the parallel for loops.

`__syncthreads()` is a block-level synchronization barrier, and Taichi provides a synonymous API `ti.simt.block.sync()`, which for now supports CUDA and Vulkan backends only. However, all block-level APIs are still experimental, and you should use this API only when it relates to SIMT operation synchronization and `SharedArray` reads and writes.

### How can I swap elements between two fields in the Taichi scope? `a,b = b,a` does not work.

Direct value assignments lead to semantic ambiguity. For example, `a = b` can mean data copy if `a` is pre-defined, or otherwise can serve to define and initialize `a`.

You can swap two fields in the Taichi scope using a struct for:

```python
@ti.func
def field_copy(src: ti.template(), dst: ti.template()):
for I in ti.grouped(src):
dst[I] = src[I]

@ti.kernel
def test():
# copy b to a
field_copy(b, a)
print(a[0])

test()
```

0 comments on commit 1b4b46f

Please sign in to comment.