Halide 22.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
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 */
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 */
32 struct ReductionVariableInfo {
33 Expr min, extent;
34 int index;
35 ReductionDomain domain;
36 std::string name;
37};
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 */
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 */
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 */
65 bool 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 */
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 */
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 */
84 struct BufferInfo {
85 int dimension;
86 Type type;
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 */
96 Expr substitute_rdom_predicate(
97 const std::string &name, const Expr &replacement, const Expr &expr);
98
99/**
100 * Return true if expr contains call to func_name
101 */
102 bool is_calling_function(
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 */
108 bool is_calling_function(
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 */
116 Expr substitute_call_arg_with_pure_arg(Func f,
117 int variable_id,
118 const Expr &e);
119
120} // namespace Internal
121} // namespace Halide
122
123#endif
Bounds.h
Methods for computing the upper and lower bounds of an expression, and the regions of a function read...
Derivative.h
Automatic differentiation.
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
RDom.h
Defines the front-end syntax for reduction domains and reduction variables.
Scope.h
Defines the Scope class, which is used for keeping track of names in a scope while traversing IR.
Var.h
Defines the Var - the front-end variable.
Halide::Func
A halide function.
Definition Func.h:728
Halide::Internal::ReductionDomain
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition Reduction.h:38
Halide::RDom
A multi-dimensional domain over which to iterate.
Definition RDom.h:193
Halide::Tuple
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition Tuple.h:18
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::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::vars_to_strings
std::vector< std::string > vars_to_strings(const std::vector< Var > &vars)
Return a list of variable names.
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::sort_expressions
std::vector< Expr > sort_expressions(const Expr &expr)
Topologically sort the expression graph expressed by expr.
Halide::Internal::equal
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
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.
Halide::Internal::find_buffer_param_calls
std::map< std::string, BufferInfo > find_buffer_param_calls(const Func &func)
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::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,...
Halide::Internal::gather_rvariables
std::map< std::string, ReductionVariableInfo > gather_rvariables(const Expr &expr)
Halide::Internal::extract_rdom
ReductionDomain extract_rdom(const Expr &expr)
Return the reduction domain used by expr.
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::remove_let_definitions
Expr remove_let_definitions(const Expr &expr)
Remove all let definitions of expr.
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.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Internal::Box
Represents the bounds of a region of arbitrary dimension.
Definition Bounds.h:53
Halide::Internal::BufferInfo
Find all calls to image buffers and parameters in the function.
Definition DerivativeUtils.h:84
Halide::Internal::BufferInfo::type
Type type
Definition DerivativeUtils.h:86
Halide::Internal::BufferInfo::dimension
int dimension
Definition DerivativeUtils.h:85
Halide::Internal::ReductionVariableInfo
Return a list of reduction variables the expression or tuple depends on.
Definition DerivativeUtils.h:32
Halide::Internal::ReductionVariableInfo::index
int index
Definition DerivativeUtils.h:34
Halide::Internal::ReductionVariableInfo::extent
Expr extent
Definition DerivativeUtils.h:33
Halide::Internal::ReductionVariableInfo::name
std::string name
Definition DerivativeUtils.h:36
Halide::Internal::ReductionVariableInfo::min
Expr min
Definition DerivativeUtils.h:33
Halide::Internal::ReductionVariableInfo::domain
ReductionDomain domain
Definition DerivativeUtils.h:35
Halide::Type
Types in the halide type system.
Definition Type.h:281