This source file includes following definitions.
- my_malloc
- my_free
- my_error
- main
#include "Halide.h"
using namespace Halide;
void *my_malloc(void *user_context, size_t x) {
printf("There was not supposed to be a heap allocation\n");
exit(-1);
return nullptr;
}
void my_free(void *user_context, void *ptr) {
}
bool errored = false;
void my_error(void *user_context, const char* msg) {
errored = true;
char expected[] = "Bounds given for f in x (from 0 to 7) do not cover required region (from 0 to 9)";
if (strncmp(expected, msg, sizeof(expected)-1)) {
printf("Unexpected error: '%s'\n", msg);
exit(-1);
}
}
int main(int argc, char **argv) {
{
Func f("f"), g;
Var x("x"), xo, xi;
Param<int> p;
f(x) = x;
g(x) = f(x);
g.split(x, xo, xi, p);
f.compute_at(g, xo).bound_extent(x, 8).vectorize(x);
g.set_custom_allocator(&my_malloc, &my_free);
p.set(5);
g.realize(20);
g.set_custom_allocator(nullptr, nullptr);
g.set_error_handler(&my_error);
p.set(10);
g.realize(20);
if (!errored) {
printf("There was supposed to be an error\n");
return -1;
}
}
{
Func f, g;
Var x, xo, xi;
f(x) = x;
g(x) = f(x);
g.split(x, xo, xi, 8, TailStrategy::GuardWithIf);
f.compute_at(g, xo);
f.bound_extent(x, 8);
g.set_custom_allocator(&my_malloc, &my_free);
g.realize(20);
}
printf("Success!\n");
return 0;
}