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

[Bug] [ir] Fix compilation crash when there's a cross-offload global atomic operation #1392

Merged
merged 3 commits into from
Jul 4, 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
24 changes: 12 additions & 12 deletions taichi/transforms/offload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ class FixCrossOffloadReferences : public BasicStmtVisitor {
}

void visit(AtomicOpStmt *stmt) override {
if (!stmt->dest->is<AllocaStmt>()) {
generic_visit(stmt);
return;
}
if (visit_operand(stmt, stmt->locate_operand(&stmt->val)))
throw IRModified();
TI_ASSERT(stmt->width() == 1);
Expand Down Expand Up @@ -442,8 +446,8 @@ class FixCrossOffloadReferences : public BasicStmtVisitor {
}
}
if (op->is<GlobalPtrStmt>()) {
TI_ASSERT(!op->has_global_side_effect());
auto copy = op->clone();
copy->as<GlobalPtrStmt>()->activate = false;
stmt_to_offloaded[copy.get()] = stmt_to_offloaded[stmt];
stmt->set_operand(index, copy.get());
stmt->insert_before_me(std::move(copy));
Expand All @@ -462,9 +466,7 @@ class FixCrossOffloadReferences : public BasicStmtVisitor {
return true;
}

// Generic visitor
void visit(Stmt *stmt) override {
TI_ASSERT(stmt->width() == 1);
void generic_visit(Stmt *stmt) {
int n_op = stmt->num_operands();
bool modified = false;
for (int i = 0; i < n_op; i++) {
Expand All @@ -475,15 +477,13 @@ class FixCrossOffloadReferences : public BasicStmtVisitor {
throw IRModified();
}

void visit(Stmt *stmt) override {
TI_ASSERT(stmt->width() == 1);
generic_visit(stmt);
}

void preprocess_container_stmt(Stmt *stmt) override {
int n_op = stmt->num_operands();
bool modified = false;
for (int i = 0; i < n_op; i++) {
if (visit_operand(stmt, i))
modified = true;
}
if (modified)
throw IRModified();
generic_visit(stmt);
}

public:
Expand Down
20 changes: 19 additions & 1 deletion tests/python/test_offload_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def ker():
assert ret[None] == 10


@ti.archs_excluding(ti.opengl) # OpenGL doesn't support dynamic range for now
@ti.all_archs
def test_offload_with_flexible_bounds():
s = ti.var(ti.i32, shape=())
lower = ti.var(ti.i32, shape=())
Expand All @@ -90,3 +90,21 @@ def ker():
ker()

assert s[None] == 29 * 10 // 2


@ti.all_archs
def test_offload_with_cross_block_globals():
ret = ti.var(ti.f32)

ti.root.place(ret)

@ti.kernel
def ker():
ret[None] = 0
for i in range(10):
ret[None] += i
ret[None] += 1

ker()

assert ret[None] == 46