-
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
[Lang] MatrixType refactor part 2: add more ops #6425
Conversation
✅ Deploy Preview for docsite-preview ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Issue: #5819 ### Brief Summary A slice actually corresponds to several indices. Let's take a look at the following example: ```python import taichi as ti ti.init(real_matrix=True, real_matrix_scalarize=True, print_ir=True) @ti.kernel def foo(): c = ti.Vector([1, 2, 3, 4, 5]) print(c[:4:2]) foo() ``` `c[:4:2]` is a "partially selected vector with length 2" which contains references to `c[0]` and `c[2]`. Let's represent it with `c[(0), (2), shape=2]`. This PR does the following: - expands slices into groups of indices in Python; - extends `IndexExpression` to accept a group of indices; - creates `MatrixOfMatrixPtrStmt` to represent a "partially selected matrix" in CHI IR; - eliminates `MatrixOfMatrixPtrStmt` in the `lower_matrix_ptr()` pass. Frontend IR and CHI IR of the above example: ``` [I 10/25/22 19:54:51.885 816603] [compile_to_offloads.cpp:operator()@22] [foo_c80_0] Initial IR: kernel { $0 = alloca @tmp0 @tmp0 = [1, 2, 3, 4, 5] (dt=[Tensor (5) i32]) $2 = alloca @TMP1 @TMP1 = @tmp0 print @TMP1[(0), (2), shape=(2)], "\n" } [I 10/25/22 19:54:51.885 816603] [compile_to_offloads.cpp:operator()@22] [foo_c80_0] Lowered: kernel { <[Tensor (5) i32]> $0 = alloca <i32> $1 = const 1 <i32> $2 = const 2 <i32> $3 = const 3 <i32> $4 = const 4 <i32> $5 = const 5 <[Tensor (5) i32]> $6 = [$1, $2, $3, $4, $5] $7 : local store [$0 <- $6] <[Tensor (5) i32]> $8 = alloca $9 = local load [$0] $10 : local store [$8 <- $9] <i32> $11 = const 0 <*i32> $12 = shift ptr [$8 + $11] <i32> $13 = const 2 <*i32> $14 = shift ptr [$8 + $13] <[Tensor (2) i32]> $15 = matrix of matrix ptr [$12, $14] $16 = local load [$15] print $16, "\n" } ``` Some tests of matrix slice haven't been enabled yet because they require `x.transpose()`, which depends on #6425. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Zhanlue Yang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think the decorators need another refactor. However, this shouldn't be blocking and I can help with that after all the attributes are finalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other parts LGTM.
Co-authored-by: Zhanlue Yang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
### Brief Summary Foreach check in PR #6425 is verbose. This PR simplifies the usage. Co-authored-by: Yi Xu <[email protected]>
Issue: taichi-dev#5819 ### Brief Summary This PR only contains the valid case and a corresponding test. More comprehensive tests will be enabled once taichi-dev#6425 is in. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Issue: taichi-dev#5478 taichi-dev#5819 ### Brief Summary Co-authored-by: Yi Xu <[email protected]> Co-authored-by: Zhanlue Yang <[email protected]>
Issue: taichi-dev#5819 ### Brief Summary The use of atomic ops in taichi-dev#6425 is unnecessary. This PR removes those usage and simplifies logic around reduction ops.
### Brief Summary Foreach check in PR taichi-dev#6425 is verbose. This PR simplifies the usage. Co-authored-by: Yi Xu <[email protected]>
Issue: #5478 #5819
Brief Summary