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

using namespace Halide;
using namespace Halide::Internal;

int main(int argc, char **argv) {
    // Verify that the realization order is invariant to anything to do with
    // unique_name counters.

    std::vector<std::string> expected;

    for (int i = 0; i < 10; i++) {
        std::map<std::string, Function> env;
        Var x, y;
        Expr s = 0;
        std::vector<Func> funcs(8);
        for (size_t i = 0; i < funcs.size() - 1; i++) {
            funcs[i](x, y) = x + y;
            s += funcs[i](x, y);
            env[funcs[i].name()] = funcs[i].function();
        }
        funcs.back()(x, y) = s;
        env[funcs.back().name()] = funcs.back().function();

        auto r = realization_order({funcs.back().function()}, env).first;
        // Ties in the realization order are supposed to be broken by any
        // alphabetical prefix of the Func name followed by time of
        // definition. All the Funcs in this test have the same name, so it
        // should just depend on time of definition.
        assert(r.size() == funcs.size());
        for (size_t i = 0; i < funcs.size(); i++) {
            if (funcs[i].name() != r[i]) {
                debug(0) << "Unexpected realization order: "
                         << funcs[i].name() << " != " << r[i] << "\n";
            }
        }
    }

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