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

[Bug] Avoid overwriting global tmp with dynamic_index=True #6820

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions taichi/transforms/offload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,8 @@ class FixCrossOffloadReferences : public BasicStmtVisitor {
auto const_zero_stmt = replacement.push_back<ConstStmt>(zero);
stmt_to_offloaded_[const_zero_stmt] = offloaded;
for (int i = 0; i < tensor_type->get_num_elements(); ++i) {
TypedConstant offset(i *
data_type_size(tensor_type->get_element_type()));
auto const_offset_stmt = replacement.push_back<ConstStmt>(offset);
auto const_offset_stmt =
replacement.push_back<ConstStmt>(TypedConstant(i));
auto ptr_offset_stmt =
replacement.push_back<MatrixPtrStmt>(ptr, const_offset_stmt);
auto global_store_stmt = replacement.push_back<GlobalStoreStmt>(
Expand Down
22 changes: 22 additions & 0 deletions tests/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,3 +1209,25 @@ def foo():
r"`transpose\(\)` cannot apply to a vector. If you want something like `a @ b.transpose\(\)`, write `a.outer_product\(b\)` instead."
):
foo()


@test_utils.test(require=ti.extension.dynamic_index,
dynamic_index=True,
debug=True)
def test_global_tmp_overwrite():
# https://github.com/taichi-dev/taichi/issues/6663
@ti.kernel
def foo() -> ti.i32:
p = ti.Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
loop = 1
sig = ti.Vector([0, 0, 0, 0])
assert p[0, 0] == 1
while loop == 1:
assert p[0, 0] == 1
loop = 0
p[0, 0] = -1
for i in range(1):
sig[i] = 2
return sig.sum() + p.sum()

assert foo() == 4