Skip to content

Instantly share code, notes, and snippets.

@mebjas
Created July 11, 2022 08:21
Show Gist options
  • Save mebjas/894a3be39dd72b8b1b736056fb6a9400 to your computer and use it in GitHub Desktop.
Save mebjas/894a3be39dd72b8b1b736056fb6a9400 to your computer and use it in GitHub Desktop.
Weighted sum as division
// Algorithm
Expr numerator = f32(u32(input_a_(x, y)) * u32(coeff_a_(x, y)) +
u32(input_b_(x, y)) * u32(coeff_b_(x, y)));
Expr denominator = u16(coeff_a_(x, y)) + u16(coeff_b_(x, y));
output_(x, y) = u8_sat(numerator / denominator + 0.5f);
// Schedule
Var xi("xi"), yi("yi");
output_.compute_root()
.split(y, y, yi, 32, TailStrategy::ShiftInwards)
.split(x, x, xi, 16, TailStrategy::ShiftInwards)
.vectorize(xi)
.reorder(xi, x, yi, y)
.parallel(y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment