1#ifndef HALIDE_PIPELINE_H
2#define HALIDE_PIPELINE_H
10#include <initializer_list>
29struct PipelineContents;
72void delete_lowering_pass(T *pass) {
116 template<
typename T,
int Dims>
118 :
buf(dst.raw_buffer()) {
120 template<
typename T,
int Dims>
122 :
buf(dst.raw_buffer()) {
124 template<
typename T,
int Dims,
typename... Args,
125 typename =
typename std::enable_if<Internal::all_are_convertible<Buffer<>, Args...>::value>::type>
127 :
buffer_list(std::make_unique<std::vector<
Buffer<>>>(std::initializer_list<
Buffer<>>{a, std::forward<Args>(args)...})) {
147 void prepare_jit_call_arguments(RealizationArg &output,
const Target &target,
const ParamMap ¶m_map,
148 JITUserContext **user_context,
bool is_bounds_inference, JITCallArgs &args_result);
150 static std::vector<Internal::JITModule> make_externs_jit_module(
const Target &target,
151 std::map<std::string, JITExtern> &externs_in_out);
153 static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
155 static std::string &get_default_autoscheduler_name();
157 static AutoSchedulerFn find_autoscheduler(
const std::string &autoscheduler_name);
159 int call_jit_code(
const Target &target,
const JITCallArgs &args);
163 Target get_compiled_jit_target()
const;
217 void compile_to(
const std::map<OutputFileType, std::string> &output_files,
218 const std::vector<Argument> &args,
219 const std::string &fn_name,
227 const std::vector<Argument> &args,
228 const std::string &fn_name,
236 const std::vector<Argument> &args,
237 const std::string &fn_name,
246 const std::vector<Argument> &,
247 const std::string &fn_name,
257 const std::vector<Argument> &,
258 const std::string &fn_name,
267 const std::vector<Argument> &args,
268 const std::string &fn_name,
276 const std::vector<Argument> &,
277 const std::string &fn_name,
284 const std::vector<Argument> &args,
296 const std::vector<Argument> &args,
297 const std::string &fn_name,
303 const std::vector<Argument> &args,
304 const std::string &fn_name,
315 const std::vector<Argument> &args,
316 const std::vector<Target> &targets);
332 const std::vector<Argument> &args,
333 const std::vector<Target> &targets,
334 const std::vector<std::string> &suffixes);
339 const std::string &fn_name,
359 void (*
free)(
void *,
void *));
424 std::vector<int32_t> sizes = {},
467 const std::vector<int32_t> &sizes,
506 template<
typename... Args>
508 std::vector<Expr> collected_args;
514 std::string generate_function_name()
const;
520 bool is_void_return_{
false};
521 std::vector<Type> arg_types_;
533 template<
typename RT,
typename... Args>
536 is_void_return_(std::is_void<RT>::value),
537 arg_types_({type_of<Args>()...}) {
546 return is_void_return_;
554 if (sig.is_void_return_) {
557 stream << sig.ret_type_;
561 for (
const auto &t : sig.arg_types_) {
575 void *address_{
nullptr};
585 template<
typename RT,
typename... Args>
610 template<
typename RT,
typename... Args>
619 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 a collection of parameters to be passed as formal arguments to a JIT invocation.
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.
static const ParamMap & empty_map()
A const ref to an empty ParamMap.
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 add_requirement(const Expr &condition, std::vector< Expr > &error)
Add a top-level precondition to the generated pipeline, expressed as a boolean Expr.
void set_error_handler(void(*handler)(void *, const char *))
Deprecated variants of the above that use a void pointer instead of a JITUserContext pointer.
AutoSchedulerResults auto_schedule(const std::string &autoscheduler_name, const Target &target, const MachineParams &arch_params=MachineParams::generic())
Generate a schedule for the pipeline using the specified autoscheduler.
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 set_custom_do_task(int(*custom_do_task)(void *, int(*)(void *, int, uint8_t *), int, uint8_t *))
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
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.
void realize(JITUserContext *context, RealizationArg output, const Target &target=Target(), const ParamMap ¶m_map=ParamMap::empty_map())
Same as above, but takes a custom user-provided context to be passed to runtime functions.
Realization realize(JITUserContext *context, std::vector< int32_t > sizes={}, const Target &target=Target(), const ParamMap ¶m_map=ParamMap::empty_map())
Same as above, but takes a custom user-provided context to be passed to runtime functions.
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target(), const ParamMap ¶m_map=ParamMap::empty_map())
See Func::realize.
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 set_custom_print(void(*handler)(void *, const char *))
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 realize(RealizationArg output, const Target &target=Target(), const ParamMap ¶m_map=ParamMap::empty_map())
Evaluate this Pipeline into an existing allocated buffer or buffers.
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)
AutoSchedulerResults auto_schedule(const Target &target, const MachineParams &arch_params=MachineParams::generic())
Generate a schedule for the pipeline using the currently-default autoscheduler.
Pipeline(const std::vector< Func > &outputs)
Make a pipeline that computes the givens Funcs as outputs.
void infer_input_bounds(const std::vector< int32_t > &sizes, const Target &target=get_jit_target_from_environment(), const ParamMap ¶m_map=ParamMap::empty_map())
For a given size of output, or a given set of output buffers, determine the bounds required of all un...
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 ...
static void set_default_autoscheduler_name(const std::string &autoscheduler_name)
Globally set the default autoscheduler method to use whenever autoscheduling any Pipeline when no nam...
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 infer_input_bounds(RealizationArg output, const Target &target=get_jit_target_from_environment(), const ParamMap ¶m_map=ParamMap::empty_map())
void set_custom_allocator(void *(*malloc)(void *, size_t), void(*free)(void *, void *))
void infer_input_bounds(JITUserContext *context, const std::vector< int32_t > &sizes, const Target &target=get_jit_target_from_environment(), const ParamMap ¶m_map=ParamMap::empty_map())
Variants of infer_inputs_bounds that take a custom user context.
std::vector< Func > outputs() const
Get the Funcs this pipeline outputs.
void print_loop_nest()
Write out the loop nests specified by the schedule for this Pipeline's Funcs.
void set_custom_do_par_for(int(*custom_do_par_for)(void *, int(*)(void *, int, uint8_t *), int, int, uint8_t *))
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...
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 set_custom_trace(int(*trace_fn)(void *, const halide_trace_event_t *))
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.
void infer_input_bounds(JITUserContext *context, RealizationArg output, const Target &target=get_jit_target_from_environment(), const ParamMap ¶m_map=ParamMap::empty_map())
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.
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...args)
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)
WEAK halide_do_task_t custom_do_task
WEAK halide_do_par_for_t custom_do_par_for
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
std::function< void(const Pipeline &, const Target &, const MachineParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
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.
class HALIDE_ATTRIBUTE_DEPRECATED("Use OutputFileType instead of Output") Output
Type type_of()
Construct the halide equivalent of a C type.
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...
unsigned __INT64_TYPE__ uint64_t
unsigned __INT8_TYPE__ uint8_t
std::string schedule_source
std::string machine_params_string
std::vector< uint8_t > featurization
std::string scheduler_name
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
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.
A struct representing the machine parameters to generate the auto-scheduled code for.
int parallelism
Maximum level of parallelism avalaible.
float balance
Indicates how much more expensive is the cost of a load compared to the cost of an arithmetic operati...
std::string to_string() const
Convert the MachineParams into canonical string form.
MachineParams(int parallelism, uint64_t llc, float balance)
MachineParams(const std::string &s)
Reconstruct a MachineParams from canonical string form.
static MachineParams generic()
Default machine parameters for generic CPU architecture.
uint64_t last_level_cache_size
Size of the last-level cache (in bytes).
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.