1 #ifndef HALIDE_PIPELINE_H 2 #define HALIDE_PIPELINE_H 10 #include <initializer_list> 28 struct PipelineContents;
50 std::map<std::string, std::string>
extra;
81 void delete_lowering_pass(T *pass) {
103 using AutoSchedulerFn = std::function<void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)>;
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>
153 void prepare_jit_call_arguments(RealizationArg &output,
const Target &target,
154 JITUserContext **user_context,
bool is_bounds_inference, Internal::JITCallArgs &args_result);
156 static std::vector<Internal::JITModule> make_externs_jit_module(
const Target &target,
157 std::map<std::string, JITExtern> &externs_in_out);
159 static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
161 static AutoSchedulerFn find_autoscheduler(
const std::string &autoscheduler_name);
163 int call_jit_code(
const Target &target,
const Internal::JITCallArgs &args);
167 Target get_compiled_jit_target()
const;
170 std::vector<Argument> args,
171 const std::vector<Internal::Function> &
outputs,
172 const std::map<std::string, JITExtern> &jit_externs,
173 const Target &target_arg);
193 std::vector<Func>
outputs()
const;
214 void compile_to(
const std::map<OutputFileType, std::string> &output_files,
215 const std::vector<Argument> &args,
216 const std::string &fn_name,
224 const std::vector<Argument> &args,
225 const std::string &fn_name,
233 const std::vector<Argument> &args,
234 const std::string &fn_name,
243 const std::vector<Argument> &,
244 const std::string &fn_name,
254 const std::vector<Argument> &,
255 const std::string &fn_name,
264 const std::vector<Argument> &args,
265 const std::string &fn_name,
273 const std::vector<Argument> &,
274 const std::string &fn_name,
281 const std::vector<Argument> &args,
293 const std::vector<Argument> &args,
294 const std::string &fn_name,
300 const std::vector<Argument> &args,
301 const std::string &fn_name,
312 const std::vector<Argument> &args,
313 const std::vector<Target> &targets);
329 const std::vector<Argument> &args,
330 const std::vector<Target> &targets,
331 const std::vector<std::string> &suffixes);
336 const std::string &fn_name,
399 Realization realize(std::vector<int32_t> sizes = {},
const Target &target = Target());
405 Realization
realize(JITUserContext *context,
406 std::vector<int32_t> sizes = {},
407 const Target &target = Target());
418 void realize(RealizationArg output,
const Target &target = Target());
424 void realize(JITUserContext *context,
425 RealizationArg output,
426 const Target &target = Target());
443 const std::vector<int32_t> &sizes,
446 RealizationArg output,
476 void add_requirement(
const Expr &condition,
const std::vector<Expr> &error_args);
478 template<
typename... Args,
479 typename =
typename std::enable_if<Internal::all_are_printable_args<Args...>::value>::type>
481 std::vector<Expr> collected_args;
491 std::string generate_function_name()
const;
497 bool is_void_return_{
false};
498 std::vector<Type> arg_types_;
504 : ret_type_(ret_type),
505 is_void_return_(is_void_return),
506 arg_types_(arg_types) {
510 template<
typename RT,
typename... Args>
513 is_void_return_(
std::is_void<RT>::value),
514 arg_types_({type_of<Args>()...}) {
523 return is_void_return_;
531 if (sig.is_void_return_) {
534 stream << sig.ret_type_;
538 for (
const auto &t : sig.arg_types_) {
552 void *address_{
nullptr};
562 template<
typename RT,
typename... Args>
587 template<
typename RT,
typename... Args>
596 return extern_c_function_;
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
std::function< void()> deleter
A fragment of Halide syntax.
void invalidate_cache()
Invalidate any internal cached state, e.g.
const Pipeline & pipeline() const
A class representing a Halide pipeline.
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...
RealizationArg(halide_buffer_t *buf)
Target get_target_from_environment()
Return the target that Halide will use.
Pipeline()
Make an undefined Pipeline object.
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
AutoSchedulerResults apply_autoscheduler(const Target &target, const AutoschedulerParams &autoscheduler_params) const
Generate a schedule for the pipeline using the specified autoscheduler.
A Realization is a vector of references to existing Buffer objects.
Internal::IRMutator * pass
bool defined() const
Check if this pipeline object is defined.
A set of custom overrides of runtime functions.
std::map< std::string, std::string > extra
Defines Module, an IR container that fully describes a Halide program.
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.
A struct representing a target machine and os to generate code for.
#define internal_assert(c)
RealizationArg(Buffer< T, Dims > &a, Args &&...args)
std::string to_string() const
std::unique_ptr< std::vector< Buffer<> > > buffer_list
RealizationArg(Realization &r)
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide's bounds tools to query properties of it.
ExternCFunction()=default
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...
std::vector< Func > outputs() const
Get the Funcs this pipeline outputs.
Defines the structure that describes a Halide target.
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.
void print_loop_nest()
Write out the loop nests specified by the schedule for this Pipeline's Funcs.
Defines the struct representing lifetime and dependencies of a JIT compiled halide pipeline...
ExternSignature(RT(*f)(Args... args))
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.
RealizationArg(Realization &&r)
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Func get_func(size_t index)
Return handle to the index-th Func within the pipeline based on the topological order.
JITExtern(RT(*f)(Args... args))
A templated Buffer class that wraps halide_buffer_t and adds functionality.
const std::vector< Type > & arg_types() const
Visible externally. Argument metadata and an argv wrapper are also generated.
AutoschedulerParams()=default
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.
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...
LinkageType
Type of linkage a function in a lowered Halide module can have.
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.
std::function< void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
ExternCFunction(RT(*f)(Args... args))
static void add_autoscheduler(const std::string &autoscheduler_name, const AutoSchedulerFn &autoscheduler)
Add a new the autoscheduler method with the given name.
#define HALIDE_NO_USER_CODE_INLINE
AutoschedulerParams(const std::string &name)
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...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)
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 ...
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...
Support classes for reference-counting via intrusive shared pointers.
std::string schedule_source
ExternCFunction(void *address, const ExternSignature &signature)
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 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.
const ExternCFunction & extern_c_function() const
AutoschedulerParams autoscheduler_params
Realization realize(std::vector< int32_t > sizes={}, const Target &target=Target())
See Func::realize.
const std::vector< CustomLoweringPass > & custom_lowering_passes()
Get the custom lowering passes.
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 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 ...
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
std::vector< uint8_t > featurization
void add_custom_lowering_pass(T *pass)
Add a custom pass to be used during lowering.
Defines Realization - a vector of Buffer for use in pipelines with multiple outputs.
JITHandlers & jit_handlers()
Get a struct containing the currently set custom functions used by JIT.
A context to be passed to Pipeline::realize.
RealizationArg(Runtime::Buffer< T, Dims > &dst)
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.
const ExternSignature & signature() const
Types in the halide type system.
const std::map< std::string, JITExtern > & get_jit_externs()
Return the map of previously installed externs.
const Type & ret_type() const
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
std::vector< Internal::Stmt > requirements() const
Get the requirements of this pipeline.
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...
size_t size() const
The number of images in the Realization.
Target get_jit_target_from_environment()
Return the target that Halide will use for jit-compilation.
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...
The raw representation of an image passed around by generated Halide code.
A base class for passes over the IR which modify it (e.g.
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 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...
void clear_custom_lowering_passes()
Remove all previously-set custom lowering passes.
bool is_void_return() const
Type type_of()
Construct the halide equivalent of a C type.
Defines Tuple - the front-end handle on small arrays of expressions.
void compile_jit(const Target &target=get_jit_target_from_environment())
Eagerly jit compile the function to machine code.
JITExtern(Pipeline pipeline)
StmtOutputFormat
Used to determine if the output printed to file should be as a normal string or as an HTML file which...