Halide 16.0.0
Halide compiler and libraries
Pipeline.h
Go to the documentation of this file.
1#ifndef HALIDE_PIPELINE_H
2#define HALIDE_PIPELINE_H
3
4/** \file
5 *
6 * Defines the front-end class representing an entire Halide imaging
7 * pipeline.
8 */
9
10#include <initializer_list>
11#include <map>
12#include <memory>
13#include <vector>
14
15#include "IROperator.h"
16#include "IntrusivePtr.h"
17#include "JITModule.h"
18#include "Module.h"
19#include "ParamMap.h"
20#include "Realization.h"
21#include "Target.h"
22#include "Tuple.h"
23
24namespace Halide {
25
26struct Argument;
27class Callable;
28class Func;
29struct PipelineContents;
30
31/** Special the Autoscheduler to be used (if any), along with arbitrary
32 * additional arguments specific to the given Autoscheduler.
33 *
34 * The 'name' field specifies the type of Autoscheduler
35 * to be used (e.g. Adams2019, Mullapudi2016). If this is an empty string,
36 * no autoscheduling will be done; if not, it mustbe the name of a known Autoscheduler.
37 *
38 * At this time, well-known autoschedulers include:
39 * "Mullapudi2016" -- heuristics-based; the first working autoscheduler; currently built in to libHalide
40 * see http://graphics.cs.cmu.edu/projects/halidesched/
41 * "Adams2019" -- aka "the ML autoscheduler"; currently located in apps/autoscheduler
42 * see https://halide-lang.org/papers/autoscheduler2019.html
43 * "Li2018" -- aka "the gradient autoscheduler"; currently located in apps/gradient_autoscheduler.
44 * see https://people.csail.mit.edu/tzumao/gradient_halide
45 *
46 * The key/value pairs in 'extra' are defined on a per-autoscheduler basis.
47 * An autoscheduler can have any number of required or optional keys.
48 */
50 std::string name;
51 std::map<std::string, std::string> extra;
52
54 /*not-explicit*/ AutoschedulerParams(const std::string &name)
55 : name(name) {
56 }
57 AutoschedulerParams(const std::string &name, const std::map<std::string, std::string> &extra)
58 : name(name), extra(extra) {
59 }
60
61 std::string to_string() const;
62};
63
64namespace Internal {
65class IRMutator;
66struct JITCache;
67struct JITCallArgs;
68} // namespace Internal
69
70/**
71 * Used to determine if the output printed to file should be as a normal string
72 * or as an HTML file which can be opened in a browerser and manipulated via JS and CSS.*/
75 HTML
76};
77
78namespace {
79// Helper for deleting custom lowering passes. In the header so that
80// it goes in user code on windows, where you can have multiple heaps.
81template<typename T>
82void delete_lowering_pass(T *pass) {
83 delete pass;
84}
85} // namespace
86
87/** A custom lowering pass. See Pipeline::add_custom_lowering_pass. */
90 std::function<void()> deleter;
91};
92
93struct JITExtern;
94
96 Target target; // Target specified to the autoscheduler
97 AutoschedulerParams autoscheduler_params; // The autoscheduler used, along with its params
98 std::string schedule_source; // The C++ source code of the generated schedule
99 std::vector<uint8_t> featurization; // The featurization of the pipeline (if any)
100};
101
102class Pipeline;
103
104using AutoSchedulerFn = std::function<void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)>;
105
106/** A class representing a Halide pipeline. Constructed from the Func
107 * or Funcs that it outputs. */
108class Pipeline {
109public:
111 // Only one of the following may be non-null
112 Realization *r{nullptr};
114 std::unique_ptr<std::vector<Buffer<>>> buffer_list;
115
117 : r(&r) {
118 }
120 : r(&r) {
121 }
123 : buf(buf) {
124 }
125 template<typename T, int Dims>
127 : buf(dst.raw_buffer()) {
128 }
129 template<typename T, int Dims>
131 : buf(dst.raw_buffer()) {
132 }
133 template<typename T, int Dims, typename... Args,
134 typename = typename std::enable_if<Internal::all_are_convertible<Buffer<>, Args...>::value>::type>
135 RealizationArg(Buffer<T, Dims> &a, Args &&...args)
136 : buffer_list(std::make_unique<std::vector<Buffer<>>>(std::initializer_list<Buffer<>>{a, std::forward<Args>(args)...})) {
137 }
139
140 size_t size() const {
141 if (r != nullptr) {
142 return r->size();
143 } else if (buffer_list) {
144 return buffer_list->size();
145 }
146 return 1;
147 }
148 };
149
150private:
152
153 // For the three method below, precisely one of the first two args should be non-null
154 void prepare_jit_call_arguments(RealizationArg &output, const Target &target, const ParamMap &param_map,
155 JITUserContext **user_context, bool is_bounds_inference, Internal::JITCallArgs &args_result);
156
157 static std::vector<Internal::JITModule> make_externs_jit_module(const Target &target,
158 std::map<std::string, JITExtern> &externs_in_out);
159
160 static std::map<std::string, AutoSchedulerFn> &get_autoscheduler_map();
161
162 static AutoSchedulerFn find_autoscheduler(const std::string &autoscheduler_name);
163
164 int call_jit_code(const Target &target, const Internal::JITCallArgs &args);
165
166 // Get the value of contents->jit_target, but reality-check that the contents
167 // sensibly match the value. Return Target() if not jitted.
168 Target get_compiled_jit_target() const;
169
170 static Internal::JITCache compile_jit_cache(const Module &module,
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);
175
176public:
177 /** Make an undefined Pipeline object. */
179
180 /** Make a pipeline that computes the given Func. Schedules the
181 * Func compute_root(). */
182 Pipeline(const Func &output);
183
184 /** Make a pipeline that computes the givens Funcs as
185 * outputs. Schedules the Funcs compute_root(). */
186 Pipeline(const std::vector<Func> &outputs);
187
188 std::vector<Argument> infer_arguments(const Internal::Stmt &body);
189
190 /** Get the Funcs this pipeline outputs. */
191 std::vector<Func> outputs() const;
192
193 /** Generate a schedule for the pipeline using the specified autoscheduler. */
195 const AutoschedulerParams &autoscheduler_params) const;
196
197 /** Add a new the autoscheduler method with the given name. Does not affect the current default autoscheduler.
198 * It is an error to call this with the same name multiple times. */
199 static void add_autoscheduler(const std::string &autoscheduler_name, const AutoSchedulerFn &autoscheduler);
200
201 /** Return handle to the index-th Func within the pipeline based on the
202 * topological order. */
203 Func get_func(size_t index);
204
205 /** Compile and generate multiple target files with single call.
206 * Deduces target files based on filenames specified in
207 * output_files map.
208 */
209 void compile_to(const std::map<OutputFileType, std::string> &output_files,
210 const std::vector<Argument> &args,
211 const std::string &fn_name,
212 const Target &target);
213
214 /** Statically compile a pipeline to llvm bitcode, with the given
215 * filename (which should probably end in .bc), type signature,
216 * and C function name. If you're compiling a pipeline with a
217 * single output Func, see also Func::compile_to_bitcode. */
218 void compile_to_bitcode(const std::string &filename,
219 const std::vector<Argument> &args,
220 const std::string &fn_name,
221 const Target &target = get_target_from_environment());
222
223 /** Statically compile a pipeline to llvm assembly, with the given
224 * filename (which should probably end in .ll), type signature,
225 * and C function name. If you're compiling a pipeline with a
226 * single output Func, see also Func::compile_to_llvm_assembly. */
227 void compile_to_llvm_assembly(const std::string &filename,
228 const std::vector<Argument> &args,
229 const std::string &fn_name,
230 const Target &target = get_target_from_environment());
231
232 /** Statically compile a pipeline with multiple output functions to an
233 * object file, with the given filename (which should probably end in
234 * .o or .obj), type signature, and C function name (which defaults to
235 * the same name as this halide function. You probably don't want to
236 * use this directly; call compile_to_static_library or compile_to_file instead. */
237 void compile_to_object(const std::string &filename,
238 const std::vector<Argument> &,
239 const std::string &fn_name,
240 const Target &target = get_target_from_environment());
241
242 /** Emit a header file with the given filename for a pipeline. The
243 * header will define a function with the type signature given by
244 * the second argument, and a name given by the third. You don't
245 * actually have to have defined any of these functions yet to
246 * call this. You probably don't want to use this directly; call
247 * compile_to_static_library or compile_to_file instead. */
248 void compile_to_header(const std::string &filename,
249 const std::vector<Argument> &,
250 const std::string &fn_name,
251 const Target &target = get_target_from_environment());
252
253 /** Statically compile a pipeline to text assembly equivalent to
254 * the object file generated by compile_to_object. This is useful
255 * for checking what Halide is producing without having to
256 * disassemble anything, or if you need to feed the assembly into
257 * some custom toolchain to produce an object file. */
258 void compile_to_assembly(const std::string &filename,
259 const std::vector<Argument> &args,
260 const std::string &fn_name,
261 const Target &target = get_target_from_environment());
262
263 /** Statically compile a pipeline to C source code. This is useful
264 * for providing fallback code paths that will compile on many
265 * platforms. Vectorization will fail, and parallelization will
266 * produce serial code. */
267 void compile_to_c(const std::string &filename,
268 const std::vector<Argument> &,
269 const std::string &fn_name,
270 const Target &target = get_target_from_environment());
271
272 /** Write out an internal representation of lowered code. Useful
273 * for analyzing and debugging scheduling. Can emit html or plain
274 * text. */
275 void compile_to_lowered_stmt(const std::string &filename,
276 const std::vector<Argument> &args,
278 const Target &target = get_target_from_environment());
279
280 /** Write out the loop nests specified by the schedule for this
281 * Pipeline's Funcs. Helpful for understanding what a schedule is
282 * doing. */
284
285 /** Compile to object file and header pair, with the given
286 * arguments. */
287 void compile_to_file(const std::string &filename_prefix,
288 const std::vector<Argument> &args,
289 const std::string &fn_name,
290 const Target &target = get_target_from_environment());
291
292 /** Compile to static-library file and header pair, with the given
293 * arguments. */
294 void compile_to_static_library(const std::string &filename_prefix,
295 const std::vector<Argument> &args,
296 const std::string &fn_name,
297 const Target &target = get_target_from_environment());
298
299 /** Compile to static-library file and header pair once for each target;
300 * each resulting function will be considered (in order) via halide_can_use_target_features()
301 * at runtime, with the first appropriate match being selected for subsequent use.
302 * This is typically useful for specializations that may vary unpredictably by machine
303 * (e.g., SSE4.1/AVX/AVX2 on x86 desktop machines).
304 * All targets must have identical arch-os-bits.
305 */
306 void compile_to_multitarget_static_library(const std::string &filename_prefix,
307 const std::vector<Argument> &args,
308 const std::vector<Target> &targets);
309
310 /** Like compile_to_multitarget_static_library(), except that the object files
311 * are all output as object files (rather than bundled into a static library).
312 *
313 * `suffixes` is an optional list of strings to use for as the suffix for each object
314 * file. If nonempty, it must be the same length as `targets`. (If empty, Target::to_string()
315 * will be used for each suffix.)
316 *
317 * Note that if `targets.size()` > 1, the wrapper code (to select the subtarget)
318 * will be generated with the filename `${filename_prefix}_wrapper.o`
319 *
320 * Note that if `targets.size()` > 1 and `no_runtime` is not specified, the runtime
321 * will be generated with the filename `${filename_prefix}_runtime.o`
322 */
323 void compile_to_multitarget_object_files(const std::string &filename_prefix,
324 const std::vector<Argument> &args,
325 const std::vector<Target> &targets,
326 const std::vector<std::string> &suffixes);
327
328 /** Create an internal representation of lowered code as a self
329 * contained Module suitable for further compilation. */
330 Module compile_to_module(const std::vector<Argument> &args,
331 const std::string &fn_name,
332 const Target &target = get_target_from_environment(),
334
335 /** Eagerly jit compile the function to machine code. This
336 * normally happens on the first call to realize. If you're
337 * running your halide pipeline inside time-sensitive code and
338 * wish to avoid including the time taken to compile a pipeline,
339 * then you can call this ahead of time. Default is to use the Target
340 * returned from Halide::get_jit_target_from_environment()
341 */
343
344 /** Eagerly jit compile the function to machine code and return a callable
345 * struct that behaves like a function pointer. The calling convention
346 * will exactly match that of an AOT-compiled version of this Func
347 * with the same Argument list.
348 */
349 Callable compile_to_callable(const std::vector<Argument> &args,
350 const Target &target = get_jit_target_from_environment());
351
352 /** Install a set of external C functions or Funcs to satisfy
353 * dependencies introduced by HalideExtern and define_extern
354 * mechanisms. These will be used by calls to realize,
355 * infer_bounds, and compile_jit. */
356 void set_jit_externs(const std::map<std::string, JITExtern> &externs);
357
358 /** Return the map of previously installed externs. Is an empty
359 * map unless set otherwise. */
360 const std::map<std::string, JITExtern> &get_jit_externs();
361
362 /** Get a struct containing the currently set custom functions
363 * used by JIT. This can be mutated. Changes will take effect the
364 * next time this Pipeline is realized. */
366
367 /** Add a custom pass to be used during lowering. It is run after
368 * all other lowering passes. Can be used to verify properties of
369 * the lowered Stmt, instrument it with extra code, or otherwise
370 * modify it. The Func takes ownership of the pass, and will call
371 * delete on it when the Func goes out of scope. So don't pass a
372 * stack object, or share pass instances between multiple
373 * Funcs. */
374 template<typename T>
376 // Template instantiate a custom deleter for this type, then
377 // wrap in a lambda. The custom deleter lives in user code, so
378 // that deletion is on the same heap as construction (I hate Windows).
379 add_custom_lowering_pass(pass, [pass]() { delete_lowering_pass<T>(pass); });
380 }
381
382 /** Add a custom pass to be used during lowering, with the
383 * function that will be called to delete it also passed in. Set
384 * it to nullptr if you wish to retain ownership of the object. */
385 void add_custom_lowering_pass(Internal::IRMutator *pass, std::function<void()> deleter);
386
387 /** Remove all previously-set custom lowering passes */
389
390 /** Get the custom lowering passes. */
391 const std::vector<CustomLoweringPass> &custom_lowering_passes();
392
393 /** See Func::realize */
394 Realization realize(std::vector<int32_t> sizes = {}, const Target &target = Target(),
395 const ParamMap &param_map = ParamMap::empty_map());
396
397 /** Same as above, but takes a custom user-provided context to be
398 * passed to runtime functions. A nullptr context is legal, and is
399 * equivalent to calling the variant of realize that does not take
400 * a context. */
402 std::vector<int32_t> sizes = {},
403 const Target &target = Target(),
404 const ParamMap &param_map = ParamMap::empty_map());
405
406 /** Evaluate this Pipeline into an existing allocated buffer or
407 * buffers. If the buffer is also one of the arguments to the
408 * function, strange things may happen, as the pipeline isn't
409 * necessarily safe to run in-place. The realization should
410 * contain one Buffer per tuple component per output Func. For
411 * each individual output Func, all Buffers must have the same
412 * shape, but the shape can vary across the different output
413 * Funcs. This form of realize does *not* automatically copy data
414 * back from the GPU. */
416 const Target &target = Target(),
417 const ParamMap &param_map = ParamMap::empty_map());
418
419 /** Same as above, but takes a custom user-provided context to be
420 * passed to runtime functions. A nullptr context is legal, and
421 * is equivalent to calling the variant of realize that does not
422 * take a context. */
423 void realize(JITUserContext *context,
424 RealizationArg output,
425 const Target &target = Target(),
426 const ParamMap &param_map = ParamMap::empty_map());
427
428 /** For a given size of output, or a given set of output buffers,
429 * determine the bounds required of all unbound ImageParams
430 * referenced. Communicates the result by allocating new buffers
431 * of the appropriate size and binding them to the unbound
432 * ImageParams. */
433 // @{
434 void infer_input_bounds(const std::vector<int32_t> &sizes,
435 const Target &target = get_jit_target_from_environment(),
436 const ParamMap &param_map = ParamMap::empty_map());
438 const Target &target = get_jit_target_from_environment(),
439 const ParamMap &param_map = ParamMap::empty_map());
440 // @}
441
442 /** Variants of infer_inputs_bounds that take a custom user context */
443 // @{
445 const std::vector<int32_t> &sizes,
446 const Target &target = get_jit_target_from_environment(),
447 const ParamMap &param_map = ParamMap::empty_map());
449 RealizationArg output,
450 const Target &target = get_jit_target_from_environment(),
451 const ParamMap &param_map = ParamMap::empty_map());
452 // @}
453
454 /** Infer the arguments to the Pipeline, sorted into a canonical order:
455 * all buffers (sorted alphabetically by name), followed by all non-buffers
456 * (sorted alphabetically by name).
457 This lets you write things like:
458 \code
459 pipeline.compile_to_assembly("/dev/stdout", pipeline.infer_arguments());
460 \endcode
461 */
462 std::vector<Argument> infer_arguments();
463
464 /** Check if this pipeline object is defined. That is, does it
465 * have any outputs? */
466 bool defined() const;
467
468 /** Invalidate any internal cached state, e.g. because Funcs have
469 * been rescheduled. */
471
472 /** Add a top-level precondition to the generated pipeline,
473 * expressed as a boolean Expr. The Expr may depend on parameters
474 * only, and may not call any Func or use a Var. If the condition
475 * is not true at runtime, the pipeline will call halide_error
476 * with the remaining arguments, and return
477 * halide_error_code_requirement_failed. Requirements are checked
478 * in the order added. */
479 // @{
480 void add_requirement(const Expr &condition, const std::vector<Expr> &error_args);
481
482 template<typename... Args,
483 typename = typename std::enable_if<Internal::all_are_printable_args<Args...>::value>::type>
484 inline HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args) {
485 std::vector<Expr> collected_args;
486 Internal::collect_print_args(collected_args, std::forward<Args>(error_args)...);
487 add_requirement(condition, collected_args);
488 }
489 // @}
490
491 /** Generate begin_pipeline and end_pipeline tracing calls for this pipeline. */
493
494private:
495 std::string generate_function_name() const;
496};
497
499private:
500 Type ret_type_; // Only meaningful if is_void_return is false; must be default value otherwise
501 bool is_void_return_{false};
502 std::vector<Type> arg_types_;
503
504public:
505 ExternSignature() = default;
506
507 ExternSignature(const Type &ret_type, bool is_void_return, const std::vector<Type> &arg_types)
508 : ret_type_(ret_type),
509 is_void_return_(is_void_return),
510 arg_types_(arg_types) {
511 internal_assert(!(is_void_return && ret_type != Type()));
512 }
513
514 template<typename RT, typename... Args>
515 explicit ExternSignature(RT (*f)(Args... args))
516 : ret_type_(type_of<RT>()),
517 is_void_return_(std::is_void<RT>::value),
518 arg_types_({type_of<Args>()...}) {
519 }
520
521 const Type &ret_type() const {
522 internal_assert(!is_void_return());
523 return ret_type_;
524 }
525
526 bool is_void_return() const {
527 return is_void_return_;
528 }
529
530 const std::vector<Type> &arg_types() const {
531 return arg_types_;
532 }
533
534 friend std::ostream &operator<<(std::ostream &stream, const ExternSignature &sig) {
535 if (sig.is_void_return_) {
536 stream << "void";
537 } else {
538 stream << sig.ret_type_;
539 }
540 stream << " (*)(";
541 bool comma = false;
542 for (const auto &t : sig.arg_types_) {
543 if (comma) {
544 stream << ", ";
545 }
546 stream << t;
547 comma = true;
548 }
549 stream << ")";
550 return stream;
551 }
552};
553
555private:
556 void *address_{nullptr};
557 ExternSignature signature_;
558
559public:
560 ExternCFunction() = default;
561
563 : address_(address), signature_(signature) {
564 }
565
566 template<typename RT, typename... Args>
567 ExternCFunction(RT (*f)(Args... args))
568 : ExternCFunction((void *)f, ExternSignature(f)) {
569 }
570
571 void *address() const {
572 return address_;
573 }
574 const ExternSignature &signature() const {
575 return signature_;
576 }
577};
578
579struct JITExtern {
580private:
581 // Note that exactly one of pipeline_ and extern_c_function_
582 // can be set in a given JITExtern instance.
583 Pipeline pipeline_;
584 ExternCFunction extern_c_function_;
585
586public:
588 explicit JITExtern(const Func &func);
590
591 template<typename RT, typename... Args>
592 explicit JITExtern(RT (*f)(Args... args))
594 }
595
596 const Pipeline &pipeline() const {
597 return pipeline_;
598 }
600 return extern_c_function_;
601 }
602};
603
604} // namespace Halide
605
606#endif
#define internal_assert(c)
Definition: Errors.h:19
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
Definition: Util.h:45
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition: Buffer.h:122
A halide function.
Definition: Func.h:687
A base class for passes over the IR which modify it (e.g.
Definition: IRMutator.h:26
A halide module.
Definition: Module.h:138
static const ParamMap & empty_map()
A const ref to an empty ParamMap.
Definition: ParamMap.h:110
A class representing a Halide pipeline.
Definition: Pipeline.h:108
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_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 &param_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 &param_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 &param_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 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 &param_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)
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(), const ParamMap &param_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 ...
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 infer_input_bounds(RealizationArg output, const Target &target=get_jit_target_from_environment(), const ParamMap &param_map=ParamMap::empty_map())
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.
void infer_input_bounds(JITUserContext *context, const std::vector< int32_t > &sizes, const Target &target=get_jit_target_from_environment(), const ParamMap &param_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.
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...
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args)
Definition: Pipeline.h:484
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 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 &param_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.
Definition: Pipeline.h:375
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.
Definition: Realization.h:19
size_t size() const
The number of images in the Realization.
A templated Buffer class that wraps halide_buffer_t and adds functionality.
Definition: HalideBuffer.h:216
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
Definition: IROperator.h:335
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.
Definition: Module.h:48
@ 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.
Definition: Type.h:557
std::function< void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
Definition: Pipeline.h:104
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...
Definition: Pipeline.h:73
@ HTML
Definition: Pipeline.h:75
@ Text
Definition: Pipeline.h:74
std::string schedule_source
Definition: Pipeline.h:98
std::vector< uint8_t > featurization
Definition: Pipeline.h:99
AutoschedulerParams autoscheduler_params
Definition: Pipeline.h:97
Special the Autoscheduler to be used (if any), along with arbitrary additional arguments specific to ...
Definition: Pipeline.h:49
AutoschedulerParams(const std::string &name, const std::map< std::string, std::string > &extra)
Definition: Pipeline.h:57
AutoschedulerParams(const std::string &name)
Definition: Pipeline.h:54
std::string to_string() const
std::map< std::string, std::string > extra
Definition: Pipeline.h:51
A custom lowering pass.
Definition: Pipeline.h:88
Internal::IRMutator * pass
Definition: Pipeline.h:89
std::function< void()> deleter
Definition: Pipeline.h:90
A fragment of Halide syntax.
Definition: Expr.h:257
void * address() const
Definition: Pipeline.h:571
ExternCFunction(void *address, const ExternSignature &signature)
Definition: Pipeline.h:562
const ExternSignature & signature() const
Definition: Pipeline.h:574
ExternCFunction(RT(*f)(Args... args))
Definition: Pipeline.h:567
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
Definition: Pipeline.h:507
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
Definition: Pipeline.h:534
const Type & ret_type() const
Definition: Pipeline.h:521
const std::vector< Type > & arg_types() const
Definition: Pipeline.h:530
ExternSignature(RT(*f)(Args... args))
Definition: Pipeline.h:515
bool is_void_return() const
Definition: Pipeline.h:526
A reference-counted handle to a statement node.
Definition: Expr.h:418
JITExtern(const Func &func)
const Pipeline & pipeline() const
Definition: Pipeline.h:596
const ExternCFunction & extern_c_function() const
Definition: Pipeline.h:599
JITExtern(Pipeline pipeline)
JITExtern(RT(*f)(Args... args))
Definition: Pipeline.h:592
JITExtern(const ExternCFunction &extern_c_function)
A set of custom overrides of runtime functions.
Definition: JITModule.h:35
A context to be passed to Pipeline::realize.
Definition: JITModule.h:136
RealizationArg(Buffer< T, Dims > &a, Args &&...args)
Definition: Pipeline.h:135
RealizationArg(halide_buffer_t *buf)
Definition: Pipeline.h:122
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer< T, Dims > &dst)
Definition: Pipeline.h:130
RealizationArg(RealizationArg &&from)=default
RealizationArg(Runtime::Buffer< T, Dims > &dst)
Definition: Pipeline.h:126
RealizationArg(Realization &&r)
Definition: Pipeline.h:119
RealizationArg(Realization &r)
Definition: Pipeline.h:116
std::unique_ptr< std::vector< Buffer<> > > buffer_list
Definition: Pipeline.h:114
A struct representing a target machine and os to generate code for.
Definition: Target.h:19
Types in the halide type system.
Definition: Type.h:276
The raw representation of an image passed around by generated Halide code.