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

Improve garbage collection #6803

Open
lucifer1004 opened this issue Dec 5, 2022 · 1 comment
Open

Improve garbage collection #6803

lucifer1004 opened this issue Dec 5, 2022 · 1 comment
Assignees
Labels
feature request Suggest an idea on this project

Comments

@lucifer1004
Copy link
Contributor

Currently, Taichi does not seem to reclaim unusable fields.

For example, the following code can easily lead to OOM.

import taichi as ti

ti.init(arch=ti.vulkan)


@ti.data_oriented
class Container:
    def __init__(self):
        self.f = ti.field(ti.f32, shape=100000000)

    @ti.kernel
    def do(self):
        for i in self.f:
            self.f[i] = i


for i in range(100):
    Container().do()

And this could be solved by calling ti.init() multiple times:

import taichi as ti


@ti.data_oriented
class Container:
    def __init__(self):
        self.f = ti.field(ti.f32, shape=100000000)

    @ti.kernel
    def do(self):
        for i in self.f:
            self.f[i] = i


for i in range(100):
    ti.init(arch=ti.vulkan)
    Container().do()

Despite the workaround, I think it is worth that Taichi could do some garbage collection. In the example above, it should be easy to figure out that the Container instance created in one loop will not be used any more.

@lucifer1004 lucifer1004 added the feature request Suggest an idea on this project label Dec 5, 2022
@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Dec 5, 2022
@turbo0628 turbo0628 moved this from Untriaged to Todo in Taichi Lang Dec 9, 2022
@lin-hitonami
Copy link
Contributor

Taichi does not have automatic garbage collection for fields right now, but you can allocate and destroy fields manually using FieldsBuilder. See https://docs.taichi-lang.org/docs/layout#manual-field-allocation-and-destruction for more information.

@FantasyVR FantasyVR moved this from Todo to Backlog in Taichi Lang Dec 16, 2022
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

3 participants