Halide
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 
24 namespace Halide {
25 
26 struct Argument;
27 class Callable;
28 class Func;
29 struct 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 
53  AutoschedulerParams() = default;
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 
64 namespace Internal {
65 class IRMutator;
66 struct JITCache;
67 struct 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.*/
76 };
77 
78 namespace {
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.
81 template<typename T>
82 void 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 
93 struct 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 
102 class Pipeline;
103 
104 using 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. */
108 class Pipeline {
109 public:
110  struct RealizationArg {
111  // Only one of the following may be non-null
112  Realization *r{nullptr};
113  halide_buffer_t *buf{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  }
138  RealizationArg(RealizationArg &&from) = default;
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 
150 private:
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 
176 public:
177  /** Make an undefined Pipeline object. */
178  Pipeline();
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,
277  StmtOutputFormat fmt = Text,
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. */
283  void print_loop_nest();
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  */
342  void compile_jit(const Target &target = get_jit_target_from_environment());
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>
375  void add_custom_lowering_pass(T *pass) {
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. */
401  Realization realize(JITUserContext *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. */
415  void realize(RealizationArg output,
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());
437  void infer_input_bounds(RealizationArg output,
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  // @{
444  void infer_input_bounds(JITUserContext *context,
445  const std::vector<int32_t> &sizes,
446  const Target &target = get_jit_target_from_environment(),
447  const ParamMap &param_map = ParamMap::empty_map());
448  void infer_input_bounds(JITUserContext *context,
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. */
470  void invalidate_cache();
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. */
492  void trace_pipeline();
493 
494 private:
495  std::string generate_function_name() const;
496 };
497 
499 private:
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 
504 public:
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 
555 private:
556  void *address_{nullptr};
557  ExternSignature signature_;
558 
559 public:
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 
579 struct JITExtern {
580 private:
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 
586 public:
587  explicit JITExtern(Pipeline pipeline);
588  explicit JITExtern(const Func &func);
590 
591  template<typename RT, typename... Args>
592  explicit JITExtern(RT (*f)(Args... args))
593  : JITExtern(ExternCFunction(f)) {
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
Halide::JITExtern::JITExtern
JITExtern(Pipeline pipeline)
Halide::Callable
Definition: Callable.h:82
Tuple.h
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(halide_buffer_t *buf)
Definition: Pipeline.h:122
internal_assert
#define internal_assert(c)
Definition: Errors.h:19
Halide::AutoschedulerParams::AutoschedulerParams
AutoschedulerParams()=default
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::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::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::HTML
@ HTML
Definition: Pipeline.h:75
Halide::Pipeline::RealizationArg
Definition: Pipeline.h:110
IROperator.h
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:73
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::RealizationArg::RealizationArg
RealizationArg(Buffer< T, Dims > &a, Args &&...args)
Definition: Pipeline.h:135
Halide::ExternCFunction::ExternCFunction
ExternCFunction()=default
Target.h
Halide::AutoschedulerParams::name
std::string name
Definition: Pipeline.h:50
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(Realization &r)
Definition: Pipeline.h:116
Halide::Pipeline::Pipeline
Pipeline()
Make an undefined Pipeline object.
Halide::Pipeline::clear_custom_lowering_passes
void clear_custom_lowering_passes()
Remove all previously-set custom lowering passes.
Halide::ParamMap
Definition: ParamMap.h:17
Halide::Pipeline::invalidate_cache
void invalidate_cache()
Invalidate any internal cached state, e.g.
Halide::get_target_from_environment
Target get_target_from_environment()
Return the target that Halide will use.
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(std::vector< int32_t > sizes={}, const Target &target=Target(), const ParamMap &param_map=ParamMap::empty_map())
See Func::realize.
Halide::Text
@ Text
Definition: Pipeline.h:74
Halide::Pipeline::RealizationArg::buf
halide_buffer_t * buf
Definition: Pipeline.h:113
Halide::Pipeline::jit_handlers
JITHandlers & jit_handlers()
Get a struct containing the currently set custom functions used by JIT.
Halide::AutoschedulerParams::AutoschedulerParams
AutoschedulerParams(const std::string &name)
Definition: Pipeline.h:54
Halide::Internal::IntrusivePtr< PipelineContents >
Halide::Pipeline::RealizationArg::buffer_list
std::unique_ptr< std::vector< Buffer<> > > buffer_list
Definition: Pipeline.h:114
Halide::CustomLoweringPass::deleter
std::function< void()> deleter
Definition: Pipeline.h:90
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition: Expr.h:418
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::ExternSignature::ExternSignature
ExternSignature(RT(*f)(Args... args))
Definition: Pipeline.h:515
Halide::JITUserContext
A context to be passed to Pipeline::realize.
Definition: JITModule.h:136
Halide::Module
A halide module.
Definition: Module.h:138
Halide::Type
Types in the halide type system.
Definition: Type.h:276
Halide::ExternCFunction
Definition: Pipeline.h:554
Halide::Pipeline
A class representing a Halide pipeline.
Definition: Pipeline.h:108
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
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::CustomLoweringPass
A custom lowering pass.
Definition: Pipeline.h:88
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::RealizationArg::RealizationArg
RealizationArg(Realization &&r)
Definition: Pipeline.h:119
Halide::JITHandlers
A set of custom overrides of runtime functions.
Definition: JITModule.h:35
Halide::LinkageType
LinkageType
Type of linkage a function in a lowered Halide module can have.
Definition: Module.h:48
JITModule.h
Halide::Buffer
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition: Argument.h:16
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::infer_input_bounds
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...
Halide::Internal::collect_print_args
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
Definition: IROperator.h:335
Halide::CustomLoweringPass::pass
Internal::IRMutator * pass
Definition: Pipeline.h:89
Halide::ExternSignature::arg_types
const std::vector< Type > & arg_types() const
Definition: Pipeline.h:530
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::AutoschedulerParams::AutoschedulerParams
AutoschedulerParams(const std::string &name, const std::map< std::string, std::string > &extra)
Definition: Pipeline.h:57
Halide::Runtime::Buffer
A templated Buffer class that wraps halide_buffer_t and adds functionality.
Definition: HalideBuffer.h:121
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::Internal::JITCache
Definition: JITModule.h:286
ParamMap.h
Halide::AutoSchedulerFn
std::function< void(const Pipeline &, const Target &, const AutoschedulerParams &, AutoSchedulerResults *outputs)> AutoSchedulerFn
Definition: Pipeline.h:104
Halide::Pipeline::RealizationArg::r
Realization * r
Definition: Pipeline.h:112
Halide::ExternCFunction::ExternCFunction
ExternCFunction(void *address, const ExternSignature &signature)
Definition: Pipeline.h:562
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::JITExtern::JITExtern
JITExtern(RT(*f)(Args... args))
Definition: Pipeline.h:592
Halide::ExternCFunction::address
void * address() const
Definition: Pipeline.h:571
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::AutoSchedulerResults::schedule_source
std::string schedule_source
Definition: Pipeline.h:98
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::defined
bool defined() const
Check if this pipeline object is defined.
Halide::Pipeline::RealizationArg::RealizationArg
HALIDE_NO_USER_CODE_INLINE RealizationArg(Buffer< T, Dims > &dst)
Definition: Pipeline.h:130
Halide::Pipeline::RealizationArg::size
size_t size() const
Definition: Pipeline.h:140
Halide::Func
A halide function.
Definition: Func.h:687
Halide::AutoschedulerParams
Special the Autoscheduler to be used (if any), along with arbitrary additional arguments specific to ...
Definition: Pipeline.h:49
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::Internal::IRMutator
A base class for passes over the IR which modify it (e.g.
Definition: IRMutator.h:26
Halide::AutoSchedulerResults::featurization
std::vector< uint8_t > featurization
Definition: Pipeline.h:99
Halide::Pipeline::add_requirement
HALIDE_NO_USER_CODE_INLINE void add_requirement(const Expr &condition, Args &&...error_args)
Definition: Pipeline.h:484
HALIDE_NO_USER_CODE_INLINE
#define HALIDE_NO_USER_CODE_INLINE
Definition: Util.h:45
Halide::Pipeline::RealizationArg::RealizationArg
RealizationArg(Runtime::Buffer< T, Dims > &dst)
Definition: Pipeline.h:126
Halide::AutoschedulerParams::extra
std::map< std::string, std::string > extra
Definition: Pipeline.h:51
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:375
Halide::ExternSignature
Definition: Pipeline.h:498
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::trace_pipeline
void trace_pipeline()
Generate begin_pipeline and end_pipeline tracing calls for this pipeline.
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition: HalideRuntime.h:1490
Halide::ExternCFunction::signature
const ExternSignature & signature() const
Definition: Pipeline.h:574
Halide::ExternSignature::ExternSignature
ExternSignature(const Type &ret_type, bool is_void_return, const std::vector< Type > &arg_types)
Definition: Pipeline.h:507
Halide::get_jit_target_from_environment
Target get_jit_target_from_environment()
Return the target that Halide will use for jit-compilation.
Halide::Realization::size
size_t size() const
The number of images in the Realization.
Halide::JITExtern::extern_c_function
const ExternCFunction & extern_c_function() const
Definition: Pipeline.h:599
Halide::AutoSchedulerResults::target
Target target
Definition: Pipeline.h:96
Halide::type_of
Type type_of()
Construct the halide equivalent of a C type.
Definition: Type.h:557
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::Expr
A fragment of Halide syntax.
Definition: Expr.h:257
Halide::AutoSchedulerResults::autoscheduler_params
AutoschedulerParams autoscheduler_params
Definition: Pipeline.h:97
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::Realization
A Realization is a vector of references to existing Buffer objects.
Definition: Realization.h:19
Halide::ExternSignature::ret_type
const Type & ret_type() const
Definition: Pipeline.h:521
Halide::JITExtern::pipeline
const Pipeline & pipeline() const
Definition: Pipeline.h:596
Module.h
Halide::Pipeline::outputs
std::vector< Func > outputs() const
Get the Funcs this pipeline outputs.
Halide::AutoSchedulerResults
Definition: Pipeline.h:95
IntrusivePtr.h
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::ExternCFunction::ExternCFunction
ExternCFunction(RT(*f)(Args... args))
Definition: Pipeline.h:567
Halide::Pipeline::custom_lowering_passes
const std::vector< CustomLoweringPass > & custom_lowering_passes()
Get the custom lowering passes.
Realization.h
Halide::Target
A struct representing a target machine and os to generate code for.
Definition: Target.h:19
Halide::Pipeline::compile_jit
void compile_jit(const Target &target=get_jit_target_from_environment())
Eagerly jit compile the function to machine code.
Halide::LinkageType::ExternalPlusMetadata
@ ExternalPlusMetadata
Visible externally. Argument metadata and an argv wrapper are also generated.
Halide::ExternSignature::is_void_return
bool is_void_return() const
Definition: Pipeline.h:526
Halide::JITExtern
Definition: Pipeline.h:579
Halide::Pipeline::get_jit_externs
const std::map< std::string, JITExtern > & get_jit_externs()
Return the map of previously installed externs.
Halide::AutoschedulerParams::to_string
std::string to_string() const
Halide::ExternSignature::operator<<
friend std::ostream & operator<<(std::ostream &stream, const ExternSignature &sig)
Definition: Pipeline.h:534
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::ParamMap::empty_map
static const ParamMap & empty_map()
A const ref to an empty ParamMap.
Definition: ParamMap.h:110
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...