File: let_in_rdom_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 (32 lines) | stat: -rw-r--r-- 794 bytes parent folder | download | duplicates (3)
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
#include "Halide.h"

using namespace Halide;

int main(int argc, char **argv) {
    // RDoms sanitize the input expressions to ensure there are no
    // free variables in them. Check that this doesn't apply to
    // internal variables created by lets.
    Param<int> p;
    Var x;
    RDom r(0, Halide::Internal::Let::make(x.name(), (p + 8) / p, x * x));
    Func f;
    f(x) = 0;
    f(x) += r;

    p.set(3);
    int rdom_bound = (3 + 8) / 3;
    rdom_bound *= rdom_bound;
    Buffer<int> buf = f.realize({10});

    int correct = (rdom_bound * (rdom_bound - 1)) / 2;

    for (int i = 0; i < 10; i++) {
        if (buf(i) != correct) {
            printf("buf(%d) = %d instead of %d\n", i, buf(i), correct);
            return 1;
        }
    }

    printf("Success!\n");
    return 0;
}