RecFilter
modifiers.h
Go to the documentation of this file.
1 #ifndef _MODIFIERS_H_
2 #define _MODIFIERS_H_
3 
4 #include <Halide.h>
5 
6 /** Return true if all Expr in the vector are undef */
7 bool is_undef(Halide::Expr e);
8 
9 /** Return true if all Expr in the vector are undef */
10 bool is_undef(std::vector<Halide::Expr> e);
11 
12 /** Return true if all elements of the Tuple are undef */
13 bool is_undef(Halide::Tuple t);
14 
15 /** Check if a given expression depends upon a variable */
17  Halide::Expr expr, ///< expression to be checked
18  std::string var ///< variable name
19  );
20 
21 /** Check if a given expression contains calls to a Function */
23  Halide::Expr expr, ///< expression to be checked
24  std::string func_name ///< name of Function
25  );
26 
27 
28 /** Substitute a variable in all calls to a particular Function
29  * in a given expression
30  */
31 Halide::Expr substitute_in_func_call(
32  std::string func_name, ///< name of Function
33  std::string var, ///< variable to be substituted
34  Halide::Expr replace, ///< replacement expression
35  Halide::Expr original ///< original expression
36  );
37 
38 /** Substitute all calls to a particular Function by a given expression
39  * the calling args match the given list
40  */
42  std::string func_name, ///< name of Function
43  std::vector<Halide::Expr> call_args, ///< list of calling args to match
44  Halide::Expr replace, ///< replacement expression
45  Halide::Expr original ///< original expression
46  );
47 
48 /** Add a calling argument to all calls to a particular Function */
49 Halide::Expr insert_arg_in_func_call(
50  std::string func_name, ///< name of Function
51  size_t pos, ///< position to add calling arg within list
52  Halide::Expr arg, ///< calling argument to add
53  Halide::Expr original ///< original expression
54  );
55 
56 /** Remove a calling argument from all calls to a particular Function */
57 Halide::Expr remove_arg_from_func_call(
58  std::string func_name, ///< name of Function
59  size_t pos, ///< calling arg index within list to be removed
60  Halide::Expr original ///< original expression
61  );
62 
63 /** Swap two calling arguments of given function in the expression */
64 Halide::Expr swap_args_in_func_call(
65  std::string func_name, ///< name of function to modify
66  size_t va_idx, ///< index of first calling arg
67  size_t vb_idx, ///< index of second calling arg
68  Halide::Expr original ///< original expression
69  );
70 
71 /** Substitute a calling arg in feed forward recursive calls
72  * to a Func; feedforward calls are those where all args in the
73  * Function call are identical to args in Function definition
74  */
76  std::string func_name, ///< name of function to modify
77  std::vector<Halide::Expr> def_arg, ///< args in Function definition
78  size_t pos, ///< index of calling arg to be replaced
79  Halide::Expr new_arg, ///< new calling arg
80  Halide::Expr original ///< original expression
81  );
82 
83 /** Apply zero boundary condition on all tiles except tiles that touch image
84  * borders; this pads tiles by zeros if the intra tile index is out of range -
85  * - less than zero or greater than tile width.
86  * Usually, if the feedforward coeff is 1.0 zero padding is required for in
87  * the Function definition itself - which automatically pads all tiles by zeros.
88  * But in Gaussian filtering feedforward coeff is not 1.0; so Function definition
89  * cannot pad the image by zeros; in such case it is important to forcibly pad
90  * all inner tiles by zeros.
91  */
93  std::string func_name, ///< name of function to modify
94  size_t dim, ///< dimension containing the RVar
95  Halide::Expr def_arg, ///< args in Function definition
96  Halide::Expr boundary, ///< tile width
97  Halide::Expr cond, ///< condition to check tiles touching borders
98  Halide::Expr original ///< original expression
99  );
100 
101 /** Mathematically add an expression to all calls to a particular
102  * Function; the expression to be added is selected from a list of
103  * expressions depending upon the value index of the Function call;
104  * all occurances of arguments of the Function must be replaced by
105  * calling arguments in the selected expression before adding
106  */
107 Halide::Expr augment_func_call(
108  std::string func_name, ///< name of Function
109  std::vector<std::string> func_args, ///< arguments of Function
110  std::vector<Halide::Expr> extra, ///< list of exprs to be algebraically added
111  Halide::Expr original ///< original expression
112  );
113 
114 
115 /** Substitute all calls to a particular Function by
116  * a new Function with the same calling arguments
117  */
118 Halide::Expr substitute_func_call(
119  std::string func_name, ///< name of Function
120  Halide::Internal::Function replace, ///< replacement Function
121  Halide::Expr original ///< original expression
122  );
123 
124 
125 /** Remove all calls to a particular Function or to all
126  * Functions except for a particular Function by identity
127  * as determined by a boolean flag argument, all calls
128  * to the Function are removed if flag is set
129  */
130 Halide::Expr remove_func_calls(
131  std::string func_name, ///< name of Function
132  bool matching, ///< remove calls matching or not matching
133  Halide::Expr original ///< original expression
134  );
135 
136 
137 /** Find all calls to a particular Function and increment
138  * the value_index (Halide::Internal::Call::value_index)
139  * of the call by a given offset
140  */
142  std::string func_name, ///< name of Function
143  int increment, ///< increment to value_index, can be negative
144  Halide::Expr original ///< original expression
145  );
146 
147 /** Swaps two variables in an expression */
148 Halide::Expr swap_vars_in_expr(
149  std::string a, ///< first variable name for swapping
150  std::string b, ///< second variable name for swapping
151  Halide::Expr original ///< original expression
152  );
153 
154 /** Remove all lets by inlining; all sub-expressions will exist once
155  * in memory, but may have many pointers to them, so this doesn't cause
156  * a combinatorial explosion; if you walk over this as if it were a tree,
157  * however, you're going to have a bad time */
158 Halide::Expr remove_lets(Halide::Expr);
159 
160 /** Extract the list of buffers called in the definition a function */
161 std::map<std::string, Halide::Buffer> extract_buffer_calls(Halide::Func func);
162 
163 /** Make sure that all vars with tags INNER, OUTER or FULL have VarTag count
164  * in the same order as they appear in the function definition; this continuity
165  * was broken during tiling or by RecFilterSchedule::split()
166  *
167  * \param[in,out] var_tags list of variable tags to be modified
168  * \param[in] args pure definition args
169  * \param[in] var_splits list of variables created by RecFilterSchedule::split() and the corresponding old variables for the pure definition
170  */
172  std::map<std::string,VarTag>& var_tags,
173  std::vector<std::string> args,
174  std::map<std::string,std::string> var_splits);
175 
176 /** Make sure that all vars with tags INNER, OUTER or FULL have VarTag count
177  * in the same order as they appear in the function definition; this continuity
178  * was broken during tiling or by RecFilterSchedule::split()
179  *
180  * \param[in,out] var_tags list of variable tags to be modified
181  * \param[in] args update definition args
182  * \param[in] var_splits list of variables created by RecFilterSchedule::split() and the corresponding old variables for this update definition
183  */
185  std::map<std::string,VarTag>& var_tags,
186  std::vector<Halide::Expr> args,
187  std::map<std::string,std::string> var_splits);
188 
189 /** Inline a pure function in a list of other functions
190  *
191  * \param[in] f function to be inlined
192  * \param[inout] func_list list of functions in which calls to first parameter must be inlined
193  */
194 void inline_function(Halide::Internal::Function f, std::vector<Halide::Func> func_list);
195 
196 #endif // _MODIFIERS_H_
void reassign_vartag_counts(std::map< std::string, VarTag > &var_tags, std::vector< std::string > args, std::map< std::string, std::string > var_splits)
Make sure that all vars with tags INNER, OUTER or FULL have VarTag count in the same order as they ap...
Halide::Expr substitute_arg_in_feedforward_func_call(std::string func_name, std::vector< Halide::Expr > def_arg, size_t pos, Halide::Expr new_arg, Halide::Expr original)
Substitute a calling arg in feed forward recursive calls to a Func; feedforward calls are those where...
Halide::Expr augment_func_call(std::string func_name, std::vector< std::string > func_args, std::vector< Halide::Expr > extra, Halide::Expr original)
Mathematically add an expression to all calls to a particular Function; the expression to be added is...
Halide::Expr substitute_func_call_with_args(std::string func_name, std::vector< Halide::Expr > call_args, Halide::Expr replace, Halide::Expr original)
Substitute all calls to a particular Function by a given expression the calling args match the given ...
void inline_function(Halide::Internal::Function f, std::vector< Halide::Func > func_list)
Inline a pure function in a list of other functions.
Halide::Expr insert_arg_in_func_call(std::string func_name, size_t pos, Halide::Expr arg, Halide::Expr original)
Add a calling argument to all calls to a particular Function.
std::map< std::string, Halide::Buffer > extract_buffer_calls(Halide::Func func)
Extract the list of buffers called in the definition a function.
Halide::Expr remove_lets(Halide::Expr)
Remove all lets by inlining; all sub-expressions will exist once in memory, but may have many pointer...
Halide::Expr remove_func_calls(std::string func_name, bool matching, Halide::Expr original)
Remove all calls to a particular Function or to all Functions except for a particular Function by ide...
Halide::Expr swap_vars_in_expr(std::string a, std::string b, Halide::Expr original)
Swaps two variables in an expression.
bool expr_depends_on_var(Halide::Expr expr, std::string var)
Check if a given expression depends upon a variable.
Halide::Expr remove_arg_from_func_call(std::string func_name, size_t pos, Halide::Expr original)
Remove a calling argument from all calls to a particular Function.
bool is_undef(Halide::Expr e)
Return true if all Expr in the vector are undef.
Halide::Expr increment_value_index_in_func_call(std::string func_name, int increment, Halide::Expr original)
Find all calls to a particular Function and increment the value_index (Halide::Internal::Call::value_...
Halide::Expr substitute_in_func_call(std::string func_name, std::string var, Halide::Expr replace, Halide::Expr original)
Substitute a variable in all calls to a particular Function in a given expression.
bool expr_depends_on_func(Halide::Expr expr, std::string func_name)
Check if a given expression contains calls to a Function.
Halide::Expr swap_args_in_func_call(std::string func_name, size_t va_idx, size_t vb_idx, Halide::Expr original)
Swap two calling arguments of given function in the expression.
Halide::Expr substitute_func_call(std::string func_name, Halide::Internal::Function replace, Halide::Expr original)
Substitute all calls to a particular Function by a new Function with the same calling arguments...
Halide::Expr apply_zero_boundary_in_func_call(std::string func_name, size_t dim, Halide::Expr def_arg, Halide::Expr boundary, Halide::Expr cond, Halide::Expr original)
Apply zero boundary condition on all tiles except tiles that touch image borders; this pads tiles by ...