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
|
#include "Halide.h"
using namespace Halide;
int call_count;
extern "C" HALIDE_EXPORT_SYMBOL int call_counter(int x) {
call_count++;
return x;
}
HalideExtern_1(int, call_counter, int);
int main(int argc, char **argv) {
Func f, g, h;
Var x, y;
// A clone should use the same cache key as the parent, so that
// computations of the clone can reuse computations of the
// parent. This pipeline exploits that to compute f per row of one
// consumer, then retrieve it from cache per row of another
// consumer.
//
// Setting cache size gives you a trade-off between peak memory
// usage and recompute.
f(x, y) = call_counter(x);
g(x, y) = f(x, y) * 2;
h(x, y) = f(x, y) + g(x, y);
h.compute_root();
g.compute_root();
f.clone_in(h).compute_at(h, y).memoize();
f.compute_at(g, y).memoize();
h.bound(x, 0, 1024).bound(y, 0, 32);
call_count = 0;
h.realize({1024, 32});
if (call_count != 1024 * 32) {
printf("call_count was supposed to be 1024 * 32: %d\n", call_count);
return 1;
}
Internal::JITSharedRuntime::release_all();
printf("Success!\n");
return 0;
}
|