This source file includes following definitions.
- my_malloc
- my_free
- main
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
size_t expected_allocation = 0;
void *my_malloc(void *user_context, size_t x) {
if (x != expected_allocation) {
printf("Error! Expected allocation of %zu bytes, got %zu bytes\n", expected_allocation, x);
exit(-1);
}
return malloc(x);
}
void my_free(void *user_context, void *ptr) {
free(ptr);
}
int main(int argc, char **argv) {
Var x, y, c;
Func f("f"), g;
f(x, y, c) = 1;
g(x, y, c) = f(x, y, c);
f.compute_root().reorder_storage(c, x, y);
g.set_custom_allocator(my_malloc, my_free);
int W = 10;
int H = 11;
expected_allocation = (3*W*H + 1)*sizeof(int);
g.realize(W, H, 3);
int x_alignment = 16;
f.align_storage(x, x_alignment);
int W_aligned = (W + x_alignment - 1) & ~(x_alignment - 1);
expected_allocation = (W_aligned*H*3 + 1)*sizeof(int);
g.compute_root();
g.realize(W, H, 3);
printf("Success!\n");
return 0;
}