File: vectorized_assert.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 (46 lines) | stat: -rw-r--r-- 978 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
#include "Halide.h"

using namespace Halide;

int error_count = 0;
void my_error(JITUserContext *ucon, const char *msg) {
    error_count++;
}

int main(int argc, char **argv) {
    Func f("f"), g("g");
    Var x("x");
    Param<int> p;

    f(x) = x;
    f(x) += 1;
    g(x) = f(x) + f(2 * x + p);

    g.vectorize(x, 8);
    f.bound_storage(x, 32);
    // No way to check this at compile time. The size of f depends on both x and
    // p.  An assert is injected, but the assert is inside g's vectorized loop.

    g.jit_handlers().custom_error = my_error;

    g.compile_jit();

    // Will trigger the assert
    p.set(256);
    g.realize({128});
    if (error_count != 1) {
        printf("There should have been an error\n");
        return 1;
    }

    // Will not trigger the assert
    p.set(0);
    g.realize({8});
    if (error_count != 1) {
        printf("There should not have been an error\n");
        return 1;
    }

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