1 #ifndef HALIDE_PIPELINE_H
2 #define HALIDE_PIPELINE_H
27 struct PipelineContents;
70 void delete_lowering_pass(T *pass) {
114 template<
typename T,
int D>
122 template<
typename T,
typename... Args,
123 typename =
typename std::enable_if<Internal::all_are_convertible<Buffer<>, Args...>::value>::type>
145 void prepare_jit_call_arguments(RealizationArg &output,
const Target &target,
const ParamMap ¶m_map,
146 void *
user_context,
bool is_bounds_inference, JITCallArgs &args_result);
148 static std::vector<Internal::JITModule> make_externs_jit_module(
const Target &target,
149 std::map<std::string, JITExtern> &externs_in_out);
151 static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
153 static std::string &get_default_autoscheduler_name();
155 static AutoSchedulerFn find_autoscheduler(
const std::string &autoscheduler_name);
157 int call_jit_code(
const Target &target,
const JITCallArgs &args);
161 Target get_compiled_jit_target()
const;
215 void compile_to(
const std::map<Output, std::string> &output_files,
216 const std::vector<Argument> &args,
217 const std::string &fn_name,
225 const std::vector<Argument> &args,
226 const std::string &fn_name,
234 const std::vector<Argument> &args,
235 const std::string &fn_name,
244 const std::vector<Argument> &,
245 const std::string &fn_name,
255 const std::vector<Argument> &,
256 const std::string &fn_name,
265 const std::vector<Argument> &args,
266 const std::string &fn_name,
274 const std::vector<Argument> &,
275 const std::string &fn_name,
282 const std::vector<Argument> &args,
294 const std::vector<Argument> &args,
295 const std::string &fn_name,
301 const std::vector<Argument> &args,
302 const std::string &fn_name,
313 const std::vector<Argument> &args,
314 const std::vector<Target> &targets);
330 const std::vector<Argument> &args,
331 const std::vector<Target> &targets,
332 const std::vector<std::string> &suffixes);
337 const std::string &fn_name,
374 void (*
free)(
void *,
void *));
502 template<typename T, typename = typename std::enable_if<std::is_same<T,
int>::value>::type>
506 return realize(std::vector<int32_t>{x_size}, target, param_map);
566 template<
typename... Args>
568 std::vector<Expr> collected_args;
574 std::string generate_function_name()
const;
580 bool is_void_return_{
false};
581 std::vector<Type> arg_types_;
593 template<
typename RT,
typename... Args>
596 is_void_return_(std::is_void<RT>::value),
597 arg_types_({type_of<Args>()...}) {
606 return is_void_return_;
614 if (sig.is_void_return_) {
617 stream << sig.ret_type_;
621 for (
const auto &t : sig.arg_types_) {
635 void *address_{
nullptr};
645 template<
typename RT,
typename... Args>
670 template<
typename RT,
typename... Args>
679 return extern_c_function_;
#define internal_assert(c)
#define HALIDE_ATTRIBUTE_DEPRECATED(x)
#define HALIDE_ALWAYS_INLINE
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.
std::vector< Argument > infer_arguments()
Infer the arguments to the Pipeline, sorted into a canonical order: all buffers (sorted alphabeticall...
void set_error_handler(void(*handler)(void *, const char *))
Set the error handler function that be called in the case of runtime errors during halide pipelines.
const Internal::JITHandlers & jit_handlers()
Get a struct containing the currently set custom functions used by JIT.
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 *))
Set a custom task handler to be called by the parallel for loop.
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
const std::map< std::string, JITExtern > & get_jit_externs()
Return the map of previously installed externs.
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(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.
void set_custom_print(void(*handler)(void *, const char *))
Set the function called to print messages from the runtime.
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.
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...
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...
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...
std::vector< Argument > infer_arguments(const Internal::Stmt &body)
void compile_to(const std::map< Output, 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.
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.
const std::vector< CustomLoweringPass > & custom_lowering_passes()
Get the custom lowering passes.
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 *))
Set a custom malloc and free for halide to use.
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 *))
Set a custom parallel for loop launcher.
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< Func > outputs() const
Get the Funcs this pipeline outputs.
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_...
void set_custom_trace(int(*trace_fn)(void *, const halide_trace_event_t *))
Set custom routines to call when tracing is enabled.
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.
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.
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.
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)
ExternCFunction()=default
const ExternSignature & signature() const
ExternCFunction(RT(*f)(Args... args))
ExternSignature()=default
const std::vector< Type > & arg_types() const
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
const Type & ret_type() const
ExternSignature(RT(*f)(Args... args))
bool is_void_return() const
A reference-counted handle to a statement node.
JITExtern(const Func &func)
JITExtern(Pipeline pipeline)
const Pipeline & pipeline() const
JITExtern(RT(*f)(Args... args))
const ExternCFunction & extern_c_function() const
JITExtern(const ExternCFunction &extern_c_function)
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(Runtime::Buffer< T, D > &dst)
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer< T > &dst)
RealizationArg(halide_buffer_t *buf)
RealizationArg(RealizationArg &&from)=default
RealizationArg(Buffer< T > &a, Args &&...args)
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.