Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
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
13namespace Halide {
14namespace Internal {
15
16/**
17 * Remove all let definitions of expr
18 */
20
21/**
22 * Return a list of variables' indices that expr depends on and are in the filter
23 */
24std::vector<int> gather_variables(const Expr &expr,
25 const std::vector<std::string> &filter);
26std::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 */
38std::map<std::string, ReductionVariableInfo> gather_rvariables(const Expr &expr);
39std::map<std::string, ReductionVariableInfo> gather_rvariables(const Tuple &tuple);
40/**
41 * Add necessary let expressions to expr
42 */
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 */
49std::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 */
54std::map<std::string, Box> inference_bounds(const std::vector<Func> &funcs,
55 const std::vector<Box> &output_bounds);
56std::map<std::string, Box> inference_bounds(const Func &func,
57 const Box &output_bounds);
58/**
59 * Convert Box to vector of (min, extent)
60 */
61std::vector<std::pair<Expr, Expr>> box_to_vector(const Box &bounds);
62/**
63 * Return true if bounds0 and bounds1 represent the same bounds.
64 */
65bool equal(const RDom &bounds0, const RDom &bounds1);
66/**
67 * Return a list of variable names
68 */
69std::vector<std::string> vars_to_strings(const std::vector<Var> &vars);
70/**
71 * Return the reduction domain used by expr
72 */
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 */
78std::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 */
84struct BufferInfo {
87};
88std::map<std::string, BufferInfo> find_buffer_param_calls(const Func &func);
89/**
90 * Find all implicit variables in expr
91 */
92std::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
Methods for computing the upper and lower bounds of an expression, and the regions of a function read...
Automatic differentiation.
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines the front-end syntax for reduction domains and reduction variables.
Defines the Scope class, which is used for keeping track of names in a scope while traversing IR.
Defines the Var - the front-end variable.
A halide function.
Definition Func.h:700
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition Reduction.h:33
A multi-dimensional domain over which to iterate.
Definition RDom.h:193
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition Tuple.h:18
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.
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.
std::vector< std::string > vars_to_strings(const std::vector< Var > &vars)
Return a list of variable names.
std::vector< std::pair< Expr, Expr > > box_to_vector(const Box &bounds)
Convert Box to vector of (min, extent)
std::vector< Expr > sort_expressions(const Expr &expr)
Topologically sort the expression graph expressed by expr.
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
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.
std::map< std::string, BufferInfo > find_buffer_param_calls(const Func &func)
std::map< std::string, Box > inference_bounds(const std::vector< Func > &funcs, const std::vector< Box > &output_bounds)
Compute the bounds of funcs.
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,...
std::map< std::string, ReductionVariableInfo > gather_rvariables(const Expr &expr)
ReductionDomain extract_rdom(const Expr &expr)
Return the reduction domain used by expr.
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.
Expr remove_let_definitions(const Expr &expr)
Remove all let definitions of expr.
std::set< std::string > find_implicit_variables(const Expr &expr)
Find all implicit variables in expr.
Expr substitute_rdom_predicate(const std::string &name, const Expr &replacement, const Expr &expr)
Substitute the variable.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
A fragment of Halide syntax.
Definition Expr.h:258
Represents the bounds of a region of arbitrary dimension.
Definition Bounds.h:53
Find all calls to image buffers and parameters in the function.
Return a list of reduction variables the expression or tuple depends on.
Types in the halide type system.
Definition Type.h:283