Loading...
Searching...
No Matches
AutoScheduleUtils.h
Go to the documentation of this file.
#ifndef HALIDE_INTERNAL_AUTO_SCHEDULE_UTILS_H
#define HALIDE_INTERNAL_AUTO_SCHEDULE_UTILS_H
/** \file
*
* Defines util functions that used by auto scheduler.
*/
#include <limits>
#include <set>
#include "Bounds.h"
#include "Definition.h"
#include "IRVisitor.h"
#include "Interval.h"
namespace Halide {
namespace Internal {
typedef std::map<std::string, Interval> DimBounds;
const int64_t unknown = std::numeric_limits<int64_t>::min();
/** Visitor for keeping track of functions that are directly called and the
* arguments with which they are called. */
class FindAllCalls : public IRVisitor {
using IRVisitor::visit;
void visit(const Call *call) override {
if (call->call_type == Call::Halide || call->call_type == Call::Image) {
funcs_called.insert(call->name);
call_args.emplace_back(call->name, call->args);
}
for (const auto &arg : call->args) {
arg.accept(this);
}
}
public:
std::set<std::string> funcs_called;
std::vector<std::pair<std::string, std::vector<Expr>>> call_args;
};
/** Return an int representation of 's'. Throw an error on failure. */
int string_to_int(const std::string &s);
/** Substitute every variable in an Expr or a Stmt with its estimate
* if specified. */
//@{
Expr substitute_var_estimates(Expr e);
Stmt substitute_var_estimates(Stmt s);
//@}
/** Return the size of an interval. Return an undefined expr if the interval
* is unbounded. */
Expr get_extent(const Interval &i);
/** Return the size of an n-d box. */
Expr box_size(const Box &b);
/** Helper function to print the bounds of a region. */
void disp_regions(const std::map<std::string, Box> &regions);
/** Return the corresponding definition of a function given the stage. This
* will throw an assertion if the function is an extern function (Extern Func
* does not have definition). */
Definition get_stage_definition(const Function &f, int stage_num);
/** Return the corresponding loop dimensions of a function given the stage.
* For extern Func, this will return a list of size 1 containing the
* dummy __outermost loop dimension. */
std::vector<Dim> &get_stage_dims(const Function &f, int stage_num);
/** Add partial load costs to the corresponding function in the result costs. */
void combine_load_costs(std::map<std::string, Expr> &result,
const std::map<std::string, Expr> &partial);
/** Return the required bounds of an intermediate stage (f, stage_num) of
* function 'f' given the bounds of the pure dimensions. */
DimBounds get_stage_bounds(const Function &f, int stage_num, const DimBounds &pure_bounds);
/** Return the required bounds for all the stages of the function 'f'. Each entry
* in the returned vector corresponds to a stage. */
std::vector<DimBounds> get_stage_bounds(const Function &f, const DimBounds &pure_bounds);
/** Recursively inline all the functions in the set 'inlines' into the
* expression 'e' and return the resulting expression. If 'order' is
* passed, inlining will be done in the reverse order of function realization
* to avoid extra inlining works. */
Expr perform_inline(Expr e, const std::map<std::string, Function> &env,
const std::set<std::string> &inlines = std::set<std::string>(),
const std::vector<std::string> &order = std::vector<std::string>());
/** Return all functions that are directly called by a function stage (f, stage). */
std::set<std::string> get_parents(Function f, int stage);
/** Return value of element within a map. This will assert if the element is not
* in the map. */
// @{
template<typename K, typename V>
V get_element(const std::map<K, V> &m, const K &key) {
const auto &iter = m.find(key);
internal_assert(iter != m.end());
return iter->second;
}
template<typename K, typename V>
V &get_element(std::map<K, V> &m, const K &key) {
const auto &iter = m.find(key);
internal_assert(iter != m.end());
return iter->second;
}
// @}
/** If the cost of computing a Func is about the same as calling the Func,
* inline the Func. Return true of any of the Funcs is inlined. */
bool inline_all_trivial_functions(const std::vector<Function> &outputs,
const std::vector<std::string> &order,
const std::map<std::string, Function> &env);
/** Determine if a Func (order[index]) is only consumed by another single Func
* in element-wise manner. If it is, return the name of the consumer Func;
* otherwise, return an empty string. */
std::string is_func_called_element_wise(const std::vector<std::string> &order, size_t index,
const std::map<std::string, Function> &env);
/** Inline a Func if its values are only consumed by another single Func in
* element-wise manner. */
bool inline_all_element_wise_functions(const std::vector<Function> &outputs,
const std::vector<std::string> &order,
const std::map<std::string, Function> &env);
void propagate_estimate_test();
} // 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...
Definition.h
Defines the internal representation of a halide function's definition and related classes.
internal_assert
#define internal_assert(c)
Definition Error.h:218
IRVisitor.h
Defines the base class for things that recursively walk over the IR.
Interval.h
Defines the Interval class.
Halide::Internal::Definition
A Function definition which can either represent a init or an update definition.
Definition Definition.h:38
Halide::Internal::FindAllCalls
Visitor for keeping track of functions that are directly called and the arguments with which they are...
Definition AutoScheduleUtils.h:26
Halide::Internal::FindAllCalls::call_args
std::vector< std::pair< std::string, std::vector< Expr > > > call_args
Definition AutoScheduleUtils.h:41
Halide::Internal::FindAllCalls::funcs_called
std::set< std::string > funcs_called
Definition AutoScheduleUtils.h:40
Halide::Internal::Function
A reference-counted handle to Halide's internal representation of a function.
Definition Function.h:39
Halide::Internal::IRVisitor::visit
virtual void visit(const IntImm *)
Halide::Internal::IRVisitor::IRVisitor
IRVisitor()=default
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::box_size
Expr box_size(const Box &b)
Return the size of an n-d box.
Halide::Internal::get_parents
std::set< std::string > get_parents(Function f, int stage)
Return all functions that are directly called by a function stage (f, stage).
Halide::Internal::is_func_called_element_wise
std::string is_func_called_element_wise(const std::vector< std::string > &order, size_t index, const std::map< std::string, Function > &env)
Determine if a Func (order[index]) is only consumed by another single Func in element-wise manner.
Halide::Internal::perform_inline
Expr perform_inline(Expr e, const std::map< std::string, Function > &env, const std::set< std::string > &inlines=std::set< std::string >(), const std::vector< std::string > &order=std::vector< std::string >())
Recursively inline all the functions in the set 'inlines' into the expression 'e' and return the resu...
Halide::Internal::get_stage_bounds
DimBounds get_stage_bounds(const Function &f, int stage_num, const DimBounds &pure_bounds)
Return the required bounds of an intermediate stage (f, stage_num) of function 'f' given the bounds o...
Halide::Internal::get_stage_definition
Definition get_stage_definition(const Function &f, int stage_num)
Return the corresponding definition of a function given the stage.
Halide::Internal::substitute_var_estimates
Expr substitute_var_estimates(Expr e)
Substitute every variable in an Expr or a Stmt with its estimate if specified.
Halide::Internal::get_stage_dims
std::vector< Dim > & get_stage_dims(const Function &f, int stage_num)
Return the corresponding loop dimensions of a function given the stage.
Halide::Internal::disp_regions
void disp_regions(const std::map< std::string, Box > &regions)
Helper function to print the bounds of a region.
Halide::Internal::propagate_estimate_test
void propagate_estimate_test()
Halide::Internal::combine_load_costs
void combine_load_costs(std::map< std::string, Expr > &result, const std::map< std::string, Expr > &partial)
Add partial load costs to the corresponding function in the result costs.
Halide::Internal::get_element
V get_element(const std::map< K, V > &m, const K &key)
Return value of element within a map.
Definition AutoScheduleUtils.h:101
Halide::Internal::get_extent
Expr get_extent(const Interval &i)
Return the size of an interval.
Halide::Internal::inline_all_trivial_functions
bool inline_all_trivial_functions(const std::vector< Function > &outputs, const std::vector< std::string > &order, const std::map< std::string, Function > &env)
If the cost of computing a Func is about the same as calling the Func, inline the Func.
Halide::Internal::DimBounds
std::map< std::string, Interval > DimBounds
Definition AutoScheduleUtils.h:20
Halide::Internal::unknown
const int64_t unknown
Definition AutoScheduleUtils.h:22
Halide::Internal::string_to_int
int string_to_int(const std::string &s)
Return an int representation of 's'.
Halide::Internal::inline_all_element_wise_functions
bool inline_all_element_wise_functions(const std::vector< Function > &outputs, const std::vector< std::string > &order, const std::map< std::string, Function > &env)
Inline a Func if its values are only consumed by another single Func in element-wise manner.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
int64_t
signed __INT64_TYPE__ int64_t
Definition runtime_internal.h:22
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::Call
A function call.
Definition IR.h:490
Halide::Internal::Call::Image
@ Image
A load from an input image.
Definition IR.h:493
Halide::Internal::Call::Halide
@ Halide
A call to a Func.
Definition IR.h:497
Halide::Internal::Call::name
std::string name
Definition IR.h:491
Halide::Internal::Call::call_type
CallType call_type
Definition IR.h:501
Halide::Internal::Call::args
std::vector< Expr > args
Definition IR.h:492
Halide::Internal::Interval
A class to represent ranges of Exprs.
Definition Interval.h:14
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition Expr.h:427