Skip to content

Commit

Permalink
Don't try to codegen predicated atomic stores
Browse files Browse the repository at this point in the history
By disabling predication if an Atomic node is found.

Fixes #8280.
  • Loading branch information
abadams committed Jun 11, 2024
1 parent 4b67712 commit 358f862
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/VectorizeLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ class PredicateLoadStore : public IRMutator {
return pred;
}

Stmt visit(const Atomic *op) override {
// We don't support codegen for vectorized predicated atomic stores, so
// just bail out.
valid = false;
return op;
}

Expr visit(const Load *op) override {
valid = valid && ((op->predicate.type().lanes() == lanes) || (op->predicate.type().is_scalar() && !expr_uses_var(op->index, var)));
if (!valid) {
Expand Down
23 changes: 22 additions & 1 deletion test/correctness/predicated_store_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,22 @@ int vectorized_predicated_load_lut_test(const Target &t) {
return 0;
}

int predicated_atomic_store_test(const Target &t) {
// We don't support atomic predicated stores, so ensure that we don't
// generate them. See https://github.com/halide/Halide/issues/8280
ImageParam in(Float(32), 1);
Func f;
Var x;
RDom r(0, 20);

f(x) = 0.f;
f(x) += in(r) + x;
f.update().vectorize(x, 8, TailStrategy::GuardWithIf).atomic().parallel(r);

f.compile_jit(t);
return 0;
}

} // namespace

int main(int argc, char **argv) {
Expand Down Expand Up @@ -529,6 +545,11 @@ int main(int argc, char **argv) {
return 1;
}

printf("predicated atomic store test\n");
if (predicated_atomic_store_test(t) != 0) {
return 1;
}

printf("Success!\n");
return 0;
}
}

0 comments on commit 358f862

Please sign in to comment.