Halide
DerivativeUtils.h
Go to the documentation of this file.
1 #ifndef HALIDE_INTERNAL_DERIVATIVE_UTILS_H
2 #define HALIDE_INTERNAL_DERIVATIVE_UTILS_H
3 
4 #include <set>
5 
6 #include "Bounds.h"
7 #include "Derivative.h"
8 #include "Expr.h"
9 #include "RDom.h"
10 #include "Scope.h"
11 #include "Var.h"
12 
13 namespace Halide {
14 namespace Internal {
15 
16 /**
17  * Remove all let definitions of expr
18  */
19 Expr remove_let_definitions(const Expr &expr);
20 
21 /**
22  * Return a list of variables' indices that expr depends on and are in the filter
23  */
24 std::vector<int> gather_variables(const Expr &expr,
25  const std::vector<std::string> &filter);
26 std::vector<int> gather_variables(const Expr &expr,
27  const std::vector<Var> &filter);
28 
29 /**
30  * Return a list of reduction variables the expression or tuple depends on
31  */
34  int index;
36  std::string name;
37 };
38 std::map<std::string, ReductionVariableInfo> gather_rvariables(const Expr &expr);
39 std::map<std::string, ReductionVariableInfo> gather_rvariables(const Tuple &tuple);
40 /**
41  * Add necessary let expressions to expr
42  */
43 Expr add_let_expression(const Expr &expr,
44  const std::map<std::string, Expr> &let_var_mapping,
45  const std::vector<std::string> &let_variables);
46 /**
47  * Topologically sort the expression graph expressed by expr
48  */
49 std::vector<Expr> sort_expressions(const Expr &expr);
50 /**
51  * Compute the bounds of funcs. The bounds represent a conservative region
52  * that is used by the "consumers" of the function, except of itself.
53  */
54 std::map<std::string, Box> inference_bounds(const std::vector<Func> &funcs,
55  const std::vector<Box> &output_bounds);
56 std::map<std::string, Box> inference_bounds(const Func &func,
57  const Box &output_bounds);
58 /**
59  * Convert Box to vector of (min, extent)
60  */
61 std::vector<std::pair<Expr, Expr>> box_to_vector(const Box &bounds);
62 /**
63  * Return true if bounds0 and bounds1 represent the same bounds.
64  */
65 bool equal(const RDom &bounds0, const RDom &bounds1);
66 /**
67  * Return a list of variable names
68  */
69 std::vector<std::string> vars_to_strings(const std::vector<Var> &vars);
70 /**
71  * Return the reduction domain used by expr
72  */
73 ReductionDomain extract_rdom(const Expr &expr);
74 /**
75  * expr is new_var == f(var), solve for var == g(new_var)
76  * if multiple new_var corresponds to same var, introduce a RDom
77  */
78 std::pair<bool, Expr> solve_inverse(Expr expr,
79  const std::string &new_var,
80  const std::string &var);
81 /**
82  * Find all calls to image buffers and parameters in the function
83  */
84 struct BufferInfo {
85  int dimension;
87 };
88 std::map<std::string, BufferInfo> find_buffer_param_calls(const Func &func);
89 /**
90  * Find all implicit variables in expr
91  */
92 std::set<std::string> find_implicit_variables(const Expr &expr);
93 /**
94  * Substitute the variable. Also replace all occurrences in rdom.where() predicates.
95  */
97  const std::string &name, const Expr &replacement, const Expr &expr);
98 
99 /**
100  * Return true if expr contains call to func_name
101  */
103  const std::string &func_name, const Expr &expr,
104  const std::map<std::string, Expr> &let_var_mapping);
105 /**
106  * Return true if expr depends on any function or buffer
107  */
109  const Expr &expr,
110  const std::map<std::string, Expr> &let_var_mapping);
111 
112 /**
113  * Replaces call to Func f in Expr e such that the call argument at variable_id
114  * is the pure argument.
115  */
117  int variable_id,
118  const Expr &e);
119 
120 } // namespace Internal
121 } // namespace Halide
122 
123 #endif
Halide::Internal::sort_expressions
std::vector< Expr > sort_expressions(const Expr &expr)
Topologically sort the expression graph expressed by expr.
Scope.h
Derivative.h
Halide::Internal::ReductionVariableInfo
Return a list of reduction variables the expression or tuple depends on.
Definition: DerivativeUtils.h:32
Halide::Internal::ReductionVariableInfo::extent
Expr extent
Definition: DerivativeUtils.h:33
Halide::Internal::is_calling_function
bool is_calling_function(const std::string &func_name, const Expr &expr, const std::map< std::string, Expr > &let_var_mapping)
Return true if expr contains call to func_name.
Bounds.h
Halide::Internal::gather_variables
std::vector< int > gather_variables(const Expr &expr, const std::vector< std::string > &filter)
Return a list of variables' indices that expr depends on and are in the filter.
Halide::Internal::solve_inverse
std::pair< bool, Expr > solve_inverse(Expr expr, const std::string &new_var, const std::string &var)
expr is new_var == f(var), solve for var == g(new_var) if multiple new_var corresponds to same var,...
Var.h
Halide::Internal::ReductionVariableInfo::name
std::string name
Definition: DerivativeUtils.h:36
Halide::Type
Types in the halide type system.
Definition: Type.h:269
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::BufferInfo::dimension
int dimension
Definition: DerivativeUtils.h:85
Halide::Internal::find_buffer_param_calls
std::map< std::string, BufferInfo > find_buffer_param_calls(const Func &func)
Halide::Internal::remove_let_definitions
Expr remove_let_definitions(const Expr &expr)
Remove all let definitions of expr.
Halide::Internal::gather_rvariables
std::map< std::string, ReductionVariableInfo > gather_rvariables(const Expr &expr)
Halide::Internal::box_to_vector
std::vector< std::pair< Expr, Expr > > box_to_vector(const Box &bounds)
Convert Box to vector of (min, extent)
Halide::Internal::ReductionVariableInfo::domain
ReductionDomain domain
Definition: DerivativeUtils.h:35
Halide::Internal::inference_bounds
std::map< std::string, Box > inference_bounds(const std::vector< Func > &funcs, const std::vector< Box > &output_bounds)
Compute the bounds of funcs.
Halide::Internal::find_implicit_variables
std::set< std::string > find_implicit_variables(const Expr &expr)
Find all implicit variables in expr.
Halide::Internal::substitute_rdom_predicate
Expr substitute_rdom_predicate(const std::string &name, const Expr &replacement, const Expr &expr)
Substitute the variable.
Expr.h
Halide::Internal::equal
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
Halide::Func
A halide function.
Definition: Func.h:667
Halide::Internal::substitute_call_arg_with_pure_arg
Expr substitute_call_arg_with_pure_arg(Func f, int variable_id, const Expr &e)
Replaces call to Func f in Expr e such that the call argument at variable_id is the pure argument.
Halide::Internal::vars_to_strings
std::vector< std::string > vars_to_strings(const std::vector< Var > &vars)
Return a list of variable names.
Halide::RDom
A multi-dimensional domain over which to iterate.
Definition: RDom.h:191
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
RDom.h
Halide::Internal::ReductionDomain
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition: Reduction.h:33
Halide::Tuple
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition: Tuple.h:18
Halide::Internal::BufferInfo
Find all calls to image buffers and parameters in the function.
Definition: DerivativeUtils.h:84
Halide::Internal::ReductionVariableInfo::index
int index
Definition: DerivativeUtils.h:34
Halide::Internal::ReductionVariableInfo::min
Expr min
Definition: DerivativeUtils.h:33
Halide::Internal::add_let_expression
Expr add_let_expression(const Expr &expr, const std::map< std::string, Expr > &let_var_mapping, const std::vector< std::string > &let_variables)
Add necessary let expressions to expr.
Halide::Internal::BufferInfo::type
Type type
Definition: DerivativeUtils.h:86
Halide::Internal::extract_rdom
ReductionDomain extract_rdom(const Expr &expr)
Return the reduction domain used by expr.
Halide::Internal::Box
Represents the bounds of a region of arbitrary dimension.
Definition: Bounds.h:53