Skip to content

prefetch and ring_buffer don't interact well #9459

Description

@abadams

Description

If you prefetch and ring_buffer the same Func, it only prefetches ring slot zero. The repro below produces the IR:

   allocate producer[int32 * 17 * 1 * 2]
   for (consumer.s0.x.xo, 0, (consumer.extent.0/16) + -1) {
    produce producer {
     let t330 = (consumer.s0.x.xo*16) + ((consumer.min.0 + consumer.min.1) + consumer.s0.y.rebased)
     for (producer.s0.x.rebased, 0, 16) {
      producer[((consumer.s0.x.xo % 2)*17) + producer.s0.x.rebased] = producer.s0.x.rebased + t330
     }
    }
    consume producer {
     let t333 = (consumer.s0.x.xo*16) + (consumer.s0.y.rebased*consumer.stride.1)
     for (consumer.s0.x.xi, 0, 15) {
      if (consumer.s0.x.xi <= 11) {
       prefetch(producer, consumer.s0.x.xi + 4, 1, 16)
      }
      consumer[consumer.s0.x.xi + t333] = 
        let t355 = ((consumer.s0.x.xo % 2)*17) + consumer.s0.x.xi in
        producer[t355] + producer[t355 + 1]

     }
    }
   }

Nothing about the prefetch node names xo, even though the actual consumption toggles based on it.

Reproducing case

#include "Halide.h"
using namespace Halide;

int main() {
    Func producer("producer"), consumer("consumer");
    Var x("x"), y("y"), xo("xo"), xi("xi");

    producer(x, y) = x + y;
    consumer(x, y) = producer(x, y) + producer(x + 1, y);

    consumer.compute_root().split(x, xo, xi, 16, TailStrategy::RoundUp);
    producer.compute_at(consumer, xo)
        .hoist_storage(consumer, y)
        .ring_buffer(2);
    consumer.prefetch(producer, xi, xi, 4);

    consumer.compile_to_lowered_stmt("repro.stmt", {}, StmtOutputFormat::Text,
                                     Target("host-no_asserts-no_bounds_query-no_runtime"));
    Buffer<int> out = consumer.realize({64, 4});
    return 0;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions