Loading...
Searching...
No Matches
DerivativeUtils.h
Go to the documentation of this file.
#ifndef HALIDE_INTERNAL_DERIVATIVE_UTILS_H
#define HALIDE_INTERNAL_DERIVATIVE_UTILS_H
#include <set>
#include "Bounds.h"
#include "Derivative.h"
#include "Expr.h"
#include "RDom.h"
#include "Scope.h"
#include "Var.h"
namespace Halide {
namespace Internal {
/**
* Remove all let definitions of expr
*/
Expr remove_let_definitions(const Expr &expr);
/**
* Return a list of variables' indices that expr depends on and are in the filter
*/
std::vector<int> gather_variables(const Expr &expr,
const std::vector<std::string> &filter);
std::vector<int> gather_variables(const Expr &expr,
const std::vector<Var> &filter);
/**
* Return a list of reduction variables the expression or tuple depends on
*/
struct ReductionVariableInfo {
Expr min, extent;
int index;
ReductionDomain domain;
std::string name;
};
std::map<std::string, ReductionVariableInfo> gather_rvariables(const Expr &expr);
std::map<std::string, ReductionVariableInfo> gather_rvariables(const Tuple &tuple);
/**
* Add necessary let expressions to expr
*/
Expr add_let_expression(const Expr &expr,
const std::map<std::string, Expr> &let_var_mapping,
const std::vector<std::string> &let_variables);
/**
* Topologically sort the expression graph expressed by expr
*/
std::vector<Expr> sort_expressions(const Expr &expr);
/**
* Compute the bounds of funcs. The bounds represent a conservative region
* that is used by the "consumers" of the function, except of itself.
*/
std::map<std::string, Box> inference_bounds(const std::vector<Func> &funcs,
const std::vector<Box> &output_bounds);
std::map<std::string, Box> inference_bounds(const Func &func,
const Box &output_bounds);
/**
* Convert Box to vector of (min, extent)
*/
std::vector<std::pair<Expr, Expr>> box_to_vector(const Box &bounds);
/**
* Return true if bounds0 and bounds1 represent the same bounds.
*/
bool equal(const RDom &bounds0, const RDom &bounds1);
/**
* Return a list of variable names
*/
std::vector<std::string> vars_to_strings(const std::vector<Var> &vars);
/**
* Return the reduction domain used by expr
*/
ReductionDomain extract_rdom(const Expr &expr);
/**
* expr is new_var == f(var), solve for var == g(new_var)
* if multiple new_var corresponds to same var, introduce a RDom
*/
std::pair<bool, Expr> solve_inverse(Expr expr,
const std::string &new_var,
const std::string &var);
/**
* Find all calls to image buffers and parameters in the function
*/
struct BufferInfo {
int dimension;
Type type;
};
std::map<std::string, BufferInfo> find_buffer_param_calls(const Func &func);
/**
* Find all implicit variables in expr
*/
std::set<std::string> find_implicit_variables(const Expr &expr);
/**
* Substitute the variable. Also replace all occurrences in rdom.where() predicates.
*/
Expr substitute_rdom_predicate(
const std::string &name, const Expr &replacement, const Expr &expr);
/**
* Return true if expr contains call to func_name
*/
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 depends on any function or buffer
*/
bool is_calling_function(
const Expr &expr,
const std::map<std::string, Expr> &let_var_mapping);
/**
* Replaces call to Func f in Expr e such that the call argument at variable_id
* is the pure argument.
*/
Expr substitute_call_arg_with_pure_arg(Func f,
int variable_id,
const Expr &e);
} // namespace Internal
} // namespace Halide
#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:706
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
Definition AbstractGenerator.h:24
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::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:283