Skip to content

Commit

Permalink
Don't add ring_buffer semaphores if the function is not scheduled as …
Browse files Browse the repository at this point in the history
…async (#8015)

Don't add ring_buffer semaphores if the function is not scheduled as asybc

Co-authored-by: Steven Johnson <srj@google.com>
  • Loading branch information
vksnk and steven-johnson authored Jan 2, 2024
1 parent 6f26b04 commit 8024bdc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/AsyncProducers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,14 @@ class InjectRingBuffering : public IRMutator {
current_index = current_index % f.schedule().ring_buffer();
// Adds an extra index for to the all of the references of f.
body = UpdateIndices(op->name, current_index).mutate(body);
Expr sema_var = Variable::make(type_of<halide_semaphore_t *>(), f.name() + ".folding_semaphore.ring_buffer");
Expr release_producer = Call::make(Int(32), "halide_semaphore_release", {sema_var, 1}, Call::Extern);
Stmt release = Evaluate::make(release_producer);
body = Block::make(body, release);
body = Acquire::make(sema_var, 1, body);

if (f.schedule().async()) {
Expr sema_var = Variable::make(type_of<halide_semaphore_t *>(), f.name() + ".folding_semaphore.ring_buffer");
Expr release_producer = Call::make(Int(32), "halide_semaphore_release", {sema_var, 1}, Call::Extern);
Stmt release = Evaluate::make(release_producer);
body = Block::make(body, release);
body = Acquire::make(sema_var, 1, body);
}
}

return Realize::make(op->name, op->types, op->memory_type, bounds, op->condition, body);
Expand All @@ -747,7 +750,7 @@ class InjectRingBuffering : public IRMutator {
Stmt mutated = mutate(op->body);
mutated = HoistedStorage::make(op->name, mutated);

if (f.schedule().ring_buffer().defined()) {
if (f.schedule().async() && f.schedule().ring_buffer().defined()) {
// Make a semaphore on the stack
Expr sema_space = Call::make(type_of<halide_semaphore_t *>(), "halide_make_semaphore",
{2}, Call::Extern);
Expand Down

0 comments on commit 8024bdc

Please sign in to comment.