Loading...
Searching...
No Matches
Pipeline.h
Go to the documentation of this file.
#ifndef HALIDE_PIPELINE_H
#define HALIDE_PIPELINE_H
/** \file
*
* Defines the front-end class representing an entire Halide imaging
* pipeline.
*/
#include <initializer_list>
#include <map>
#include <memory>
#include <vector>
#include "IROperator.h"
#include "IntrusivePtr.h"
#include "JITModule.h"
#include "Module.h"
#include "Realization.h"
#include "Target.h"
#include "Tuple.h"
namespace Halide {
struct Argument;
class Callable;
class Func;
struct PipelineContents;
/** Special the Autoscheduler to be used (if any), along with arbitrary
* additional arguments specific to the given Autoscheduler.
*
* The 'name' field specifies the type of Autoscheduler
* to be used (e.g. Adams2019, Mullapudi2016). If this is an empty string,
* no autoscheduling will be done; if not, it must be the name of a known Autoscheduler.
*
* At this time, well-known autoschedulers include:
* "Mullapudi2016" -- heuristics-based; the first working autoscheduler; currently built in to libHalide
* see http://graphics.cs.cmu.edu/projects/halidesched/
* "Adams2019" -- aka "the ML autoscheduler"; currently located in apps/autoscheduler
* see https://halide-lang.org/papers/autoscheduler2019.html
* "Li2018" -- aka "the gradient autoscheduler"; currently located in apps/gradient_autoscheduler.
* see https://people.csail.mit.edu/tzumao/gradient_halide
*
* The key/value pairs in 'extra' are defined on a per-autoscheduler basis.
* An autoscheduler can have any number of required or optional keys.
*/
struct AutoschedulerParams {
std::string name;
std::map<std::string, std::string> extra;
AutoschedulerParams() = default;
/*not-explicit*/ AutoschedulerParams(const std::string &name)
: name(name) {
}
AutoschedulerParams(const std::string &name, const std::map<std::string, std::string> &extra)
: name(name), extra(extra) {
}
std::string to_string() const;
};
namespace Internal {
class IRMutator;
struct JITCache;
struct JITCallArgs;
} // namespace Internal
/**
* Used to determine if the output printed to file should be as a normal string
* or as an HTML file which can be opened in a browerser and manipulated via JS and CSS.*/
enum StmtOutputFormat {
Text,
HTML
};
namespace {
// Helper for deleting custom lowering passes. In the header so that
// it goes in user code on windows, where you can have multiple heaps.
template<typename T>
void delete_lowering_pass(T *pass) {
delete pass;
}
} // namespace
/** A custom lowering pass. See Pipeline::add_custom_lowering_pass. */
struct CustomLoweringPass {
Internal::IRMutator *pass;
std::function<void()> deleter;
};
struct JITExtern;
struct AutoSchedulerResults {
Target target; // Target specified to the autoscheduler
AutoschedulerParams autoscheduler_params; // The autoscheduler used, along with its params
std::string schedule_source; // The C++ source code of the generated schedule
std::vector<uint8_t> featurization; // The featurization of the pipeline (if any)
};
class Pipeline;
using AutoSchedulerFn = std::function<void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)>;
/** A class representing a Halide pipeline. Constructed from the Func
* or Funcs that it outputs. */
class Pipeline {
public:
struct RealizationArg {
// Only one of the following may be non-null
Realization *r{nullptr};
halide_buffer_t *buf{nullptr};
std::unique_ptr<std::vector<Buffer<>>> buffer_list;
RealizationArg(Realization &r)
: r(&r) {
}
RealizationArg(Realization &&r)
: r(&r) {
}
RealizationArg(halide_buffer_t *buf)
: buf(buf) {
}
template<typename T, int Dims>
RealizationArg(Runtime::Buffer<T, Dims> &dst)
: buf(dst.raw_buffer()) {
}
template<typename T, int Dims>
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer<T, Dims> &dst)
: buf(dst.raw_buffer()) {
}
template<typename T, int Dims, typename... Args,
typename = typename std::enable_if<Internal::all_are_convertible<Buffer<>, Args...>::value>::type>
RealizationArg(Buffer<T, Dims> &a, Args &&...args)
: buffer_list(std::make_unique<std::vector<Buffer<>>>(std::initializer_list<Buffer<>>{a, std::forward<Args>(args)...})) {
}
RealizationArg(RealizationArg &&from) = default;
size_t size() const {
if (r != nullptr) {
return r->size();
} else if (buffer_list) {
return buffer_list->size();
}
return 1;
}
};
private:
Internal::IntrusivePtr<PipelineContents> contents;
void prepare_jit_call_arguments(RealizationArg &output, const Target &target,
JITUserContext **user_context, bool is_bounds_inference, Internal::JITCallArgs &args_result);
static std::vector<Internal::JITModule> make_externs_jit_module(const Target &target,
std::map<std::string, JITExtern> &externs_in_out);
static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
static AutoSchedulerFn find_autoscheduler(const std::string &autoscheduler_name);
int call_jit_code(const Internal::JITCallArgs &args);
// Get the value of contents->jit_target, but reality-check that the contents
// sensibly match the value. Return Target() if not jitted.
Target get_compiled_jit_target() const;
static Internal::JITCache compile_jit_cache(const Module &module,
std::vector<Argument> args,
const std::vector<Internal::Function> &outputs,
const std::map<std::string, JITExtern> &jit_externs,
const Target &target_arg);
public:
/** Make an undefined Pipeline object. */
Pipeline();
/** Make a pipeline that computes the given Func. Schedules the
* Func compute_root(). */
Pipeline(const Func &output);
/** Make a pipeline that computes the givens Funcs as
* outputs. Schedules the Funcs compute_root(). */
Pipeline(const std::vector<Func> &outputs);
/** Make a pipeline from deserialization. */
Pipeline(const std::vector<Func> &outputs, const std::vector<Internal::Stmt> &requirements);
std::vector<Argument> infer_arguments(const Internal::Stmt &body);
/** Get the Funcs this pipeline outputs. */
std::vector<Func> outputs() const;
/** Get the requirements of this pipeline. */
std::vector<Internal::Stmt> requirements() const;
/** Generate a schedule for the pipeline using the specified autoscheduler. */
AutoSchedulerResults apply_autoscheduler(const Target &target,
const AutoschedulerParams &autoscheduler_params) const;
/** Add a new the autoscheduler method with the given name. Does not affect the current default autoscheduler.
* It is an error to call this with the same name multiple times. */
static void add_autoscheduler(const std::string &autoscheduler_name, const AutoSchedulerFn &autoscheduler);
/** Return handle to the index-th Func within the pipeline based on the
* topological order. */
Func get_func(size_t index);
/** Compile and generate multiple target files with single call.
* Deduces target files based on filenames specified in
* output_files map.
*/
void compile_to(const std::map<OutputFileType, std::string> &output_files,
const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target);
/** Statically compile a pipeline to llvm bitcode, with the given
* filename (which should probably end in .bc), type signature,
* and C function name. If you're compiling a pipeline with a
* single output Func, see also Func::compile_to_bitcode. */
void compile_to_bitcode(const std::string &filename,
const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Statically compile a pipeline to llvm assembly, with the given
* filename (which should probably end in .ll), type signature,
* and C function name. If you're compiling a pipeline with a
* single output Func, see also Func::compile_to_llvm_assembly. */
void compile_to_llvm_assembly(const std::string &filename,
const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Statically compile a pipeline with multiple output functions to an
* object file, with the given filename (which should probably end in
* .o or .obj), type signature, and C function name (which defaults to
* the same name as this halide function. You probably don't want to
* use this directly; call compile_to_static_library or compile_to_file instead. */
void compile_to_object(const std::string &filename,
const std::vector<Argument> &,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Emit a header file with the given filename for a pipeline. The
* header will define a function with the type signature given by
* the second argument, and a name given by the third. You don't
* actually have to have defined any of these functions yet to
* call this. You probably don't want to use this directly; call
* compile_to_static_library or compile_to_file instead. */
void compile_to_header(const std::string &filename,
const std::vector<Argument> &,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Statically compile a pipeline to text assembly equivalent to
* the object file generated by compile_to_object. This is useful
* for checking what Halide is producing without having to
* disassemble anything, or if you need to feed the assembly into
* some custom toolchain to produce an object file. */
void compile_to_assembly(const std::string &filename,
const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Statically compile a pipeline to C source code. This is useful
* for providing fallback code paths that will compile on many
* platforms. Vectorization will fail, and parallelization will
* produce serial code. */
void compile_to_c(const std::string &filename,
const std::vector<Argument> &,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Write out an internal representation of lowered code. Useful
* for analyzing and debugging scheduling. Can emit html or plain
* text. */
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 a conceptual representation of lowered code, before any parallel loop
* get factored out into separate functions, or GPU loops are offloaded to kernel code.r
* Useful for analyzing and debugging scheduling. Can emit html or plain text. */
void compile_to_conceptual_stmt(const std::string &filename,
const std::vector<Argument> &args,
StmtOutputFormat fmt = Text,
const Target &target = get_target_from_environment());
/** Write out the loop nests specified by the schedule for this
* Pipeline's Funcs. Helpful for understanding what a schedule is
* doing. */
void print_loop_nest();
/** Compile to object file and header pair, with the given
* arguments. */
void compile_to_file(const std::string &filename_prefix,
const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Compile to static-library file and header pair, with the given
* arguments. */
void compile_to_static_library(const std::string &filename_prefix,
const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target = get_target_from_environment());
/** Compile to static-library file and header pair once for each target;
* each resulting function will be considered (in order) via halide_can_use_target_features()
* at runtime, with the first appropriate match being selected for subsequent use.
* This is typically useful for specializations that may vary unpredictably by machine
* (e.g., SSE4.1/AVX/AVX2 on x86 desktop machines).
* All targets must have identical arch-os-bits.
*/
void compile_to_multitarget_static_library(const std::string &filename_prefix,
const std::vector<Argument> &args,
const std::vector<Target> &targets);
/** Like compile_to_multitarget_static_library(), except that the object files
* are all output as object files (rather than bundled into a static library).
*
* `suffixes` is an optional list of strings to use for as the suffix for each object
* file. If nonempty, it must be the same length as `targets`. (If empty, Target::to_string()
* will be used for each suffix.)
*
* Note that if `targets.size()` > 1, the wrapper code (to select the subtarget)
* will be generated with the filename `${filename_prefix}_wrapper.o`
*
* Note that if `targets.size()` > 1 and `no_runtime` is not specified, the runtime
* will be generated with the filename `${filename_prefix}_runtime.o`
*/
void compile_to_multitarget_object_files(const std::string &filename_prefix,
const std::vector<Argument> &args,
const std::vector<Target> &targets,
const std::vector<std::string> &suffixes);
/** Create an internal representation of lowered code as a self
* contained Module suitable for further compilation. */
Module compile_to_module(const std::vector<Argument> &args,
const std::string &fn_name,
const Target &target = get_target_from_environment(),
LinkageType linkage_type = LinkageType::ExternalPlusMetadata);
/** Eagerly jit compile the function to machine code. This
* normally happens on the first call to realize. If you're
* running your halide pipeline inside time-sensitive code and
* wish to avoid including the time taken to compile a pipeline,
* then you can call this ahead of time. Default is to use the Target
* returned from Halide::get_jit_target_from_environment()
*/
void compile_jit(const Target &target = get_jit_target_from_environment());
/** Eagerly jit compile the function to machine code and return a callable
* struct that behaves like a function pointer. The calling convention
* will exactly match that of an AOT-compiled version of this Func
* with the same Argument list.
*/
Callable compile_to_callable(const std::vector<Argument> &args,
const Target &target = get_jit_target_from_environment());
/** Install a set of external C functions or Funcs to satisfy
* dependencies introduced by HalideExtern and define_extern
* mechanisms. These will be used by calls to realize,
* infer_bounds, and compile_jit. */
void set_jit_externs(const std::map<std::string, JITExtern> &externs);
/** Return the map of previously installed externs. Is an empty
* map unless set otherwise. */
const std::map<std::string, JITExtern> &get_jit_externs();
/** Get a struct containing the currently set custom functions
* used by JIT. This can be mutated. Changes will take effect the
* next time this Pipeline is realized. */
JITHandlers &jit_handlers();
/** Add a custom pass to be used during lowering. It is run after
* all other lowering passes. Can be used to verify properties of
* the lowered Stmt, instrument it with extra code, or otherwise
* modify it. The Func takes ownership of the pass, and will call
* delete on it when the Func goes out of scope. So don't pass a
* stack object, or share pass instances between multiple
* Funcs. */
template<typename T>
void add_custom_lowering_pass(T *pass) {
// Template instantiate a custom deleter for this type, then
// wrap in a lambda. The custom deleter lives in user code, so
// that deletion is on the same heap as construction (I hate Windows).
add_custom_lowering_pass(pass, [pass]() { delete_lowering_pass<T>(pass); });
}
/** Add a custom pass to be used during lowering, with the
* function that will be called to delete it also passed in. Set
* it to nullptr if you wish to retain ownership of the object. */
void add_custom_lowering_pass(Internal::IRMutator *pass, std::function<void()> deleter);
/** Remove all previously-set custom lowering passes */
void clear_custom_lowering_passes();
/** Get the custom lowering passes. */
const std::vector<CustomLoweringPass> &custom_lowering_passes();
/** See Func::realize */
Realization realize(std::vector<int32_t> sizes = {}, const Target &target = Target());
/** Same as above, but takes a custom user-provided context to be
* passed to runtime functions. A nullptr context is legal, and is
* equivalent to calling the variant of realize that does not take
* a context. */
Realization realize(JITUserContext *context,
std::vector<int32_t> sizes = {},
const Target &target = Target());
/** Evaluate this Pipeline into an existing allocated buffer or
* buffers. If the buffer is also one of the arguments to the
* function, strange things may happen, as the pipeline isn't
* necessarily safe to run in-place. The realization should
* contain one Buffer per tuple component per output Func. For
* each individual output Func, all Buffers must have the same
* shape, but the shape can vary across the different output
* Funcs. This form of realize does *not* automatically copy data
* back from the GPU. */
void realize(RealizationArg output, const Target &target = Target());
/** Same as above, but takes a custom user-provided context to be
* passed to runtime functions. A nullptr context is legal, and
* is equivalent to calling the variant of realize that does not
* take a context. */
void realize(JITUserContext *context,
RealizationArg output,
const Target &target = Target());
/** For a given size of output, or a given set of output buffers,
* determine the bounds required of all unbound ImageParams
* referenced. Communicates the result by allocating new buffers
* of the appropriate size and binding them to the unbound
* ImageParams. */
// @{
void infer_input_bounds(const std::vector<int32_t> &sizes,
const Target &target = get_jit_target_from_environment());
void infer_input_bounds(RealizationArg output,
const Target &target = get_jit_target_from_environment());
// @}
/** Variants of infer_inputs_bounds that take a custom user context */
// @{
void infer_input_bounds(JITUserContext *context,
const std::vector<int32_t> &sizes,
const Target &target = get_jit_target_from_environment());
void infer_input_bounds(JITUserContext *context,
RealizationArg output,
const Target &target = get_jit_target_from_environment());
// @}
/** Infer the arguments to the Pipeline, sorted into a canonical order:
* all buffers (sorted alphabetically by name), followed by all non-buffers
* (sorted alphabetically by name).
This lets you write things like:
\code
pipeline.compile_to_assembly("/dev/stdout", pipeline.infer_arguments());
\endcode
*/
std::vector<Argument> infer_arguments();
/** Check if this pipeline object is defined. That is, does it
* have any outputs? */
bool defined() const;
/** Invalidate any internal cached state, e.g. because Funcs have
* been rescheduled. */
void invalidate_cache();
/** Add a top-level precondition to the generated pipeline,
* expressed as a boolean Expr. The Expr may depend on parameters
* only, and may not call any Func or use a Var. If the condition
* is not true at runtime, the pipeline will call halide_error
* with the remaining arguments, and return
* halide_error_code_requirement_failed. Requirements are checked
* in the order added. */
// @{
void add_requirement(const Expr &condition, const std::vector<Expr> &error_args);
template<typename... Args,
typename = typename std::enable_if<Internal::all_are_printable_args<Args...>::value>::type>
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args) {
std::vector<Expr> collected_args;
Internal::collect_print_args(collected_args, std::forward<Args>(error_args)...);
add_requirement(condition, collected_args);
}
// @}
/** Generate begin_pipeline and end_pipeline tracing calls for this pipeline. */
void trace_pipeline();
private:
std::string generate_function_name() const;
};
struct ExternSignature {
private:
Type ret_type_; // Only meaningful if is_void_return is false; must be default value otherwise
bool is_void_return_{false};
std::vector<Type> arg_types_;
public:
ExternSignature() = default;
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector<Type> &arg_types)
: ret_type_(ret_type),
is_void_return_(is_void_return),
arg_types_(arg_types) {
internal_assert(!(is_void_return && ret_type != Type()));
}
template<typename RT, typename... Args>
explicit ExternSignature(RT (*f)(Args... args))
: ret_type_(type_of<RT>()),
is_void_return_(std::is_void<RT>::value),
arg_types_({type_of<Args>()...}) {
}
const Type &ret_type() const {
internal_assert(!is_void_return());
return ret_type_;
}
bool is_void_return() const {
return is_void_return_;
}
const std::vector<Type> &arg_types() const {
return arg_types_;
}
friend std::ostream &operator<<(std::ostream &stream, const ExternSignature &sig) {
if (sig.is_void_return_) {
stream << "void";
} else {
stream << sig.ret_type_;
}
stream << " (*)(";
bool comma = false;
for (const auto &t : sig.arg_types_) {
if (comma) {
stream << ", ";
}
stream << t;
comma = true;
}
stream << ")";
return stream;
}
};
struct ExternCFunction {
private:
void *address_{nullptr};
ExternSignature signature_;
public:
ExternCFunction() = default;
ExternCFunction(void *address, const ExternSignature &signature)
: address_(address), signature_(signature) {
}
template<typename RT, typename... Args>
ExternCFunction(RT (*f)(Args... args))
: ExternCFunction((void *)f, ExternSignature(f)) {
}
void *address() const {
return address_;
}
const ExternSignature &signature() const {
return signature_;
}
};
struct JITExtern {
private:
// Note that exactly one of pipeline_ and extern_c_function_
// can be set in a given JITExtern instance.
Pipeline pipeline_;
ExternCFunction extern_c_function_;
public:
explicit JITExtern(Pipeline pipeline);
explicit JITExtern(const Func &func);
explicit JITExtern(const ExternCFunction &extern_c_function);
template<typename RT, typename... Args>
explicit JITExtern(RT (*f)(Args... args))
: JITExtern(ExternCFunction(f)) {
}
const Pipeline &pipeline() const {
return pipeline_;
}
const ExternCFunction &extern_c_function() const {
return extern_c_function_;
}
};
} // namespace Halide
#endif
internal_assert
#define internal_assert(c)
Definition Error.h:218
IROperator.h
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
IntrusivePtr.h
Support classes for reference-counting via intrusive shared pointers.
JITModule.h
Defines the struct representing lifetime and dependencies of a JIT compiled halide pipeline.
Module.h
Defines Module, an IR container that fully describes a Halide program.
Realization.h
Defines Realization - a vector of Buffer for use in pipelines with multiple outputs.
Target.h
Defines the structure that describes a Halide target.
Tuple.h
Defines Tuple - the front-end handle on small arrays of expressions.
HALIDE_NO_USER_CODE_INLINE
#define HALIDE_NO_USER_CODE_INLINE
Definition Util.h:47
Halide::Buffer
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition Buffer.h:122
Halide::Callable
Definition Callable.h:82
Halide::Func
A halide function.
Definition Func.h:706
Halide::Internal::IRMutator
A base class for passes over the IR which modify it (e.g.
Definition IRMutator.h:26
Halide::Module
A halide module.
Definition Module.h:142
Halide::Pipeline
A class representing a Halide pipeline.
Definition Pipeline.h:107
Halide::Pipeline::compile_to_bitcode
void compile_to_bitcode(const std::string &filename, const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment())
Statically compile a pipeline to llvm bitcode, with the given filename (which should probably end in ...
Halide::Pipeline::compile_to_c
void compile_to_c(const std::string &filename, const std::vector< Argument > &, const std::string &fn_name, const Target &target=get_target_from_environment())
Statically compile a pipeline to C source code.
Halide::Pipeline::compile_jit
void compile_jit(const Target &target=get_jit_target_from_environment())
Eagerly jit compile the function to machine code.
Halide::Pipeline::trace_pipeline
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
Halide::Pipeline::compile_to_conceptual_stmt
void compile_to_conceptual_stmt(const std::string &filename, const std::vector< Argument > &args, StmtOutputFormat fmt=Text, const Target &target=get_target_from_environment())
Write out a conceptual representation of lowered code, before any parallel loop get factored out into...
Halide::Pipeline::realize
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target())
See Func::realize.
Halide::Pipeline::compile_to_file
void compile_to_file(const std::string &filename_prefix, const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment())
Compile to object file and header pair, with the given arguments.
Halide::Pipeline::realize
Realization realize(JITUserContext *context, std::vector< int32_t > sizes={}, const Target &target=Target())
Same as above, but takes a custom user-provided context to be passed to runtime functions.
Halide::Pipeline::realize
void realize(JITUserContext *context, RealizationArg output, const Target &target=Target())
Same as above, but takes a custom user-provided context to be passed to runtime functions.
Halide::Pipeline::get_func
Func get_func(size_t index)
Return handle to the index-th Func within the pipeline based on the topological order.
Halide::Pipeline::compile_to_header
void compile_to_header(const std::string &filename, const std::vector< Argument > &, const std::string &fn_name, const Target &target=get_target_from_environment())
Emit a header file with the given filename for a pipeline.
Halide::Pipeline::infer_arguments
std::vector< Argument > infer_arguments()
Infer the arguments to the Pipeline, sorted into a canonical order: all buffers (sorted alphabeticall...
Halide::Pipeline::infer_input_bounds
void infer_input_bounds(JITUserContext *context, const std::vector< int32_t > &sizes, const Target &target=get_jit_target_from_environment())
Variants of infer_inputs_bounds that take a custom user context.
Halide::Pipeline::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::Pipeline::get_jit_externs
const std::map< std::string, JITExtern > & get_jit_externs()
Return the map of previously installed externs.
Halide::Pipeline::add_autoscheduler
static void add_autoscheduler(const std::string &autoscheduler_name, const AutoSchedulerFn &autoscheduler)
Add a new the autoscheduler method with the given name.
Halide::Pipeline::set_jit_externs
void set_jit_externs(const std::map< std::string, JITExtern > &externs)
Install a set of external C functions or Funcs to satisfy dependencies introduced by HalideExtern and...
Halide::Pipeline::add_custom_lowering_pass
void add_custom_lowering_pass(Internal::IRMutator *pass, std::function< void()> deleter)
Add a custom pass to be used during lowering, with the function that will be called to delete it also...
Halide::Pipeline::custom_lowering_passes
const std::vector< CustomLoweringPass > & custom_lowering_passes()
Get the custom lowering passes.
Halide::Pipeline::Pipeline
Pipeline()
Make an undefined Pipeline object.
Halide::Pipeline::compile_to_llvm_assembly
void compile_to_llvm_assembly(const std::string &filename, const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment())
Statically compile a pipeline to llvm assembly, with the given filename (which should probably end in...
Halide::Pipeline::infer_arguments
std::vector< Argument > infer_arguments(const Internal::Stmt &body)
Halide::Pipeline::Pipeline
Pipeline(const std::vector< Func > &outputs)
Make a pipeline that computes the givens Funcs as outputs.
Halide::Pipeline::compile_to_callable
Callable compile_to_callable(const std::vector< Argument > &args, const Target &target=get_jit_target_from_environment())
Eagerly jit compile the function to machine code and return a callable struct that behaves like a fun...
Halide::Pipeline::infer_input_bounds
void infer_input_bounds(const std::vector< int32_t > &sizes, const Target &target=get_jit_target_from_environment())
For a given size of output, or a given set of output buffers, determine the bounds required of all un...
Halide::Pipeline::Pipeline
Pipeline(const std::vector< Func > &outputs, const std::vector< Internal::Stmt > &requirements)
Make a pipeline from deserialization.
Halide::Pipeline::compile_to_multitarget_object_files
void compile_to_multitarget_object_files(const std::string &filename_prefix, const std::vector< Argument > &args, const std::vector< Target > &targets, const std::vector< std::string > &suffixes)
Like compile_to_multitarget_static_library(), except that the object files are all output as object f...
Halide::Pipeline::compile_to_multitarget_static_library
void compile_to_multitarget_static_library(const std::string &filename_prefix, const std::vector< Argument > &args, const std::vector< Target > &targets)
Compile to static-library file and header pair once for each target; each resulting function will be ...
Halide::Pipeline::apply_autoscheduler
AutoSchedulerResults apply_autoscheduler(const Target &target, const AutoschedulerParams &autoscheduler_params) const
Generate a schedule for the pipeline using the specified autoscheduler.
Halide::Pipeline::compile_to_object
void compile_to_object(const std::string &filename, const std::vector< Argument > &, const std::string &fn_name, const Target &target=get_target_from_environment())
Statically compile a pipeline with multiple output functions to an object file, with the given filena...
Halide::Pipeline::invalidate_cache
void invalidate_cache()
Invalidate any internal cached state, e.g.
Halide::Pipeline::add_requirement
void add_requirement(const Expr &condition, const std::vector< Expr > &error_args)
Add a top-level precondition to the generated pipeline, expressed as a boolean Expr.
Halide::Pipeline::outputs
std::vector< Func > outputs() const
Get the Funcs this pipeline outputs.
Halide::Pipeline::infer_input_bounds
void infer_input_bounds(RealizationArg output, const Target &target=get_jit_target_from_environment())
Halide::Pipeline::print_loop_nest
void print_loop_nest()
Write out the loop nests specified by the schedule for this Pipeline's Funcs.
Halide::Pipeline::compile_to_module
Module compile_to_module(const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment(), LinkageType linkage_type=LinkageType::ExternalPlusMetadata)
Create an internal representation of lowered code as a self contained Module suitable for further com...
Halide::Pipeline::requirements
std::vector< Internal::Stmt > requirements() const
Get the requirements of this pipeline.
Halide::Pipeline::add_requirement
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args)
Definition Pipeline.h:487
Halide::Pipeline::infer_input_bounds
void infer_input_bounds(JITUserContext *context, RealizationArg output, const Target &target=get_jit_target_from_environment())
Halide::Pipeline::compile_to_assembly
void compile_to_assembly(const std::string &filename, const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment())
Statically compile a pipeline to text assembly equivalent to the object file generated by compile_to_...
Halide::Pipeline::jit_handlers
JITHandlers & jit_handlers()
Get a struct containing the currently set custom functions used by JIT.
Halide::Pipeline::realize
void realize(RealizationArg output, const Target &target=Target())
Evaluate this Pipeline into an existing allocated buffer or buffers.
Halide::Pipeline::clear_custom_lowering_passes
void clear_custom_lowering_passes()
Remove all previously-set custom lowering passes.
Halide::Pipeline::defined
bool defined() const
Check if this pipeline object is defined.
Halide::Pipeline::compile_to_static_library
void compile_to_static_library(const std::string &filename_prefix, const std::vector< Argument > &args, const std::string &fn_name, const Target &target=get_target_from_environment())
Compile to static-library file and header pair, with the given arguments.
Halide::Pipeline::Pipeline
Pipeline(const Func &output)
Make a pipeline that computes the given Func.
Halide::Pipeline::add_custom_lowering_pass
void add_custom_lowering_pass(T *pass)
Add a custom pass to be used during lowering.
Definition Pipeline.h:387
Halide::Pipeline::compile_to
void compile_to(const std::map< OutputFileType, std::string > &output_files, const std::vector< Argument > &args, const std::string &fn_name, const Target &target)
Compile and generate multiple target files with single call.
Halide::Realization
A Realization is a vector of references to existing Buffer objects.
Definition Realization.h:19
Halide::Runtime::Buffer
A templated Buffer class that wraps halide_buffer_t and adds functionality.
Definition HalideBuffer.h:224
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::collect_print_args
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
Definition IROperator.h:353
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::LinkageType
LinkageType
Type of linkage a function in a lowered Halide module can have.
Definition Module.h:52
Halide::LinkageType::ExternalPlusMetadata
@ ExternalPlusMetadata
Visible externally. Argument metadata and an argv wrapper are also generated.
Definition Module.h:54
Halide::type_of
Type type_of()
Construct the halide equivalent of a C type.
Definition Type.h:572
Halide::AutoSchedulerFn
std::function< void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
Definition Pipeline.h:103
Halide::get_jit_target_from_environment
Target get_jit_target_from_environment()
Return the target that Halide will use for jit-compilation.
Halide::get_target_from_environment
Target get_target_from_environment()
Return the target that Halide will use.
Halide::StmtOutputFormat
StmtOutputFormat
Used to determine if the output printed to file should be as a normal string or as an HTML file which...
Definition Pipeline.h:72
Halide::HTML
@ HTML
Definition Pipeline.h:74
Halide::Text
@ Text
Definition Pipeline.h:73
Halide::Argument
A struct representing an argument to a halide-generated function.
Definition Argument.h:37
Halide::AutoSchedulerResults
Definition Pipeline.h:94
Halide::AutoSchedulerResults::schedule_source
std::string schedule_source
Definition Pipeline.h:97
Halide::AutoSchedulerResults::target
Target target
Definition Pipeline.h:95
Halide::AutoSchedulerResults::featurization
std::vector< uint8_t > featurization
Definition Pipeline.h:98
Halide::AutoSchedulerResults::autoscheduler_params
AutoschedulerParams autoscheduler_params
Definition Pipeline.h:96
Halide::AutoschedulerParams
Special the Autoscheduler to be used (if any), along with arbitrary additional arguments specific to ...
Definition Pipeline.h:48
Halide::AutoschedulerParams::AutoschedulerParams
AutoschedulerParams()=default
Halide::AutoschedulerParams::AutoschedulerParams
AutoschedulerParams(const std::string &name, const std::map< std::string, std::string > &extra)
Definition Pipeline.h:56
Halide::AutoschedulerParams::name
std::string name
Definition Pipeline.h:49
Halide::AutoschedulerParams::AutoschedulerParams
AutoschedulerParams(const std::string &name)
Definition Pipeline.h:53
Halide::AutoschedulerParams::to_string
std::string to_string() const
Halide::AutoschedulerParams::extra
std::map< std::string, std::string > extra
Definition Pipeline.h:50
Halide::CustomLoweringPass
A custom lowering pass.
Definition Pipeline.h:87
Halide::CustomLoweringPass::pass
Internal::IRMutator * pass
Definition Pipeline.h:88
Halide::CustomLoweringPass::deleter
std::function< void()> deleter
Definition Pipeline.h:89
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::ExternCFunction
Definition Pipeline.h:557
Halide::ExternCFunction::address
void * address() const
Definition Pipeline.h:574
Halide::ExternCFunction::ExternCFunction
ExternCFunction(void *address, const ExternSignature &signature)
Definition Pipeline.h:565
Halide::ExternCFunction::signature
const ExternSignature & signature() const
Definition Pipeline.h:577
Halide::ExternCFunction::ExternCFunction
ExternCFunction()=default
Halide::ExternCFunction::ExternCFunction
ExternCFunction(RT(*f)(Args... args))
Definition Pipeline.h:570
Halide::ExternSignature
Definition Pipeline.h:501
Halide::ExternSignature::ExternSignature
ExternSignature()=default
Halide::ExternSignature::ExternSignature
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
Definition Pipeline.h:510
Halide::ExternSignature::operator<<
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
Definition Pipeline.h:537
Halide::ExternSignature::ret_type
const Type & ret_type() const
Definition Pipeline.h:524
Halide::ExternSignature::arg_types
const std::vector< Type > & arg_types() const
Definition Pipeline.h:533
Halide::ExternSignature::ExternSignature
ExternSignature(RT(*f)(Args... args))
Definition Pipeline.h:518
Halide::ExternSignature::is_void_return
bool is_void_return() const
Definition Pipeline.h:529
Halide::Internal::IntrusivePtr
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
Definition IntrusivePtr.h:71
Halide::Internal::JITCache
Definition JITModule.h:304
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition Expr.h:427
Halide::Internal::all_are_printable_args
Definition IROperator.h:350
Halide::JITExtern
Definition Pipeline.h:582
Halide::JITExtern::JITExtern
JITExtern(const Func &func)
Halide::JITExtern::pipeline
const Pipeline & pipeline() const
Definition Pipeline.h:599
Halide::JITExtern::extern_c_function
const ExternCFunction & extern_c_function() const
Definition Pipeline.h:602
Halide::JITExtern::JITExtern
JITExtern(Pipeline pipeline)
Halide::JITExtern::JITExtern
JITExtern(RT(*f)(Args... args))
Definition Pipeline.h:595
Halide::JITExtern::JITExtern
JITExtern(const ExternCFunction &extern_c_function)
Halide::JITHandlers
A set of custom overrides of runtime functions.
Definition JITModule.h:35
Halide::JITUserContext
A context to be passed to Pipeline::realize.
Definition JITModule.h:136
Halide::Pipeline::RealizationArg
Definition Pipeline.h:109
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(Buffer< T, Dims > &a, Args &&...args)
Definition Pipeline.h:134
Halide::Pipeline::RealizationArg::buf
halide_buffer_t * buf
Definition Pipeline.h:112
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(halide_buffer_t *buf)
Definition Pipeline.h:121
Halide::Pipeline::RealizationArg::RealizationArg
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer< T, Dims > &dst)
Definition Pipeline.h:129
Halide::Pipeline::RealizationArg::r
Realization * r
Definition Pipeline.h:111
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(RealizationArg &&from)=default
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(Runtime::Buffer< T, Dims > &dst)
Definition Pipeline.h:125
Halide::Pipeline::RealizationArg::size
size_t size() const
Definition Pipeline.h:139
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(Realization &&r)
Definition Pipeline.h:118
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(Realization &r)
Definition Pipeline.h:115
Halide::Pipeline::RealizationArg::buffer_list
std::unique_ptr< std::vector< Buffer<> > > buffer_list
Definition Pipeline.h:113
Halide::Target
A struct representing a target machine and os to generate code for.
Definition Target.h:19
Halide::Type
Types in the halide type system.
Definition Type.h:283
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition HalideRuntime.h:1569