This source file includes following definitions.
- main
#include "Halide.h"
using namespace Halide;
using std::vector;
using std::pair;
int main(int argc, char **argv) {
Func input;
Var x, y;
input(x, y) = random_float();
input.compute_root();
const int levels = 20;
Func pyr_down[levels];
Param<int> width, height;
vector<pair<Expr, Expr> > sizes(levels);
sizes[0] = { width, height };
for (int i = 1; i < levels; i++) {
sizes[i] = { (sizes[i-1].first + 1)/2, (sizes[i-1].second + 1)/2 };
}
pyr_down[0] = input;
for (int i = 1; i < levels; i++) {
Func bounded = BoundaryConditions::repeat_edge(pyr_down[i-1], {{0, sizes[i].first}, {0, sizes[i].second}});
Func downsampled;
downsampled(x, y) = bounded(2*x-1, 2*y-1) + bounded(2*x+2, 2*y+2);
pyr_down[i](x, y) = select(max(sizes[i].first, sizes[i].second) > 5,
downsampled(x, y),
0.0f);
pyr_down[i].compute_root()
.specialize(max(width, height) > 32)
.vectorize(x, 16)
.parallel(y, 16, TailStrategy::GuardWithIf);
}
Func pyr_up[levels];
pyr_up[levels-1] = pyr_down[levels-1];
for (int i = levels-2; i >= 0; i--) {
Func upsample;
upsample(x, y) = pyr_up[i+1](x/2 - 1, y/2 - 1) + pyr_up[i+1](x/2 + 1, y/2 + 1);
pyr_up[i](x, y) = select(max(sizes[i].first, sizes[i].second) > 5,
pyr_down[i](x, y) - upsample(x, y),
pyr_down[i](x, y));
pyr_up[i].compute_root()
.specialize(max(width, height) > 32)
.vectorize(x, 16)
.parallel(y, 16, TailStrategy::GuardWithIf);
}
width.set(1000);
height.set(1000);
pyr_up[0].realize(1000, 1000);
return 0;
}