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

[type] Fix struct-for on bit_struct #2129

Merged
merged 3 commits into from
Dec 29, 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
4 changes: 3 additions & 1 deletion taichi/transforms/offload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class Offloader {
if (!demotable) {
for (int i = 1; i < path.size(); i++) {
auto snode_child = path[i];
if (snode_child->type == SNodeType::bit_array && i == path.size() - 1) {
if ((snode_child->type == SNodeType::bit_array ||
snode_child->type == SNodeType::bit_struct) &&
i == path.size() - 1) {
continue;
}
auto offloaded_clear_list =
Expand Down
20 changes: 20 additions & 0 deletions tests/python/test_bit_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,23 @@ def verify_val(test_val: ti.ext_arr()):

test_single_bit_struct(16, 16, [5, 5, 6], np.array([15, 5, 20]))
test_single_bit_struct(32, 32, [10, 10, 12], np.array([11, 19, 2020]))


@ti.test(require=ti.extension.quant, debug=True)
def test_bit_struct_struct_for():
block_size = 16
N = 64
cell = ti.root.pointer(ti.i, N // block_size)
ci32 = ti.type_factory_.get_custom_int_type(32, True)
cft = ti.type_factory.custom_float(significand_type=ci32,
scale=4 / (2**15))

x = ti.field(dtype=cft)
cell.dense(ti.i, block_size)._bit_struct(32).place(x)

@ti.kernel
def assign():
for i in x:
x[i] = ti.cast(i, float)

assign()