1#ifndef HALIDE_FUNCTION_H
2#define HALIDE_FUNCTION_H
20struct ExternFuncArgument;
48 return a.contents < b.contents;
77 const std::vector<std::string> &
args,
80 const std::vector<Definition> &
updates,
87 const Expr &extern_proxy_expr,
91 const std::vector<std::string> &trace_tags,
112 std::map<FunctionPtr, FunctionPtr> &copied_map)
const;
140 const std::string &
name()
const;
154 const std::vector<std::string> &
args()
const;
217 const std::vector<Definition> &
updates()
const;
246 const std::vector<ExternFuncArgument> &
args,
247 const std::vector<Type> &types,
248 const std::vector<Var> &dims,
266 return contents.
same_as(other.contents);
323 const std::map<std::string, FunctionPtr> &
wrappers()
const;
361std::pair<std::vector<Function>, std::map<std::string, Function>>
deep_copy(
362 const std::vector<Function> &outputs,
363 const std::map<std::string, Function> &env);
Defines the internal representation of a halide function's definition and related classes.
#define internal_assert(c)
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines internal classes related to Reduction Domains.
Defines the internal representation of the schedule for a function.
A Function definition which can either represent a init or an update definition.
A schedule for a Function of a Halide pipeline.
A reference-counted handle to Halide's internal representation of a function.
const std::vector< ExternFuncArgument > & extern_arguments() const
Retrive the arguments of the extern definition.
const std::string & extern_function_name() const
Get the name of the extern function called for an extern definition.
FunctionPtr get_contents() const
Get a handle on the halide function contents that this Function represents.
void define(const std::vector< std::string > &args, std::vector< Expr > values)
Add a pure definition to this function.
bool should_not_profile() const
Check if the function is marked as one that should not be profiled.
void deep_copy(const FunctionPtr ©, std::map< FunctionPtr, FunctionPtr > &copied_map) const
Deep copy this Function into 'copy'.
bool frozen() const
Check if a function has been frozen.
DeviceAPI extern_function_device_api() const
Get the DeviceAPI declared for an extern function.
Function(const std::string &n)
Construct a new function with the given name.
int dimensions() const
Get the dimensionality.
void check_types(const Type &t) const
bool is_tracing_realizations() const
bool has_extern_definition() const
Check if the function has an extern definition.
int outputs() const
Get the number of outputs.
int required_dimensions() const
Get the dimensionality constaints on the outputs (if any).
Function & substitute_calls(const std::map< FunctionPtr, FunctionPtr > &substitutions)
Replace every call to Functions in 'substitutions' keys by all Exprs referenced in this Function to c...
const std::map< std::string, FunctionPtr > & wrappers() const
const Definition & update(int idx=0) const
Get a const reference to this function's update definition at index 'idx'.
bool is_tracing_loads() const
void define_update(const std::vector< Expr > &args, std::vector< Expr > values, const ReductionDomain &rdom=ReductionDomain{})
Add an update definition to this function.
const std::vector< Type > & required_types() const
Get the type constaints on the outputs (if any).
void lock_loop_levels()
Replace this Function's LoopLevels with locked copies that cannot be mutated further.
bool can_be_inlined() const
Is it legal to inline this function?
StageSchedule & update_schedule(int idx=0)
Get a mutable handle to the stage-specfic schedule for the update stage.
bool is_tracing_stores() const
std::string & debug_file()
Get a handle to the debug filename.
const Call * is_wrapper() const
Check if a Function is a trivial wrapper around another Function, Buffer, or Parameter.
bool has_pure_definition() const
Does this function have a pure definition?
FuncSchedule & schedule()
Get a handle to the function-specific schedule for the purpose of modifying it.
const std::vector< Parameter > & output_buffers() const
Get a handle on the output buffer used for setting constraints on it.
const Definition & definition() const
Get the init definition.
void check_dims(int dims) const
If the Function has dimension requirements, check that the given argument is compatible with them.
Function()=default
Construct a new function with no definitions and no name.
bool is_pure() const
Does this function only have a pure definition?
bool has_update_definition() const
Does this function have an update definition?
void trace_loads()
Tracing calls and accessors, passed down from the Func equivalents.
std::vector< ExternFuncArgument > & extern_arguments()
const FuncSchedule & schedule() const
Get a const handle to the function-specific schedule for inspecting it.
void update_with_deserialization(const std::string &name, const std::string &origin_name, const std::vector< Halide::Type > &output_types, const std::vector< Halide::Type > &required_types, int required_dims, const std::vector< std::string > &args, const FuncSchedule &func_schedule, const Definition &init_def, const std::vector< Definition > &updates, const std::string &debug_file, const std::vector< Parameter > &output_buffers, const std::vector< ExternFuncArgument > &extern_arguments, const std::string &extern_function_name, NameMangling name_mangling, DeviceAPI device_api, const Expr &extern_proxy_expr, bool trace_loads, bool trace_stores, bool trace_realizations, const std::vector< std::string > &trace_tags, bool no_profiling, bool frozen)
Update a function with deserialized data.
Function new_function_in_same_group(const std::string &)
Make a new Function with the same lifetime as this one, and return a strong reference to it.
const std::vector< Definition > & updates() const
Get a const reference to this function's update definitions.
Definition & definition()
Get a mutable handle to the init definition.
void check_types(const std::vector< Expr > &exprs) const
void create_output_buffers(const std::vector< Type > &types, int dims) const
Define the output buffers.
const std::vector< std::string > & args() const
Get the pure arguments.
void mutate(IRMutator *mutator)
Accept a mutator to mutator all of the definitions and arguments of this function.
void define_extern(const std::string &function_name, const std::vector< ExternFuncArgument > &args, const std::vector< Type > &types, const std::vector< Var > &dims, NameMangling mangling, DeviceAPI device_api)
Add an external definition of this Func.
void trace_realizations()
void check_types(const Expr &e) const
If the Function has type requirements, check that the given argument is compatible with them.
void deep_copy(std::string name, const FunctionPtr ©, std::map< FunctionPtr, FunctionPtr > &copied_map) const
Definition & update(int idx=0)
Get a mutable handle to this function's update definition at index 'idx'.
NameMangling extern_definition_name_mangling() const
Get the name mangling specified for the extern definition.
Expr & extern_definition_proxy_expr()
void accept(IRVisitor *visitor) const
Accept a visitor to visit all of the definitions and arguments of this function.
bool same_as(const Function &other) const
Test for equality of identity.
const std::vector< Type > & output_types() const
Get the types of the outputs.
bool is_pure_arg(const std::string &name) const
Return true iff the name matches one of the Function's pure args.
const std::vector< std::string > & get_trace_tags() const
void check_types(const Tuple &t) const
void freeze()
Mark function as frozen, which means it cannot accept new definitions.
const std::vector< Expr > & values() const
Get the right-hand-side of the pure definition.
Function & substitute_calls(const Function &orig, const Function &substitute)
const std::string & debug_file() const
Get a const handle to the debug filename.
void do_not_profile()
Mark the function as too small for meaningful profiling.
void add_wrapper(const std::string &f, Function &wrapper)
Mark calls of this function by 'f' to be replaced with its wrapper during the lowering stage.
void check_types(const std::vector< Type > &types) const
Expr make_call_to_extern_definition(const std::vector< Expr > &args, const Target &t) const
Make a call node to the extern definition.
Function(const FunctionPtr &)
Construct a Function from an existing FunctionContents pointer.
const std::string & origin_name() const
If this is a wrapper of another func, created by a chain of in or clone_in calls, returns the name of...
const std::string & name() const
Get the name of the function.
void add_trace_tag(const std::string &trace_tag)
Expr extern_definition_proxy_expr() const
Get the proxy Expr for the extern stage.
Function(const std::vector< Type > &required_types, int required_dims, const std::string &n)
Construct a new function with the given name, with a requirement that it can only represent Expr(s) o...
A base class for passes over the IR which modify it (e.g.
A base class for algorithms that need to recursively walk over the IR.
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
A schedule for a single stage of a Halide pipeline.
Create a small array of Exprs for defining and calling functions with multiple outputs.
std::pair< std::vector< Function >, std::map< std::string, Function > > deep_copy(const std::vector< Function > &outputs, const std::map< std::string, Function > &env)
Deep copy an entire Function DAG.
Expr substitute(const std::string &name, const Expr &replacement, const Expr &expr)
Substitute variables with the given name with the replacement expression within expr.
std::atomic< int > random_variable_counter
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
NameMangling
An enum to specify calling convention for extern stages.
@ CPlusPlus
C++ name mangling.
@ Default
Match whatever is specified in the Target.
DeviceAPI
An enum describing a type of device API.
A fragment of Halide syntax.
An argument to an extern-defined Func.
This lets you use a Function as a key in a map of the form map<Function, Foo, Function::Compare>
bool operator()(const Function &a, const Function &b) const
A possibly-weak pointer to a Halide function.
bool defined() const
Check if the reference is defined.
bool same_as(const FunctionPtr &other) const
Check if two FunctionPtrs refer to the same Function.
A struct representing a target machine and os to generate code for.
Types in the halide type system.