RecFilter
recfilter_internals.h
Go to the documentation of this file.
1 #ifndef _RECURSIVE_FILTER_INTERNALS_H_
2 #define _RECURSIVE_FILTER_INTERNALS_H_
3 
4 #include <vector>
5 #include <string>
6 #include <Halide.h>
7 
8 /** Info about scans in a particular dimension */
9 struct FilterInfo {
10  int filter_order; ///< order of recursive filter in a given dimension
11  int filter_dim; ///< dimension id
12  int num_scans; ///< number of scans in the dimension that must be tiled
13  int image_width; ///< image width in this dimension
14  int tile_width; ///< tile width in this dimension
15  Halide::Var var; ///< variable that represents this dimension
16  Halide::RDom rdom; ///< RDom update domain of each scan
17  std::vector<bool> scan_causal; ///< causal or anticausal flag for each scan
18  std::vector<int> scan_id; ///< scan or update definition id of each scan
19 };
20 
21 // ----------------------------------------------------------------------------
22 
23 enum FunctionTag : int {
24  INLINE = 0x000, ///< function to be removed by inlining
25  INTER = 0x010, ///< filter over tail elements across tiles (single 1D scan)
26  INTRA_N = 0x020, ///< filter within tile (multiple scans in multiple dimensions)
27  INTRA_1 = 0x040, ///< filter within tile (single scan in one dimension)
28  REINDEX = 0x100, ///< function that reindexes a subset of another function to write to global mem
29 };
30 
31 enum VariableTag: int {
32  INVALID = 0x0000, ///< invalid var
33  FULL = 0x0010, ///< full dimension before tiling
34  INNER = 0x0020, ///< inner dimension after tiling
35  OUTER = 0x0040, ///< outer dimension after tiling
36  TAIL = 0x0080, ///< if dimension is at lower granularity
37  SCAN = 0x0100, ///< if dimension is a scan
38  CHANNEL = 0x0200, ///< if dimension represents RGB channels
39  __1 = 0x0001, ///< first variable with one of the above tags
40  __2 = 0x0002, ///< second variable with one of the above tags
41  __3 = 0x0004, ///< third variable with one of the above tags
42  __4 = 0x0008, ///< fourth variable with one of the above tags
43  SPLIT = 0x1000, ///< any variable generated by split scheduling operations
44 };
45 
46 
47 /** @name Logical operations for scheduling tags */
48 // {@
49 VarTag operator |(const VarTag &a, const VarTag &b);
50 VarTag operator &(const VarTag &a, const VarTag &b);
51 VariableTag operator |(const VariableTag &a, const VariableTag &b);
52 VariableTag operator &(const VariableTag &a, const VariableTag &b);
53 
54 bool operator==(const FuncTag &a, const FuncTag &b);
55 bool operator==(const VarTag &a, const VarTag &b);
56 bool operator!=(const FuncTag &a, const FuncTag &b);
57 bool operator!=(const VarTag &a, const VarTag &b);
58 bool operator==(const FuncTag &a, const FunctionTag &b);
59 bool operator==(const VarTag &a, const VariableTag &b);
60 // @}
61 
62 
63 /** @name Utils to print scheduling tags */
64 // {@
65 std::ostream &operator<<(std::ostream &s, const FunctionTag &f);
66 std::ostream &operator<<(std::ostream &s, const VariableTag &v);
67 std::ostream &operator<<(std::ostream &s, const FuncTag &f);
68 std::ostream &operator<<(std::ostream &s, const VarTag &v);
69 // @}
70 
71 
72 /** Scheduling tags for Functions */
73 class FuncTag {
74 public:
75  FuncTag(void) : tag(INLINE){}
76  FuncTag(const FuncTag &t) : tag(t.tag) {}
77  FuncTag(const FunctionTag &t) : tag(t) {}
78  FuncTag& operator=(const FuncTag &t) { tag=t.tag; return *this; }
79  FuncTag& operator=(const FunctionTag &t) { tag=t; return *this; }
80  int as_integer(void) const { return static_cast<int>(tag); }
81 
82 private:
83  FunctionTag tag;
84 };
85 
86 // ----------------------------------------------------------------------------
87 
88 /** Recursive filter function with scheduling interface */
90 public:
91  /** Halide function */
92  Halide::Internal::Function func;
93 
94  /** Category tag for the function */
96 
97  /** Category tags for all the pure def vars */
98  std::map<std::string, VarTag> pure_var_category;
99 
100  /** Category tags for all the vars in all the update defs */
101  std::vector<std::map<std::string,VarTag> > update_var_category;
102 
103  /** List of new vars created by RecFilterSchedule::split() on pure definition */
104  std::map<std::string, std::string> pure_var_splits;
105 
106  /** List of new vars created by RecFilterSchedule::split() on update definitions */
107  std::map<int, std::map<std::string, std::string> > update_var_splits;
108 
109  /** Name of consumer function. This can be set if this function has REINDEX tag set
110  * because only REINDEX functions are guaranteed to have a single consumer */
111  std::string consumer_func;
112 
113  /** Name of producer function. This can be set if this function has REINDEX tag set
114  * because only REINDEX functions are guaranteed to have a single producer */
115  std::string producer_func;
116 
117  /** External consumer function which consumes RecFilter's output;
118  * external consumer means a Func outside the RecFilter pipeline that consumes the output
119  * of the RecFilter. This is set by RecFilter::compute_at() and is useful for merging the final
120  * stage of the recfilter and initial stage of next filter. This can be set if
121  * this function has REINDEX tag set; only REINDEX functions are guaranteed to have
122  * a single consumer */
124 
125  /** External consumer function's loop level at which the RecFilter's output is consumed;
126  * external consumer means a Func outside the RecFilter pipeline that consumes the output
127  * of the RecFilter. This is set by RecFilter::compute_at() and is useful for merging the final
128  * stage of the recfilter and initial stage of next filter. This can be set if
129  * this function has REINDEX tag set; only REINDEX functions are guaranteed to have
130  * a single consumer */
132 
133  /** Schedule for pure def of the function as valid Halide code */
134  std::vector<std::string> pure_schedule;
135 
136  /** Schedule for update defs of the function as valid Halide code */
137  std::map<int, std::vector<std::string> > update_schedule;
138 };
139 
140 // ----------------------------------------------------------------------------
141 
142 /** Data members of the recursive filter */
144  /** Smart pointer */
145  mutable Halide::Internal::RefCount ref_count;
146 
147  /** Flag to indicate if the filter has been tiled */
148  bool tiled;
149 
150  /** Flag to indicate if the filter has been JIT compiled, required before execution */
151  bool compiled;
152 
153  /** Flag to indicate if the filter has been finalized, required before compilation */
154  bool finalized;
155 
156  /** Image border expression */
158 
159  /** Name of recursive filter as well as function that contains the
160  * definition of the filter */
161  std::string name;
162 
163  /** Filter output type */
164  Halide::Type type;
165 
166  /** Info about all the scans in the recursive filter */
167  std::vector<FilterInfo> filter_info;
168 
169  /** List of functions along with their names and their schedules */
170  std::map<std::string, RecFilterFunc> func;
171 
172  /** Feed forward coeffs, only one for each scan */
173  Halide::Image<float> feedfwd_coeff;
174 
175  /** Feedback coeffs (num_scans x max_order) order j-th coeff of i-th scan is (i+1,j) */
176  Halide::Image<float> feedback_coeff;
177 
178  /** Compilation and execution target */
179  Halide::Target target;
180 };
181 
182 #endif // _RECURSIVE_FILTER_INTERNALS_H_
std::vector< bool > scan_causal
causal or anticausal flag for each scan
bool finalized
Flag to indicate if the filter has been finalized, required before compilation.
if dimension represents RGB channels
std::map< std::string, RecFilterFunc > func
List of functions along with their names and their schedules.
Halide::Type type
Filter output type.
filter within tile (multiple scans in multiple dimensions)
std::map< int, std::map< std::string, std::string > > update_var_splits
List of new vars created by RecFilterSchedule::split() on update definitions.
filter over tail elements across tiles (single 1D scan)
second variable with one of the above tags
Halide::Func external_consumer_func
External consumer function which consumes RecFilter's output; external consumer means a Func outside ...
std::map< std::string, VarTag > pure_var_category
Category tags for all the pure def vars.
Recursive filter function with scheduling interface.
Halide::Target target
Compilation and execution target.
std::vector< int > scan_id
scan or update definition id of each scan
int image_width
image width in this dimension
std::vector< FilterInfo > filter_info
Info about all the scans in the recursive filter.
std::vector< std::string > pure_schedule
Schedule for pure def of the function as valid Halide code.
Halide::Image< float > feedback_coeff
Feedback coeffs (num_scans x max_order) order j-th coeff of i-th scan is (i+1,j)
Halide::Internal::Function func
Halide function.
filter within tile (single scan in one dimension)
bool compiled
Flag to indicate if the filter has been JIT compiled, required before execution.
bool clamped_border
Image border expression.
Info about scans in a particular dimension.
std::string producer_func
Name of producer function.
Halide::RDom rdom
RDom update domain of each scan.
Scheduling tags for RecFilter function dimensions.
Definition: recfilter.h:635
Data members of the recursive filter.
inner dimension after tiling
FuncTag & operator=(const FunctionTag &t)
first variable with one of the above tags
Scheduling tags for Functions.
FuncTag(const FuncTag &t)
int filter_order
order of recursive filter in a given dimension
fourth variable with one of the above tags
Halide::Var var
variable that represents this dimension
full dimension before tiling
FuncTag(const FunctionTag &t)
FuncTag func_category
Category tag for the function.
int num_scans
number of scans in the dimension that must be tiled
Halide::Image< float > feedfwd_coeff
Feed forward coeffs, only one for each scan.
bool operator!=(const FuncTag &a, const FuncTag &b)
std::vector< std::map< std::string, VarTag > > update_var_category
Category tags for all the vars in all the update defs.
FuncTag & operator=(const FuncTag &t)
int tile_width
tile width in this dimension
invalid var
std::map< std::string, std::string > pure_var_splits
List of new vars created by RecFilterSchedule::split() on pure definition.
outer dimension after tiling
if dimension is a scan
function to be removed by inlining
function that reindexes a subset of another function to write to global mem
Halide::Var external_consumer_var
External consumer function's loop level at which the RecFilter's output is consumed; external consume...
std::map< int, std::vector< std::string > > update_schedule
Schedule for update defs of the function as valid Halide code.
if dimension is at lower granularity
int as_integer(void) const
VarTag operator|(const VarTag &a, const VarTag &b)
third variable with one of the above tags
std::ostream & operator<<(std::ostream &s, const FunctionTag &f)
bool operator==(const FuncTag &a, const FuncTag &b)
int filter_dim
dimension id
Halide::Internal::RefCount ref_count
Smart pointer.
std::string consumer_func
Name of consumer function.
bool tiled
Flag to indicate if the filter has been tiled.
VarTag operator&(const VarTag &a, const VarTag &b)
any variable generated by split scheduling operations
std::string name
Name of recursive filter as well as function that contains the definition of the filter.