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

Chang API of ti.append and ti.length #5420

Open
neozhaoliang opened this issue Jul 14, 2022 · 1 comment
Open

Chang API of ti.append and ti.length #5420

neozhaoliang opened this issue Jul 14, 2022 · 1 comment
Assignees
Labels
feature request Suggest an idea on this project

Comments

@neozhaoliang
Copy link
Contributor

neozhaoliang commented Jul 14, 2022

Feature 1

The current usage of ti.append and ti.length are quite confusing. They require the users explicitly query the parent node:

import taichi as ti
ti.init()
x = ti.field(int)
block = ti.root.dense(ti.i, 10)
pixel = block.dynamic(ti.j, 10)
pixel.place(x)
@ti.kernel
def test():
    for i in range(10):
        for j in range(i):
            ti.append(x.parent(), i, j)
test()

Shall we change this behaviour to x[i].append(j)?

Feature 2

Support appending struct to dynamic snodes. (currently only 32-bit data is allowed)

Feature 3: auto detect axes

When defining a dynamic snode, one need to explicitly write down the axes:

ti.root.dense(ti.ij, 10).dynamic(ti.k, 10)

Shall we automatically detect the first available axes (with least index) and pend the dynamic snode to this axes?
For example in the above code, ti.k is the first axes below ti.ij, hence we can make ti.k to an optional argument here?

Feature 4: dynamically allocating a dynamic snode

something like this:

@ti.kernel
def test():
    q2 = ti.root.dynamic(10)
    print(len(q))  # Use the __len__ in Python
test()

Feature 5:

Add pop method so that it can return the last active item and then deactivate it.

Feature 6: slicing

support index slicing so that q[start: end] returns a 1D vector field.

@yuanming-hu
Copy link
Member

Features 4 and 6 would be a little hard to implement (considering we need to implement these on GPUs).

In the long run, we should consider feature 4, allowing users to allocate fields in kernels.

@neozhaoliang neozhaoliang moved this from Untriaged to Backlog in Taichi Lang Jul 20, 2022
@neozhaoliang neozhaoliang self-assigned this Jul 20, 2022
lin-hitonami added a commit that referenced this issue Nov 2, 2022
…#6490)

Issue: #5420

### Brief Summary
This PR splits `append` operation of Dynamic SNode to two steps:
1. Allocate the space for the new element, increase the length by one,
and return the address (void *) to the first byte of the new element.
2. Use `GetChStmt` to get the pointer of the element (of the right type)
from the address returned in step 1, and use `GlobalStoreStmt` to store
the value into the address.

**This PR breaks Dynamic SNode on Metal**

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
lin-hitonami added a commit that referenced this issue Nov 4, 2022
Issue: #5420

### Brief Summary
This PR lets `SNodeOpExpression` store `vector<Expr> values` instead of
`Expr value`, and enables passing a struct to `ti.append`.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
lin-hitonami added a commit that referenced this issue Nov 9, 2022
Issue: #5420

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
lin-hitonami added a commit that referenced this issue Nov 28, 2022
Issue: #5420
Just noticed that we forgot to enable getting length of dynamic SNode by
`x[i].length()` along with `append` and `deactivate`
### Brief Summary
lin-hitonami added a commit that referenced this issue Nov 29, 2022
Issue: #5420

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zhao Liang <[email protected]>
Co-authored-by: Olinaaaloompa <[email protected]>
lin-hitonami added a commit to lin-hitonami/taichi that referenced this issue Nov 29, 2022
Issue: taichi-dev#5420
Just noticed that we forgot to enable getting length of dynamic SNode by
`x[i].length()` along with `append` and `deactivate`
### Brief Summary
lin-hitonami added a commit to lin-hitonami/taichi that referenced this issue Nov 29, 2022
Issue: taichi-dev#5420

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zhao Liang <[email protected]>
Co-authored-by: Olinaaaloompa <[email protected]>
lin-hitonami added a commit that referenced this issue Dec 8, 2022
Issue: #5420

### Brief Summary

![image](https://user-images.githubusercontent.com/90667349/206149920-7ce87bda-7c1c-4c59-bd38-a877c660d71a.png)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zhao Liang <[email protected]>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…taichi-dev#6490)

Issue: taichi-dev#5420

### Brief Summary
This PR splits `append` operation of Dynamic SNode to two steps:
1. Allocate the space for the new element, increase the length by one,
and return the address (void *) to the first byte of the new element.
2. Use `GetChStmt` to get the pointer of the element (of the right type)
from the address returned in step 1, and use `GlobalStoreStmt` to store
the value into the address.

**This PR breaks Dynamic SNode on Metal**

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 issue May 13, 2023
Issue: taichi-dev#5420

### Brief Summary
This PR lets `SNodeOpExpression` store `vector<Expr> values` instead of
`Expr value`, and enables passing a struct to `ti.append`.

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 issue May 13, 2023
Issue: taichi-dev#5420

### Brief Summary

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 issue May 13, 2023
Issue: taichi-dev#5420
Just noticed that we forgot to enable getting length of dynamic SNode by
`x[i].length()` along with `append` and `deactivate`
### Brief Summary
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Issue: taichi-dev#5420

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zhao Liang <[email protected]>
Co-authored-by: Olinaaaloompa <[email protected]>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
Issue: taichi-dev#5420

### Brief Summary

![image](https://user-images.githubusercontent.com/90667349/206149920-7ce87bda-7c1c-4c59-bd38-a877c660d71a.png)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zhao Liang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project
Projects
Status: Backlog
Development

No branches or pull requests

2 participants