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 49 50 51 52 53
|
#include "Halide.h"
using namespace Halide;
int main(int argc, char **argv) {
if (get_jit_target_from_environment().arch == Target::WebAssembly) {
printf("[SKIP] Autoschedulers do not support WebAssembly.\n");
return 0;
}
if (argc != 2) {
fprintf(stderr, "Usage: %s <autoscheduler-lib>\n", argv[0]);
return 1;
}
load_plugin(argv[1]);
int W = 800;
int H = 800;
Buffer<uint16_t> input(W, H);
for (int y = 0; y < input.height(); y++) {
for (int x = 0; x < input.width(); x++) {
input(x, y) = rand() & 0xfff;
}
}
Var x("x"), y("y"), c("c");
Func f("f");
f(x, y, c) = print_when(x < 0, input(x, y) * input(c, c));
Func g("g");
g(x, y) = (f(x, y, input(x, y) % 10) + f(x + 1, y, (input(x, y) - 1) % 10)) / 2;
// Provide estimates on the pipeline output
g.set_estimate(x, 0, input.width() - 1).set_estimate(y, 0, input.height());
// Auto-schedule the pipeline
Target target = get_jit_target_from_environment();
Pipeline p(g);
p.auto_schedule(target);
// Inspect the schedule
g.print_loop_nest();
// Run the schedule
Buffer<uint16_t> out = p.realize({input.width() - 1, input.height()});
printf("Success!\n");
return 0;
}
|