This source file includes following definitions.
- blur_cols_transpose
- build
#include "Halide.h"
using namespace Halide;
using namespace Halide::BoundaryConditions;
Var x, y, c;
Func blur_cols_transpose(Func input, Expr height, Expr alpha) {
Func blur;
blur(x, y, c) = undef<float>();
blur(x, 0, c) = input(x, 0, c);
RDom ry(1, height - 1);
blur(x, ry, c) =
(1 - alpha)*blur(x, ry - 1, c) + alpha*input(x, ry, c);
Expr flip_ry = height - ry - 1;
blur(x, flip_ry, c) =
(1 - alpha)*blur(x, flip_ry + 1, c) + alpha*blur(x, flip_ry, c);
Func transpose;
transpose(x, y, c) = blur(y, x, c);
Var xo, yo;
transpose.compute_root()
.tile(x, y, xo, yo, x, y, 8, 8)
.vectorize(x)
.parallel(yo)
.parallel(c);
blur.compute_at(transpose, yo);
blur.update(1)
.reorder(x, ry)
.vectorize(x);
blur.update(2)
.reorder(x, ry)
.vectorize(x);
return transpose;
}
class IirBlur : public Generator<IirBlur> {
public:
ImageParam input{Float(32), 3, "input"};
Param<float> alpha{"alpha"};
Func build() {
Expr width = input.width();
Expr height = input.height();
Func input_func;
input_func(x, y, c) = input(x, y, c);
Func blury_T = blur_cols_transpose(input_func, height, alpha);
Func blur = blur_cols_transpose(blury_T, width, alpha);
return blur;
}
};
auto iirblur = RegisterGenerator<IirBlur>("IirBlur");