This source file includes following definitions.
- my_trace
- main
#include "Halide.h"
using namespace Halide;
int num_stores = 0;
int my_trace(void *user_context, const halide_trace_event_t *e) {
if (e->event == halide_trace_store) {
num_stores++;
}
return 0;
}
int main(int argc, char **argv) {
Var x, y;
Func f;
f(x) = sin(x);
Func g;
g(x, y) = undef<float>();
g(x, x) = f(x);
const int iters = 27;
for (int i = 0; i < iters; i++) {
g(x, x+1) = g(x, x);
g(x, x-1) = g(x, x);
g(y, y) = (g(y, y) + g(y-1, y) + g(y+1, y))/3.0f;
}
g.compute_root();
Func h;
h(x) = g(x, x);
int output_extent = 19;
int last_iteration_extent = output_extent;
int first_iteration_extent = output_extent + 2*iters;
int expected = (first_iteration_extent +
iters * (last_iteration_extent + 2 + first_iteration_extent) / 2 +
iters * (last_iteration_extent + 2 + first_iteration_extent) / 2 +
iters * (last_iteration_extent + first_iteration_extent - 2) / 2);
g.trace_stores();
h.set_custom_trace(&my_trace);
h.realize(output_extent);
if (num_stores != expected) {
printf("Did not store to g the right numbers of times\n"
" Expected: %d\n"
" Actual: %d\n",
expected, num_stores);
return -1;
}
printf("Success!\n");
return 0;
}