Go to the documentation of this file. 1 #ifndef HALIDE_PIPELINE_H
2 #define HALIDE_PIPELINE_H
10 #include <initializer_list>
29 struct PipelineContents;
51 std::map<std::string, std::string>
extra;
82 void delete_lowering_pass(T *pass) {
125 template<
typename T,
int Dims>
127 :
buf(dst.raw_buffer()) {
129 template<
typename T,
int Dims>
131 :
buf(dst.raw_buffer()) {
133 template<
typename T,
int Dims,
typename... Args,
134 typename =
typename std::enable_if<Internal::all_are_convertible<Buffer<>, Args...>::value>::type>
136 :
buffer_list(std::make_unique<std::vector<
Buffer<>>>(std::initializer_list<
Buffer<>>{a, std::forward<Args>(args)...})) {
154 void prepare_jit_call_arguments(RealizationArg &output,
const Target &target,
const ParamMap ¶m_map,
155 JITUserContext **user_context,
bool is_bounds_inference, Internal::JITCallArgs &args_result);
157 static std::vector<Internal::JITModule> make_externs_jit_module(
const Target &target,
158 std::map<std::string, JITExtern> &externs_in_out);
160 static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
162 static AutoSchedulerFn find_autoscheduler(
const std::string &autoscheduler_name);
164 int call_jit_code(
const Target &target,
const Internal::JITCallArgs &args);
168 Target get_compiled_jit_target()
const;
171 std::vector<Argument> args,
172 const std::vector<Internal::Function> &
outputs,
173 const std::map<std::string, JITExtern> &jit_externs,
174 const Target &target_arg);
191 std::vector<Func>
outputs()
const;
209 void compile_to(
const std::map<OutputFileType, std::string> &output_files,
210 const std::vector<Argument> &args,
211 const std::string &fn_name,
219 const std::vector<Argument> &args,
220 const std::string &fn_name,
228 const std::vector<Argument> &args,
229 const std::string &fn_name,
238 const std::vector<Argument> &,
239 const std::string &fn_name,
249 const std::vector<Argument> &,
250 const std::string &fn_name,
259 const std::vector<Argument> &args,
260 const std::string &fn_name,
268 const std::vector<Argument> &,
269 const std::string &fn_name,
276 const std::vector<Argument> &args,
288 const std::vector<Argument> &args,
289 const std::string &fn_name,
295 const std::vector<Argument> &args,
296 const std::string &fn_name,
307 const std::vector<Argument> &args,
308 const std::vector<Target> &targets);
324 const std::vector<Argument> &args,
325 const std::vector<Target> &targets,
326 const std::vector<std::string> &suffixes);
331 const std::string &fn_name,
401 Realization
realize(JITUserContext *context,
402 std::vector<int32_t> sizes = {},
403 const Target &target = Target(),
415 void realize(RealizationArg output,
416 const Target &target = Target(),
423 void realize(JITUserContext *context,
424 RealizationArg output,
425 const Target &target = Target(),
445 const std::vector<int32_t> &sizes,
449 RealizationArg output,
480 void add_requirement(
const Expr &condition,
const std::vector<Expr> &error_args);
482 template<
typename... Args,
483 typename =
typename std::enable_if<Internal::all_are_printable_args<Args...>::value>::type>
485 std::vector<Expr> collected_args;
495 std::string generate_function_name()
const;
501 bool is_void_return_{
false};
502 std::vector<Type> arg_types_;
508 : ret_type_(ret_type),
509 is_void_return_(is_void_return),
510 arg_types_(arg_types) {
514 template<
typename RT,
typename... Args>
517 is_void_return_(std::is_void<RT>::value),
518 arg_types_({type_of<Args>()...}) {
527 return is_void_return_;
535 if (sig.is_void_return_) {
538 stream << sig.ret_type_;
542 for (
const auto &t : sig.arg_types_) {
556 void *address_{
nullptr};
566 template<
typename RT,
typename... Args>
591 template<
typename RT,
typename... Args>
600 return extern_c_function_;
JITExtern(Pipeline pipeline)
RealizationArg(halide_buffer_t *buf)
#define internal_assert(c)
AutoschedulerParams()=default
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.
AutoSchedulerResults apply_autoscheduler(const Target &target, const AutoschedulerParams &autoscheduler_params) const
Generate a schedule for the pipeline using the specified autoscheduler.
static void add_autoscheduler(const std::string &autoscheduler_name, const AutoSchedulerFn &autoscheduler)
Add a new the autoscheduler method with the given name.
StmtOutputFormat
Used to determine if the output printed to file should be as a normal string or as an HTML file which...
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_...
RealizationArg(Buffer< T, Dims > &a, Args &&...args)
ExternCFunction()=default
RealizationArg(Realization &r)
Pipeline()
Make an undefined Pipeline object.
void clear_custom_lowering_passes()
Remove all previously-set custom lowering passes.
void invalidate_cache()
Invalidate any internal cached state, e.g.
Target get_target_from_environment()
Return the target that Halide will use.
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.
JITHandlers & jit_handlers()
Get a struct containing the currently set custom functions used by JIT.
AutoschedulerParams(const std::string &name)
std::unique_ptr< std::vector< Buffer<> > > buffer_list
std::function< void()> deleter
A reference-counted handle to a statement node.
std::vector< Argument > infer_arguments()
Infer the arguments to the Pipeline, sorted into a canonical order: all buffers (sorted alphabeticall...
ExternSignature(RT(*f)(Args... args))
A context to be passed to Pipeline::realize.
Types in the halide type system.
A class representing a Halide pipeline.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
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 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.
RealizationArg(Realization &&r)
A set of custom overrides of runtime functions.
LinkageType
Type of linkage a function in a lowered Halide module can have.
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
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 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...
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
Internal::IRMutator * pass
const std::vector< Type > & arg_types() const
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.
AutoschedulerParams(const std::string &name, const std::map< std::string, std::string > &extra)
A templated Buffer class that wraps halide_buffer_t and adds functionality.
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.
std::function< void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
ExternCFunction(void *address, const ExternSignature &signature)
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 ...
JITExtern(RT(*f)(Args... args))
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.
std::string schedule_source
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 ...
bool defined() const
Check if this pipeline object is defined.
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer< T, Dims > &dst)
Special the Autoscheduler to be used (if any), along with arbitrary additional arguments specific to ...
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...
A base class for passes over the IR which modify it (e.g.
std::vector< uint8_t > featurization
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args)
#define HALIDE_NO_USER_CODE_INLINE
RealizationArg(Runtime::Buffer< T, Dims > &dst)
std::map< std::string, std::string > extra
void add_custom_lowering_pass(T *pass)
Add a custom pass to be used during lowering.
void print_loop_nest()
Write out the loop nests specified by the schedule for this Pipeline's Funcs.
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
The raw representation of an image passed around by generated Halide code.
const ExternSignature & signature() const
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
Target get_jit_target_from_environment()
Return the target that Halide will use for jit-compilation.
size_t size() const
The number of images in the Realization.
const ExternCFunction & extern_c_function() const
Type type_of()
Construct the halide equivalent of a C type.
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.
A fragment of Halide syntax.
AutoschedulerParams autoscheduler_params
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...
A Realization is a vector of references to existing Buffer objects.
const Type & ret_type() const
const Pipeline & pipeline() const
std::vector< Func > outputs() const
Get the Funcs this pipeline outputs.
Func get_func(size_t index)
Return handle to the index-th Func within the pipeline based on the topological order.
ExternCFunction(RT(*f)(Args... args))
const std::vector< CustomLoweringPass > & custom_lowering_passes()
Get the custom lowering passes.
A struct representing a target machine and os to generate code for.
void compile_jit(const Target &target=get_jit_target_from_environment())
Eagerly jit compile the function to machine code.
@ ExternalPlusMetadata
Visible externally. Argument metadata and an argv wrapper are also generated.
bool is_void_return() const
const std::map< std::string, JITExtern > & get_jit_externs()
Return the map of previously installed externs.
std::string to_string() const
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
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...
static const ParamMap & empty_map()
A const ref to an empty ParamMap.
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...