Ejemplo n.º 1
0
    void check(const std::string &inner_loop_level,
               const std::string &outer_loop_level) {
        Buffer<float> result = outer.realize(1, 1, 1);

        Module m = outer.compile_to_module({outer.infer_arguments()});
        CheckLoopLevels c(inner_loop_level, outer_loop_level);
        m.functions().front().body.accept(&c);
    }
Ejemplo n.º 2
0
int main(int argc, char **argv) {
    if (argc < 2) return 1;

    Func grid; Var cmplx,x,y;
    grid(cmplx,x,y) = cast<double>(0.0f);

    // No need for a strategy - LLVM should automatically figure out
    // that this is a memset.

    Target target(get_target_from_environment().os, Target::X86, 64, { Target::SSE41, Target::AVX});
    compile_module_to_object(grid.compile_to_module({}, "kern_init", target), argv[1]);
    return 0;
}
Ejemplo n.º 3
0
int rdom_wrapper_test() {
    Func source("source"), g("g"), result("result");
    Var x("x"), y("y");

    source(x, y) = x + y;
    ImageParam img(Int(32), 2, "img");
    Buffer<int> buf = source.realize(200, 200);
    img.set(buf);

    g(x, y) = 10;
    g(x, y) += 2 * img(x, x);
    RDom r(0, 200, 0, 200);
    g(r.x, r.y) += 3 * img(r.y, r.y);

    // Make a global wrapper on 'g', so that we can schedule initialization
    // and the update on the same compute level at the global wrapper
    Func wrapper = g.in().compute_root();
    g.compute_at(wrapper, x);
    Func img_f = img;
    img_f.compute_root();

    // Check the call graphs.
    // Expect 'wrapper' to call 'g', initialization of 'g' to call nothing
    // and its update to call 'img_f' and 'g', 'img_f' to call 'img'
    Module m = wrapper.compile_to_module({wrapper.infer_arguments()});
    CheckCalls c;
    m.functions().front().body.accept(&c);

    CallGraphs expected = {
        {g.name(), {img_f.name(), g.name()}},
        {wrapper.name(), {g.name()}},
        {img_f.name(), {img.name()}},
    };
    if (check_call_graphs(c.calls, expected) != 0) {
        return -1;
    }

    Buffer<int> im = wrapper.realize(200, 200);
    auto func = [](int x, int y) { return 4*x + 6* y + 10; };
    if (check_image(im, func)) {
        return -1;
    }
    return 0;
}
Ejemplo n.º 4
0
int rdom_wrapper_test() {
    Func f("f"), g("g"), result("result");
    Var x("x"), y("y");

    f(x, y) = x + y;
    g(x, y) = 10;
    g(x, y) += 2 * f(x, x);
    g(x, y) += 3 * f(y, y);

    // Make a global wrapper on 'g', so that we can schedule initialization
    // and the update on the same compute level at the global wrapper
    Func wrapper = g.in().compute_root();
    g.compute_at(wrapper, x);
    f.compute_root();

    // Check the call graphs.
    // Expect 'wrapper' to call 'g', initialization of 'g' to call nothing
    // and its update to call 'f' and 'g', 'f' to call nothing
    Module m = wrapper.compile_to_module({});
    CheckCalls c;
    m.functions().front().body.accept(&c);

    CallGraphs expected = {
        {g.name(), {f.name(), g.name()}},
        {wrapper.name(), {g.name()}},
        {f.name(), {}},
    };
    if (check_call_graphs(c.calls, expected) != 0) {
        return -1;
    }

    Image<int> im = wrapper.realize(200, 200);
    auto func = [](int x, int y) {
        return 4*x + 6* y + 10;
    };
    if (check_image(im, func)) {
        return -1;
    }
    return 0;
}