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

[metal] Fix listgen when iterating over children of a bitmasked SNode #1511

Merged
merged 1 commit into from
Jul 16, 2020
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
8 changes: 5 additions & 3 deletions taichi/backends/metal/shaders/runtime_kernels.metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ STR(
const int child_idx = (ii % num_slots);
const auto parent_elem = parent_list.get<ListgenElement>(parent_idx);
ListgenElement child_elem;
child_elem.root_mem_offset = parent_elem.root_mem_offset +
child_idx * child_stride +
child_meta.mem_offset_in_parent;
child_elem.root_mem_offset =
parent_elem.root_mem_offset + child_idx * child_stride;
// We are testing the activation of *parent* cells, do not add the
// offset of the child within its parent cell here.
if (is_active(root_addr + child_elem.root_mem_offset, parent_meta,
child_idx)) {
refine_coordinates(parent_elem,
runtime->snode_extractors[parent_snode_id],
child_idx, &child_elem);
child_elem.root_mem_offset += child_meta.mem_offset_in_parent;
child_list.append(child_elem);
}
}
Expand Down
35 changes: 35 additions & 0 deletions tests/python/test_bitmasked.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,38 @@ def run():
run()
assert c[None] == 4
assert s[None] == 42


@archs_support_bitmasked
def test_bitmasked_offset_child():
x = ti.var(ti.i32)
y = ti.var(ti.i32)
z = ti.var(ti.i32)
s = ti.var(ti.i32, shape=())

n = 16
# Offset children:
# * In |bm|'s cell: |bm2| has a non-zero offset
# * In |bm2|'s cell: |z| has a non-zero offset
# * We iterate over |z| to test the listgen handles offsets correctly
bm = ti.root.bitmasked(ti.i, n)
bm.dense(ti.i, 2).place(x)
bm2 = bm.bitmasked(ti.i, 4)
bm2.dense(ti.i, 2).place(y)
bm2.bitmasked(ti.i, 4).place(z)

@ti.kernel
def func():
for _ in z:
s[None] += 1

z[0] = 1
z[7] = 1
z[42] = 1
z[53] = 1
z[88] = 1
z[101] = 1
z[233] = 1

func()
assert s[None] == 7