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

cache loop invariant global vars pass induces incorrect results #8576

Open
erizmr opened this issue Aug 1, 2024 · 0 comments
Open

cache loop invariant global vars pass induces incorrect results #8576

erizmr opened this issue Aug 1, 2024 · 0 comments
Assignees

Comments

@erizmr
Copy link
Contributor

erizmr commented Aug 1, 2024

A small repro on current Taichi master branch (37a0563):

import taichi as ti

ti.init(print_ir=True, print_ir_dbg_info = False)

x = ti.Vector.field(3, float, shape=5)

@ti.kernel
def repro():
    # ti.loop_config(serialize=True)
    for i in range(5):
        x[i][2] = x[i][2] + 1.0
        for j in range(1):
            x[i][2] = x[i][2] - 5.0
            print("x value ", x[i][2])
            for z in range(1):
                idx = 0
                if z == 0:
                    idx = 2
                x_print = x[i][idx]
                print("x value inside ", x_print)
                print("x value inside direct access", x[i][2])

repro()

it can be observed that x value != x value inside

x value  -4.000000
x value inside  1.000000
x value inside direct access -4.000000
x value  -4.000000
x value inside  1.000000
x value inside direct access -4.000000
x value  -4.000000
x value inside  1.000000
x value inside direct access -4.000000
x value  -4.000000
x value inside  1.000000
x value inside direct access -4.000000
x value  -4.000000
x value inside  1.000000
x value inside direct access -4.000000

The results are correct if set cache_loop_invariant_global_vars=False however it is set to True by default.

After some investigation, I found it seems that the bug is induced by inaccurate checking of whether a pointer is uniquely accessed in an offload task. The code is in function is_offload_unique of cache_loop_invariant_global_vars.cpp. It seems that x[i][2] should not be identified as uniquely accessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants