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

[Lang] MatrixType refactor part 2: add more ops #6425

Merged
merged 26 commits into from
Nov 4, 2022

Conversation

AD1024
Copy link
Contributor

@AD1024 AD1024 commented Oct 25, 2022

Issue: #5478 #5819

Brief Summary

@netlify
Copy link

netlify bot commented Oct 25, 2022

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 53bddaa
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/63637444465cc700097bfb41
😎 Deploy Preview https://deploy-preview-6425--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.

strongoier added a commit that referenced this pull request Oct 26, 2022
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]>
@AD1024 AD1024 changed the title [Lang] MatrixType refactor: add more ops (WIP) [Lang] MatrixType refactor: add more ops Oct 27, 2022
@AD1024 AD1024 changed the title [Lang] MatrixType refactor: add more ops [Lang] MatrixType refactor part 2: add more ops Oct 27, 2022
python/taichi/lang/matrix.py Outdated Show resolved Hide resolved
python/taichi/lang/matrix_ops_utils.py Outdated Show resolved Hide resolved
python/taichi/lang/matrix_ops_utils.py Outdated Show resolved Hide resolved
python/taichi/lang/matrix_ops.py Show resolved Hide resolved
@strongoier strongoier added the full-ci Run complete set of CI tests label Oct 31, 2022
Copy link
Contributor

@jim19930609 jim19930609 left a 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.

python/taichi/lang/matrix_ops_utils.py Show resolved Hide resolved
python/taichi/lang/matrix_ops_utils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jim19930609 jim19930609 left a comment

Choose a reason for hiding this comment

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

Other parts LGTM.

strongoier added a commit that referenced this pull request Nov 3, 2022
Issue: #5819

### Brief Summary

This PR only contains the valid case and a corresponding test. More
comprehensive tests will be enabled once #6425 is in.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

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

LGTM!

@strongoier strongoier merged commit ecaf650 into taichi-dev:master Nov 4, 2022
strongoier added a commit that referenced this pull request Nov 7, 2022
Issue: #5819

### Brief Summary

The use of atomic ops in #6425 is unnecessary. This PR removes those
usage and simplifies logic around reduction ops.
strongoier added a commit that referenced this pull request Nov 12, 2022
### Brief Summary

Foreach check in PR #6425 is verbose. This PR simplifies the usage.

Co-authored-by: Yi Xu <[email protected]>
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
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>
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
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.
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
### Brief Summary

Foreach check in PR taichi-dev#6425 is verbose. This PR simplifies the usage.

Co-authored-by: Yi Xu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full-ci Run complete set of CI tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants