前言
接上, 本文学习Halide lesson_06_realizing Funcs over arbitrary domains
** how to evaluate a Func over a domain that does not start at (0, 0); **
main
//
Func gradient("gradient");
Var x("x"), y("y");
gradient(x, y) = x + y;
gradient.trace_stores();
gradient.realize({8, 8});
//****************************
//This does three things internally:
//1) Generates code that can evaluate gradient over an arbitrary rectangle.
//2) Allocates a new 8 x 8 image.
//3) Runs the generated code to evaluate gradient for all x, y from (0, 0) to (7, 7) and puts the result into the image.
//4) Returns the new image as the result of the realize call.
//Evaluates the Func into an existing image;
Buffer<int> result(8, 8);
gradient.realize(result);
// evaluate gradient over a 5 x 7 rectangle that starts somewhere else -- at position (100, 50).
Buffer<int> shifted(5, 7); // In the constructor we tell it the size.
shifted.set_min(100, 50); // Then we tell it the top-left corner.
gradient.realize(shifted);
End
这一章比较简单:
The image 'shifted' stores the value of our Func over a domain that starts at (100, 50), so asking for shifted(0, 0) would in fact read out-of-bounds and probably crash.
Halide only does rectangles.