1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include "Halide.h"
#include <atomic>
#include <stdio.h>
using namespace Halide;
std::atomic<bool> error_occurred{false};
void halide_error(JITUserContext *ctx, const char *msg) {
printf("Expected: %s\n", msg);
error_occurred = true;
}
int main(int argc, char **argv) {
Func f("f"), g("g"), h("h");
Var x("x"), y("y"), xi("xi"), yi("yi");
Param<int> split("split");
f(x, y) = x + y;
h(x, y) = f(x, y);
g(x, y) = h(x % split, y % split) + 1;
g.tile(x, y, xi, yi, split, split).parallel(y);
// Force a heap allocation inside the parallel for loop over y.
f.compute_at(g, y);
// Make a use of it inside the loop over x
h.compute_at(g, x);
// Force an assertion failure inside that for loop if split !=
// 10. Make sure it fails after the heap allocation of f.
h.bound(x, 0, 10);
split.set(11);
g.jit_handlers().custom_error = halide_error;
g.realize({40, 40});
if (!error_occurred) {
printf("There was supposed to be an error\n");
return 1;
}
printf("Success!\n");
return 0;
}
|