File: invalid_gpu_loop_nests.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 (103 lines) | stat: -rw-r--r-- 3,074 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "Halide.h"
#include <iostream>

using namespace Halide;

void check_error(bool error) {
    if (!error) {
        std::cout << "There was supposed to be an error!\n";
        exit(1);
    }
}

int main(int argc, char **argv) {
#if HALIDE_WITH_EXCEPTIONS
    if (!Halide::exceptions_enabled()) {
        std::cout << "[SKIP] Halide was compiled without exceptions.\n";
        return 0;
    }

    Target t = get_jit_target_from_environment();
    if (!t.has_gpu_feature()) {
        std::cout << "[SKIP] No GPU target enabled.\n";
        return 0;
    }

    Var v0, v1, v2, v3, v4, v5, v6, v7;
    Param<bool> p;
    for (int i = 0;; i++) {
        Func f{"f"}, g{"g"};
        f(v0, v1, v2, v3, v4, v5, v6, v7) = v0;
        g(v0, v1, v2, v3, v4, v5, v6, v7) = f(v0, v1, v2, v3, v4, v5, v6, v7);
        switch (i) {
        case 0:
            // Threads but no blocks on an output Func
            g.gpu_threads(v0);
            break;
        case 1:
            // Threads but no blocks on a compute_root non-output Func
            f.compute_root().gpu_threads(v0);
            g.gpu_blocks(v1).gpu_threads(v0);
            break;
        case 2:
            // Too many blocks loops
            g.gpu_blocks(v0, v1).gpu_blocks(v2, v3);
            break;
        case 3:
            // Too many threads loops
            g.gpu_threads(v0, v1).gpu_threads(v2, v3).gpu_blocks(v4);
            break;
        case 4:
            // Threads outside of blocks
            g.gpu_blocks(v0).gpu_threads(v1);
            break;
        case 5:
            // Something with a blocks loop compute_at inside something else with a blocks loop
            g.gpu_blocks(v0);
            f.compute_at(g, v0).gpu_blocks(v0);
            break;
        case 6:
            // Something compute_at between two gpu_blocks loops
            g.gpu_blocks(v0, v1);
            f.compute_at(g, v1);
            break;
        case 7:
            // Something with too many threads loops once nesting is taken into account
            g.gpu_threads(v0, v1).gpu_blocks(v2, v3);
            f.compute_at(g, v0).gpu_threads(v0, v1);
            break;
        case 8:
            // The same, but only in a specialization
            g.gpu_threads(v0, v1).gpu_blocks(v2, v3);
            f.compute_at(g, v0).gpu_threads(v0).specialize(p).gpu_threads(v1);
            break;
        case 9:
            // A serial loop in between two gpu blocks loops
            g.gpu_blocks(v5, v7);
            break;
        default:
            std::cout << "Success!\n";
            return 0;
        }

        bool error = false;
        try {
            g.compile_jit();
        } catch (const Halide::CompileError &e) {
            error = true;
            std::cout << "Expected compile error:\n"
                      << e.what() << "\n";
        }

        if (!error) {
            printf("There should have been an error\n");
            return 1;
        }
    }

    // unreachable
#else
    std::cout << "[SKIP] Halide was compiled without exceptions.\n";
    return 0;
#endif
}