#include "Halide.h"
#include <stdio.h>
int main(int argc, char **argv) {
Var x("x"), y("y");
{
Func gradient("gradient");
gradient(x, y) = x + y;
gradient.trace_stores();
printf("Evaluating gradient\n");
Buffer<int> output = gradient.realize({8, 8});
Func parallel_gradient("parallel_gradient");
parallel_gradient(x, y) = x + y;
parallel_gradient.trace_stores();
parallel_gradient.parallel(y);
printf("\nEvaluating parallel_gradient\n");
parallel_gradient.realize({8, 8});
}
{
Func f;
Func g;
printf("\nEvaluating sin(x) + cos(y), and just printing cos(y)\n");
g.realize({4, 4});
}
{
Func f;
f(x, y) =
sin(x) +
print(
cos(y),
"<- this is cos(", y,
") when x =", x);
printf("\nEvaluating sin(x) + cos(y), and printing cos(y) with more context\n");
f.realize({4, 4});
Func g;
g.realize({4, 4});
}
{
Func f;
e =
print_when(x == 37 && y == 42, e,
"<- this is cos(y) at x, y == (37, 42)");
printf("\nEvaluating sin(x) + cos(y), and printing cos(y) at a single pixel\n");
f.realize({640, 480});
Func g;
e =
print_when(e < 0, e,
"cos(y) < 0 at y ==", y);
printf("\nEvaluating sin(x) + cos(y), and printing whenever cos(y) < 0\n");
g.realize({4, 4});
}
{
Var fizz("fizz"), buzz("buzz");
Expr e = 1;
for (int i = 2; i < 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
e += fizz * buzz;
} else if (i % 3 == 0) {
e += fizz;
} else if (i % 5 == 0) {
e += buzz;
} else {
e += i;
}
}
std::cout << "Printing a complex Expr: " << e << "\n";
}
printf("Success!\n");
return 0;
}
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Expr print_when(Expr condition, const std::vector< Expr > &values)
Create an Expr that prints whenever it is evaluated, provided that the condition is true.
Expr sin(Expr x)
Return the sine of a floating-point expression.
Expr cos(Expr x)
Return the cosine of a floating-point expression.
Expr print(const std::vector< Expr > &values)
Create an Expr that prints out its value whenever it is evaluated.