File: scatter.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 (37 lines) | stat: -rw-r--r-- 982 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
#include "Halide.h"
#include <stdio.h>

using namespace Halide;

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

    // Splatter data all over the place
    RDom r(-10, 20);
    f(x, y) = 17;
    f(r, y) = f(r - 1, y) + 100;
    g(x, y) = f(x + 5, y + 5);

    f.compute_root();
    Buffer<int> result = g.realize({10, 1});

    // The init step of f should fill in (-11, 5) -- (14, 5) inclusive, to
    // cover both the reads done by the update step and g

    // The update step of f should cover (-10, 5) -- (9, 5) inclusive, to
    // cover the reduction domain and the reads done by g

    // The output (g) should read (5, 5) -- (14, 5) from that.

    for (int i = 0; i < 10; i++) {
        int correct = i < 5 ? (1617 + i * 100) : 17;
        if (result(i, 0) != correct) {
            printf("Value at %d should have been %d but was instead %d\n", i, correct, result(i, 0));
            return 1;
        }
    }

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