File: shadowed_bound.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (34 lines) | stat: -rw-r--r-- 1,144 bytes parent folder | download | duplicates (4)
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
#include "Halide.h"

using namespace Halide;

int main(int argc, char **argv) {
    Func f("f"), g("g");
    Var x, y, c("c");

    f(x, y, c) = x + y + c;

    g(x, y, c) = f(x, y, c) + f(x, y, 3);

    Var xi, yi, ci;
    g.compute_root().tile(x, y, xi, yi, 32, 32);
    f.compute_at(g, x).bound(c, 0, 4).unroll(c);

    g.realize({1024, 1024, 4});

    // f's loop over channels has two bounds. The first outer one
    // comes from its relationship with g - it needs to satisfy
    // however many channels of g are required. The second inner one
    // is the constant range given by the bound directive. These two
    // bounds appear as a shadowed .min/.max variable. We want to
    // ensure simplify_correlated_differences respects the inner const
    // bound instead of substituting in the outer one. The schedule
    // above is a little silly in that it overcomputes f, but it's
    // designed to be just complex enough to tempt
    // simplify_correlated_differences into trying to substitute in
    // the outer bound to cancel the c.

    // It's sufficient to check that we compiled.
    printf("Success!\n");
    return 0;
}