File: multipass_constraints.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 (51 lines) | stat: -rw-r--r-- 1,491 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
49
50
51
#include "Halide.h"
#include <stdio.h>

using namespace Halide;

int main(int argc, char **argv) {
    ImageParam in(Float(32), 2, "in");

    Func out("out");
    Var x("x"), y("y");

    out(x, y) = in(x + 1, y + 1) + in(x - 1, y - 1);
    out(x, y) += 3.0f;
    out.update().vectorize(x, 4);

    OutputImageParam o = out.output_buffer();

    // Now make some hard-to-resolve constraints
    in.dim(0).set_bounds(in.dim(1).min() - 5, in.dim(1).extent() + o.dim(0).extent());

    o.dim(0).set_bounds(0, select(o.dim(0).extent() < 22, o.dim(0).extent() + 1, o.dim(0).extent()));

    // Make a bounds query buffer
    Buffer<float> out_buf(nullptr, 7, 8);
    out_buf.set_min(2, 2);

    out.infer_input_bounds(out_buf);

    if (in.get().dim(0).min() != -4 ||
        in.get().dim(0).extent() != 34 ||
        in.get().dim(1).min() != 1 ||
        in.get().dim(1).extent() != 10 ||
        out_buf.dim(0).min() != 0 ||
        out_buf.dim(0).extent() != 24 ||
        out_buf.dim(1).min() != 2 ||
        out_buf.dim(1).extent() != 8) {

        printf("Constraints not correctly satisfied:\n"
               "in: %d %d %d %d\n"
               "out: %d %d %d %d\n",
               in.get().dim(0).min(), in.get().dim(0).extent(),
               in.get().dim(1).min(), in.get().dim(1).extent(),
               out_buf.dim(0).min(), out_buf.dim(0).extent(),
               out_buf.dim(1).min(), out_buf.dim(1).extent());

        return 1;
    }

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