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 block dim on bit_structs #2151

Merged
merged 2 commits into from
Jan 12, 2021
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: 3 additions & 5 deletions taichi/codegen/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2041,13 +2041,11 @@ void CodeGenLLVM::create_offload_struct_for(OffloadedStmt *stmt, bool spmd) {
llvm::Function *body = nullptr;
auto leaf_block = stmt->snode;

// When looping over bit_arrays and bit_structs, we generate struct for on
// their parent node (usually "dense") instead of itself for higher
// When looping over bit_arrays, we always vectorize and generate struct for
// on their parent node (usually "dense") instead of itself for higher
// performance. Also, note that the loop must be bit_vectorized for
// bit_arrays, and their parent must be "dense".
if (leaf_block->type == SNodeType::bit_struct) {
leaf_block = leaf_block->parent;
} else if (leaf_block->type == SNodeType::bit_array) {
if (leaf_block->type == SNodeType::bit_array) {
if (leaf_block->parent->type == SNodeType::dense) {
leaf_block = leaf_block->parent;
} else {
Expand Down
4 changes: 3 additions & 1 deletion taichi/transforms/flag_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class WeakenAccess : public BasicStmtVisitor {
}

static SNode *least_sparse_ancestor(SNode *a) {
while (a->type == SNodeType::place || a->type == SNodeType::dense) {
while (a->type == SNodeType::place || a->type == SNodeType::dense ||
a->type == SNodeType::bit_struct ||
a->type == SNodeType::bit_array) {
a = a->parent;
}
return a;
Expand Down
8 changes: 8 additions & 0 deletions taichi/transforms/lower_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ class LowerAST : public IRVisitor {
offsets = snode->index_offsets;
snode = snode->parent;
}

// Climb up one more level if inside bit_struct.
// Note that when looping over bit_structs, we generate
// struct for on their parent node instead of itself for
// higher performance.
if (snode->type == SNodeType::bit_struct)
snode = snode->parent;

auto &&new_for = std::make_unique<StructForStmt>(
snode, std::move(stmt->body), stmt->vectorize, stmt->bit_vectorize,
stmt->parallelize, stmt->block_dim);
Expand Down