Skip to content

Commit

Permalink
[Bug] Fix num_splits in parallel_struct_for (#7121)
Browse files Browse the repository at this point in the history
Issue: fix #7112

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
strongoier and pre-commit-ci[bot] authored Jan 11, 2023
1 parent aa0a2e8 commit 745ddc8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion taichi/codegen/llvm/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,8 @@ void TaskCodeGenLLVM::create_offload_struct_for(OffloadedStmt *stmt,

int list_element_size = std::min(leaf_block->max_num_elements(),
(int64)taichi_listgen_max_element_size);
int num_splits = std::max(1, list_element_size / stmt->block_dim);
int num_splits = std::max(1, list_element_size / stmt->block_dim +
(list_element_size % stmt->block_dim != 0));

auto struct_for_func = get_runtime_function("parallel_struct_for");

Expand Down
37 changes: 37 additions & 0 deletions tests/python/test_struct_for_non_pot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,40 @@ def test_2d():
@test_utils.test(packed=True)
def test_2d_packed():
_test_2d()


def _test_2d_pointer():
block_size, leaf_size = 3, 8
x = ti.field(ti.i32)
block = ti.root.pointer(ti.ij, (block_size, block_size))
block.dense(ti.ij, (leaf_size, leaf_size)).place(x)

@ti.kernel
def activate():
x[7, 7] = 1

activate()

@ti.kernel
def test() -> ti.i32:
res = 0
for I in ti.grouped(x):
res += I[0] + I[1] * 2
return res

ans = 0
for i in range(leaf_size):
for j in range(leaf_size):
ans += i + j * 2

assert ans == test()


@test_utils.test(require=ti.extension.sparse, packed=False)
def test_2d_pointer():
_test_2d_pointer()


@test_utils.test(require=ti.extension.sparse, packed=True)
def test_2d_pointer_packed():
_test_2d_pointer()

0 comments on commit 745ddc8

Please sign in to comment.