-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lang] MatrixType refactor: Support matrix slice (#6430)
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]>
- Loading branch information
1 parent
b1a3583
commit c273503
Showing
12 changed files
with
213 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.