File: assertion_failure_in_parallel_for.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,096 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"
#include <atomic>
#include <stdio.h>

using namespace Halide;

std::atomic<bool> error_occurred{false};

void halide_error(JITUserContext *ctx, const char *msg) {
    printf("Expected: %s\n", msg);
    error_occurred = true;
}

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

    Param<int> split("split");

    f(x, y) = x + y;
    h(x, y) = f(x, y);
    g(x, y) = h(x % split, y % split) + 1;

    g.tile(x, y, xi, yi, split, split).parallel(y);

    // Force a heap allocation inside the parallel for loop over y.
    f.compute_at(g, y);

    // Make a use of it inside the loop over x
    h.compute_at(g, x);

    // Force an assertion failure inside that for loop if split !=
    // 10. Make sure it fails after the heap allocation of f.
    h.bound(x, 0, 10);

    split.set(11);

    g.jit_handlers().custom_error = halide_error;
    g.realize({40, 40});

    if (!error_occurred) {
        printf("There was supposed to be an error\n");
        return 1;
    }

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