File: early_out.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 (49 lines) | stat: -rw-r--r-- 1,393 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
#include "Halide.h"

using namespace Halide;

int main(int argc, char **argv) {
    // This is a test case that performs an or reduction using a where clause to
    // get early-out behavior on the reduction loop. It triggered two bugs.
    //
    // First, there's a param that's only used in a specialization of a wrapper
    // func, and this wasn't picked up by InferArguments.
    //
    // Second, there's a variable-free condition
    // that feeds into bounds inference (test()), and bounds inference assumed
    // that being variable-free meant it only depended on params and could be
    // lifted out into a bounds expression.
    //
    // Both of these bugs caused compilation failures, so this test just
    // verifies that things compile.

    Param<int> height;

    Var y;

    Func test_rows("test_rows");
    test_rows(y) = y < 100;

    Func test("test");
    test() = cast<bool>(false);
    RDom ry(0, 1024);
    ry.where(!test());
    test() = test_rows(ry);

    Func output;
    output() = select(test(), cast<uint8_t>(0), cast<uint8_t>(1));

    Expr num_slices = (height + 255) / 256;
    Expr slice_size = (height + num_slices - 1) / num_slices;

    test_rows.in()
        .compute_root()
        .specialize(height > slice_size)
        .parallel(y, slice_size, TailStrategy::ShiftInwards);

    output.compile_jit();

    printf("Success!\n");

    return 0;
}