Skip to content
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

[doc] Update kernel_function #6794

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

[doc] Update kernel_function #6794

wants to merge 10 commits into from

Conversation

vai9er
Copy link
Contributor

@vai9er vai9er commented Dec 2, 2022

Cleaned up wording and Format, added some extra informative code examples the user can interact with to get a better feeling for the concepts, added extra links to core concepts in previous Taichi documentation.

@netlify
Copy link

netlify bot commented Dec 2, 2022

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 95e3a29
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/63a1ea21abc934000907252f
😎 Deploy Preview https://deploy-preview-6794--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@CLAassistant
Copy link

CLAassistant commented Dec 2, 2022

CLA assistant check
All committers have signed the CLA.

@vai9er vai9er changed the title Update kernel_function [doc] Update kernel_function Dec 2, 2022
@vai9er vai9er marked this pull request as draft December 2, 2022 09:27
Copy link
Contributor

@Olinaaaloompa Olinaaaloompa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@neozhaoliang neozhaoliang self-requested a review December 20, 2022 04:03
@neozhaoliang neozhaoliang marked this pull request as ready for review December 20, 2022 04:16
Comment on lines 173 to 192
#### Matrix Fields
We can use the ti.Matrix() function to declare our own [Matrix Field](https://docs.taichi-lang.org/docs/master/field#matrix-fields) and pass it into the kernel. This also works for [Vector Fields](https://docs.taichi-lang.org/docs/master/field#vector-fields)

In the following example, we declare a Matrix Field, generate its values, and pass it into `myKernel()`:

```python
import taichi as ti
ti.init()


@ti.kernel
def myKernel(a: ti.Matrix.field):
for i in ti.grouped(a):
a[i] = [[1,1,1], [1,1,1]]

a = ti.Matrix.field(n=2, m=3, dtype=ti.f32, shape=(2, 2)) #Declares a 2x2 matrix field, with each of its elements being a 3x2 matrix
myKernel(a)
print(a[0][0,0]) #prints 1

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Matrix Fields
We can use the ti.Matrix() function to declare our own [Matrix Field](https://docs.taichi-lang.org/docs/master/field#matrix-fields) and pass it into the kernel. This also works for [Vector Fields](https://docs.taichi-lang.org/docs/master/field#vector-fields)
In the following example, we declare a Matrix Field, generate its values, and pass it into `myKernel()`:
```python
import taichi as ti
ti.init()
@ti.kernel
def myKernel(a: ti.Matrix.field):
for i in ti.grouped(a):
a[i] = [[1,1,1], [1,1,1]]
a = ti.Matrix.field(n=2, m=3, dtype=ti.f32, shape=(2, 2)) #Declares a 2x2 matrix field, with each of its elements being a 3x2 matrix
myKernel(a)
print(a[0][0,0]) #prints 1
```

I'm sorry, Matrix.Field is a function call, not a valid type hint. We should better not mention it here.

@@ -262,7 +342,7 @@ All Taichi functions are force-inlined. Therefore, no runtime recursion is allow

### Arguments

A Taichi function can have multiple arguments, supporting scalar, `ti.Matrix`, `ti.Vector`, `ti.types.ndarray()`, `ti.template()`, `ti.field`, and `ti.Struct` as argument types. Note that some of the restrictions on a kernel's arguments do not apply here:
A Taichi function can have multiple arguments, supporting [Scalar](https://docs.taichi-lang.org/docs/master/field#scalar-fields), [ti.Matrix](https://docs.taichi-lang.org/docs/master/field#matrix-fields), [ti.Vector](https://docs.taichi-lang.org/docs/master/field#vector-fields), `ti.types.ndarray()`, `ti.template()`, and [ti.Struct](https://docs.taichi-lang.org/docs/master/field#struct-fields) as argument types. Note that some of the restrictions on a kernel's arguments do not apply here:
Copy link
Contributor

@neozhaoliang neozhaoliang Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A Taichi function can have multiple arguments, supporting [Scalar](https://docs.taichi-lang.org/docs/master/field#scalar-fields), [ti.Matrix](https://docs.taichi-lang.org/docs/master/field#matrix-fields), [ti.Vector](https://docs.taichi-lang.org/docs/master/field#vector-fields), `ti.types.ndarray()`, `ti.template()`, and [ti.Struct](https://docs.taichi-lang.org/docs/master/field#struct-fields) as argument types. Note that some of the restrictions on a kernel's arguments do not apply here:
A Taichi function can have multiple arguments, supporting [Scalar](https://docs.taichi-lang.org/docs/master/field#scalar-fields), [ti.Matrix](https://docs.taichi-lang.org/docs/master/field#matrix-fields), [ti.Vector](https://docs.taichi-lang.org/docs/master/field#vector-fields), `ti.types.ndarray()`, `ti.template()`, and [ti.Struct](https://docs.taichi-lang.org/docs/master/field#struct-fields) as argument types. Note that some of the restrictions on a kernel's arguments do not apply here:

I'm afraid that Vector and Matrix are not Vector/Matrix fields; the ref links are not leading to the exact places. Can we remove them for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants