Skip to content

Commit

Permalink
[bug] Fix the mapping from virtual axes to physical axes again
Browse files Browse the repository at this point in the history
  • Loading branch information
strongoier committed Oct 12, 2021
1 parent bfa5c28 commit 51106ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions taichi/transforms/scalar_pointer_lowerer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void ScalarPointerLowerer::run() {
if (path_length_ == 0)
return;

auto *leaf_snode = snodes_[path_length_ - 1];
Stmt *last = lowered_->push_back<GetRootStmt>(snodes_[0]);
for (int i = 0; i < path_length_; i++) {
auto *snode = snodes_[i];
Expand All @@ -72,8 +73,8 @@ void ScalarPointerLowerer::run() {
std::vector<int> strides;
// extract lowered indices
for (int k_ = 0; k_ < (int)indices_.size(); k_++) {
int k = snode->physical_index_position[k_];
if (k < 0)
int k = leaf_snode->physical_index_position[k_];
if (!snode->extractors[k].active)
continue;
Stmt *extracted;
if (packed_) { // no dependence on POT
Expand Down
15 changes: 15 additions & 0 deletions tests/python/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def test_indices():
# Note that b is column-major:
# the virtual first index exposed to the user comes second in memory layout.

@ti.kernel
def fill():
for i, j in b:
b[i, j] = i * 10 + j

@ti.kernel
def get_field_addr(i: ti.i32, j: ti.i32) -> ti.u64:
return ti.get_addr(b, [i, j])

fill()
for i in range(16):
for j in range(32):
assert b[i, j] == i * 10 + j
assert get_field_addr(0, 1) + 4 == get_field_addr(1, 1)


@ti.test(arch=ti.get_host_arch_list())
def test_float_as_index():
Expand Down

0 comments on commit 51106ce

Please sign in to comment.