Skip to content

Commit

Permalink
[Lang] Fix local matrix index without assign when real_matrix=True
Browse files Browse the repository at this point in the history
  • Loading branch information
strongoier committed Oct 11, 2022
1 parent 7e2ddaf commit a1374dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions taichi/ir/frontend_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ Stmt *make_tensor_access(Expression::FlattenContext *ctx,
std::vector<int> shape,
int stride) {
flatten_lvalue(var, ctx);
if (!var->is_lvalue()) {
auto alloca_stmt = ctx->push_back<AllocaStmt>(var->ret_type);
ctx->push_back<LocalStoreStmt>(alloca_stmt, var->stmt);
var->stmt = alloca_stmt;
}
bool needs_dynamic_index = false;
for (int i = 0; i < (int)indices.size(); ++i) {
if (!indices[i].is<ConstExpression>()) {
Expand Down
10 changes: 10 additions & 0 deletions tests/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ def get_index(i: ti.i32, j: ti.i32):
assert s[None] == i * 3 + j


@test_utils.test(arch=[ti.cuda, ti.cpu], real_matrix=True)
def test_local_matrix_read_without_assign():
@ti.kernel
def local_vector_read(i: ti.i32) -> ti.i32:
return ti.Vector([0, 1, 2])[i]

for i in range(3):
assert local_vector_read(i) == i


@test_utils.test(arch=[ti.cuda, ti.cpu], real_matrix=True)
def test_local_matrix_indexing_in_loop():
s = ti.field(ti.i32, shape=(3, 3))
Expand Down

0 comments on commit a1374dc

Please sign in to comment.