Skip to content

Minimal JIT compiled example

Andrew Adams edited this page Oct 13, 2023 · 5 revisions

Here's the simplest JIT-compiled program that does something interesting:

#include <Halide.h>
#include <stdio.h>

int main(int argc, char **argv) {
    // Define a gradient function.
    Halide::Func f;
    Halide::Var x, y;
    f(x, y) = x + y;

    // JIT-compile and evaluate it.
    Halide::Buffer<int> result = f.realize({32, 32});

    // Print the result.
    for (int y = 0; y < result.height(); y++) {
        for (int x = 0; x < result.width(); x++) {
            printf("%3d ", result(x, y));
        }
        printf("\n");
    }

    return 0;
}

The tutorials cover many more examples of JIT-compilation.

For further, more complex examples, you may wish to peruse the correctness tests.