Halide 22.0.0 Halide compiler and libraries

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