File: concat.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 (48 lines) | stat: -rw-r--r-- 1,178 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Halide.h"

using namespace Halide;

int count[2];
extern "C" HALIDE_EXPORT_SYMBOL int call_counter(int slot, int val) {
    count[slot]++;
    return val;
}
HalideExtern_2(int, call_counter, int, int);

int main(int argc, char **argv) {
    count[0] = count[1] = 0;

    Func f, g, h;
    Var x;

    f(x) = call_counter(0, x + 1);
    g(x) = call_counter(1, x + 2);
    h(x) = select(x < 100, f(x), g(x));

    // While f and g are loaded over the entire range of h, f only
    // needs to be correct where x < 100, and g only needs to be
    // correct where x >= 100, so there should be a mismatch between
    // bounds computed and bounds allocated.

    f.compute_root();
    g.compute_root();
    h.compute_root();

    Buffer<int> buf = h.realize({200});

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

    if (count[0] != 100 || count[1] != 100) {
        printf("Incorrect counts: %d %d\n", count[0], count[1]);
        return 1;
    }

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