1#ifndef HALIDE_PIPELINE_H
2#define HALIDE_PIPELINE_H
10#include <initializer_list>
28struct PipelineContents;
50 std::map<std::string, std::string>
extra;
81void delete_lowering_pass(T *pass) {
124 template<
typename T,
int Dims>
126 :
buf(dst.raw_buffer()) {
128 template<
typename T,
int Dims>
130 :
buf(dst.raw_buffer()) {
132 template<
typename T,
int Dims,
typename... Args,
133 typename =
typename std::enable_if<Internal::all_are_convertible<Buffer<>, Args...>::value>::type>
135 :
buffer_list(std::make_unique<std::vector<
Buffer<>>>(std::initializer_list<
Buffer<>>{a, std::forward<Args>(args)...})) {
152 void prepare_jit_call_arguments(RealizationArg &output,
const Target &target,
155 static std::vector<Internal::JITModule> make_externs_jit_module(
const Target &target,
156 std::map<std::string, JITExtern> &externs_in_out);
158 static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
160 static AutoSchedulerFn find_autoscheduler(
const std::string &autoscheduler_name);
162 int call_jit_code(
const Internal::JITCallArgs &args);
166 Target get_compiled_jit_target()
const;
169 std::vector<Argument> args,
170 const std::vector<Internal::Function> &
outputs,
171 const std::map<std::string, JITExtern> &jit_externs,
172 const Target &target_arg);
213 void compile_to(
const std::map<OutputFileType, std::string> &output_files,
214 const std::vector<Argument> &args,
215 const std::string &fn_name,
223 const std::vector<Argument> &args,
224 const std::string &fn_name,
232 const std::vector<Argument> &args,
233 const std::string &fn_name,
242 const std::vector<Argument> &,
243 const std::string &fn_name,
253 const std::vector<Argument> &,
254 const std::string &fn_name,
263 const std::vector<Argument> &args,
264 const std::string &fn_name,
272 const std::vector<Argument> &,
273 const std::string &fn_name,
280 const std::vector<Argument> &args,
288 const std::vector<Argument> &args,
300 const std::vector<Argument> &args,
301 const std::string &fn_name,
307 const std::vector<Argument> &args,
308 const std::string &fn_name,
319 const std::vector<Argument> &args,
320 const std::vector<Target> &targets);
336 const std::vector<Argument> &args,
337 const std::vector<Target> &targets,
338 const std::vector<std::string> &suffixes);
343 const std::string &fn_name,
413 std::vector<int32_t> sizes = {},
450 const std::vector<int32_t> &sizes,
485 template<
typename... Args,
488 std::vector<Expr> collected_args;
498 std::string generate_function_name()
const;
504 bool is_void_return_{
false};
505 std::vector<Type> arg_types_;
511 : ret_type_(ret_type),
512 is_void_return_(is_void_return),
513 arg_types_(arg_types) {
517 template<
typename RT,
typename... Args>
520 is_void_return_(std::is_void<RT>::value),
530 return is_void_return_;
538 if (sig.is_void_return_) {
541 stream << sig.ret_type_;
545 for (
const auto &t : sig.arg_types_) {
559 void *address_{
nullptr};
569 template<
typename RT,
typename... Args>
594 template<
typename RT,
typename... Args>
603 return extern_c_function_;
#define internal_assert(c)
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Support classes for reference-counting via intrusive shared pointers.
Defines the struct representing lifetime and dependencies of a JIT compiled halide pipeline.
Defines Module, an IR container that fully describes a Halide program.
Defines Realization - a vector of Buffer for use in pipelines with multiple outputs.
Defines the structure that describes a Halide target.
Defines Tuple - the front-end handle on small arrays of expressions.
#define HALIDE_NO_USER_CODE_INLINE
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
A base class for passes over the IR which modify it (e.g.
A class representing a Halide pipeline.
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 ...
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.
void compile_jit(const Target &target=get_jit_target_from_environment())
Eagerly jit compile the function to machine code.
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
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...
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target())
See Func::realize.
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.
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.
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.
Func get_func(size_t index)
Return handle to the index-th Func within the pipeline based on the topological order.
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.
std::vector< Argument > infer_arguments()
Infer the arguments to the Pipeline, sorted into a canonical order: all buffers (sorted alphabeticall...
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.
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.
const std::map< std::string, JITExtern > & get_jit_externs()
Return the map of previously installed externs.
static void add_autoscheduler(const std::string &autoscheduler_name, const AutoSchedulerFn &autoscheduler)
Add a new the autoscheduler method with the given name.
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...
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...
const std::vector< CustomLoweringPass > & custom_lowering_passes()
Get the custom lowering passes.
Pipeline()
Make an undefined Pipeline object.
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...
std::vector< Argument > infer_arguments(const Internal::Stmt &body)
Pipeline(const std::vector< Func > &outputs)
Make a pipeline that computes the givens Funcs as outputs.
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...
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...
Pipeline(const std::vector< Func > &outputs, const std::vector< Internal::Stmt > &requirements)
Make a pipeline from deserialization.
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...
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 ...
AutoSchedulerResults apply_autoscheduler(const Target &target, const AutoschedulerParams &autoscheduler_params) const
Generate a schedule for the pipeline using the specified autoscheduler.
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...
void invalidate_cache()
Invalidate any internal cached state, e.g.
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.
std::vector< Func > outputs() const
Get the Funcs this pipeline outputs.
void infer_input_bounds(RealizationArg output, const Target &target=get_jit_target_from_environment())
void print_loop_nest()
Write out the loop nests specified by the schedule for this Pipeline's Funcs.
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...
std::vector< Internal::Stmt > requirements() const
Get the requirements of this pipeline.
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args)
void infer_input_bounds(JITUserContext *context, RealizationArg output, const Target &target=get_jit_target_from_environment())
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_...
JITHandlers & jit_handlers()
Get a struct containing the currently set custom functions used by JIT.
void realize(RealizationArg output, const Target &target=Target())
Evaluate this Pipeline into an existing allocated buffer or buffers.
void clear_custom_lowering_passes()
Remove all previously-set custom lowering passes.
bool defined() const
Check if this pipeline object is defined.
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.
Pipeline(const Func &output)
Make a pipeline that computes the given Func.
void add_custom_lowering_pass(T *pass)
Add a custom pass to be used during lowering.
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.
A Realization is a vector of references to existing Buffer objects.
size_t size() const
The number of images in the Realization.
A templated Buffer class that wraps halide_buffer_t and adds functionality.
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
LinkageType
Type of linkage a function in a lowered Halide module can have.
@ ExternalPlusMetadata
Visible externally. Argument metadata and an argv wrapper are also generated.
@ Internal
Not visible externally, similar to 'static' linkage in C.
Type type_of()
Construct the halide equivalent of a C type.
std::function< void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
Target get_jit_target_from_environment()
Return the target that Halide will use for jit-compilation.
Target get_target_from_environment()
Return the target that Halide will use.
StmtOutputFormat
Used to determine if the output printed to file should be as a normal string or as an HTML file which...
std::string schedule_source
std::vector< uint8_t > featurization
AutoschedulerParams autoscheduler_params
Special the Autoscheduler to be used (if any), along with arbitrary additional arguments specific to ...
AutoschedulerParams()=default
AutoschedulerParams(const std::string &name, const std::map< std::string, std::string > &extra)
AutoschedulerParams(const std::string &name)
std::string to_string() const
std::map< std::string, std::string > extra
Internal::IRMutator * pass
std::function< void()> deleter
A fragment of Halide syntax.
ExternCFunction(void *address, const ExternSignature &signature)
const ExternSignature & signature() const
ExternCFunction()=default
ExternCFunction(RT(*f)(Args... args))
ExternSignature()=default
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
const Type & ret_type() const
const std::vector< Type > & arg_types() const
ExternSignature(RT(*f)(Args... args))
bool is_void_return() const
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
A reference-counted handle to a statement node.
JITExtern(const Func &func)
const Pipeline & pipeline() const
const ExternCFunction & extern_c_function() const
JITExtern(Pipeline pipeline)
JITExtern(RT(*f)(Args... args))
JITExtern(const ExternCFunction &extern_c_function)
A set of custom overrides of runtime functions.
A context to be passed to Pipeline::realize.
RealizationArg(Buffer< T, Dims > &a, Args &&...args)
RealizationArg(halide_buffer_t *buf)
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer< T, Dims > &dst)
RealizationArg(RealizationArg &&from)=default
RealizationArg(Runtime::Buffer< T, Dims > &dst)
RealizationArg(Realization &&r)
RealizationArg(Realization &r)
std::unique_ptr< std::vector< Buffer<> > > buffer_list
A struct representing a target machine and os to generate code for.
Types in the halide type system.
The raw representation of an image passed around by generated Halide code.