Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
tutorial/lesson_03_debugging_1.cpp
// Halide tutorial lesson 3: Inspecting the generated code
// This lesson demonstrates how to inspect what the Halide compiler is producing.
// On linux, you can compile and run it like so:
// g++ lesson_03*.cpp -g -I <path/to/Halide.h> -L <path/to/libHalide.so> -lHalide -lpthread -ldl -o lesson_03 -std=c++17
// LD_LIBRARY_PATH=<path/to/libHalide.so> ./lesson_03
// On os x:
// g++ lesson_03*.cpp -g -I <path/to/Halide.h> -L <path/to/libHalide.so> -lHalide -o lesson_03 -std=c++17
// DYLD_LIBRARY_PATH=<path/to/libHalide.dylib> ./lesson_03
// If you have the entire Halide source tree, you can also build it by
// running:
// make tutorial_lesson_03_debugging_1
// in a shell with the current directory at the top of the halide
// source tree.
#include "Halide.h"
#include <cstdio>
// This time we'll just import the entire Halide namespace
using namespace Halide;
int main() {
// We'll start by defining the simple single-stage imaging
// pipeline from lesson 1.
// This lesson will be about debugging, but unfortunately in C++,
// objects don't know their own names, which makes it hard for us
// to understand the generated code. To get around this, you can
// pass a string to the Func and Var constructors to give them a
// name for debugging purposes.
Func gradient("gradient");
Var x("x"), y("y");
gradient(x, y) = x + y;
// Realize the function to produce an output image. We'll keep it
// very small for this lesson.
Buffer<int> output = gradient.realize({8, 8});
// That line compiled and ran the pipeline. Try running this
// lesson with the environment variable HL_DEBUG_CODEGEN set to
// 1. It will print out the various stages of compilation, and a
// pseudocode representation of the final pipeline.
// If you set HL_DEBUG_CODEGEN to a higher number, you can see
// more and more details of how Halide compiles your pipeline.
// Setting HL_DEBUG_CODEGEN=2 shows the Halide code at each stage
// of compilation, and also the llvm bitcode we generate at the
// end.
// Halide will also output an HTML version of this output, which
// supports syntax highlighting and code-folding, so it can be
// nicer to read for large pipelines. Open gradient.stmt.html" with your
// browser after running this tutorial.
gradient.compile_to_lowered_stmt("gradient.stmt.html", {}, HTML);
// You can usually figure out what code Halide is generating using
// this pseudocode. In the next lesson we'll see how to snoop on
// Halide at runtime.
printf("Success!\n");
return 0;
}
Halide::Buffer
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition Buffer.h:122
Halide::Func
A halide function.
Definition Func.h:714
Halide::Func::compile_to_lowered_stmt
void compile_to_lowered_stmt(const std::string &filename, const std::vector< Argument > &args, StmtOutputFormat fmt=Text, const Target &target=get_target_from_environment())
Write out an internal representation of lowered code.
Halide::Func::realize
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target())
Evaluate this function over some rectangular domain and return the resulting buffer or buffers.
Halide::Var
A Halide variable, to be used when defining functions.
Definition Var.h:19
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19