This source file includes following definitions.
- generate
#include "Halide.h"
namespace {
class Pyramid : public Halide::Generator<Pyramid> {
public:
GeneratorParam<int> levels{"levels", 1};
Input<Func> input{ "input", Float(32), 2 };
Output<Func[]> pyramid{ "pyramid", Float(32), 2 };
void generate() {
Var x{"x"}, y{"y"};
pyramid.resize(levels);
pyramid[0](x, y) = input(x, y);
for (size_t i = 1; i < pyramid.size(); i++) {
Func p = pyramid[i-1];
pyramid[i](x, y) = (p(2*x, 2*y) +
p(2*x+1, 2*y) +
p(2*x, 2*y+1) +
p(2*x+1, 2*y+1))/4;
}
schedule = [=]() mutable {
for (Func p : pyramid) {
p.parallel(y);
const int v = natural_vector_size<float>();
p.specialize(p.output_buffer().width() >= v).vectorize(x, v);
}
};
}
std::function<void()> schedule;
};
Halide::RegisterGenerator<Pyramid> register_my_gen{"pyramid"};
}