Halide
Halide::Internal::Function Class Reference

A reference-counted handle to Halide's internal representation of a function. More...

#include <Function.h>

Classes

struct  Compare
 This lets you use a Function as a key in a map of the form map<Function, Foo, Function::Compare> More...
 

Public Member Functions

EXPORT Function ()
 Construct a new function with no definitions and no name. More...
 
EXPORT Function (const std::string &n)
 Construct a new function with the given name. More...
 
EXPORT Function (const FunctionPtr &)
 Construct a Function from an existing FunctionContents pointer. More...
 
FunctionPtr get_contents () const
 Get a handle on the halide function contents that this Function represents. More...
 
EXPORT void define (const std::vector< std::string > &args, std::vector< Expr > values)
 Add a pure definition to this function. More...
 
EXPORT void define_update (const std::vector< Expr > &args, std::vector< Expr > values)
 Add an update definition to this function. More...
 
EXPORT void accept (IRVisitor *visitor) const
 Accept a visitor to visit all of the definitions and arguments of this function. More...
 
EXPORT void mutate (IRMutator2 *mutator)
 Accept a mutator to mutator all of the definitions and arguments of this function. More...
 
EXPORT const std::string & name () const
 Get the name of the function. More...
 
EXPORT Definitiondefinition ()
 Get a mutable handle to the init definition. More...
 
EXPORT const Definitiondefinition () const
 Get the init definition. More...
 
EXPORT const std::vector< std::string > args () const
 Get the pure arguments. More...
 
EXPORT int dimensions () const
 Get the dimensionality. More...
 
int outputs () const
 Get the number of outputs. More...
 
EXPORT const std::vector< Type > & output_types () const
 Get the types of the outputs. More...
 
EXPORT const std::vector< Expr > & values () const
 Get the right-hand-side of the pure definition. More...
 
EXPORT bool has_pure_definition () const
 Does this function have a pure definition? More...
 
bool is_pure () const
 Does this function only have a pure definition? More...
 
EXPORT bool can_be_inlined () const
 Is it legal to inline this function? More...
 
EXPORT FuncScheduleschedule ()
 Get a handle to the function-specific schedule for the purpose of modifying it. More...
 
EXPORT const FuncScheduleschedule () const
 Get a const handle to the function-specific schedule for inspecting it. More...
 
EXPORT const std::vector< Parameter > & output_buffers () const
 Get a handle on the output buffer used for setting constraints on it. More...
 
EXPORT StageScheduleupdate_schedule (int idx=0)
 Get a mutable handle to the stage-specfic schedule for the update stage. More...
 
EXPORT Definitionupdate (int idx=0)
 Get a mutable handle to this function's update definition at index 'idx'. More...
 
EXPORT const Definitionupdate (int idx=0) const
 Get a const reference to this function's update definition at index 'idx'. More...
 
EXPORT const std::vector< Definition > & updates () const
 Get a const reference to this function's update definitions. More...
 
EXPORT bool has_update_definition () const
 Does this function have an update definition? More...
 
EXPORT bool has_extern_definition () const
 Check if the function has an extern definition. More...
 
EXPORT NameMangling extern_definition_name_mangling () const
 Get the name mangling specified for the extern definition. More...
 
EXPORT Expr make_call_to_extern_definition (const std::vector< Expr > &args, const Target &t) const
 Make a call node to the extern definition. More...
 
EXPORT bool extern_definition_uses_old_buffer_t () const
 Check if the extern function being called expects the legacy buffer_t type. More...
 
EXPORT void define_extern (const std::string &function_name, const std::vector< ExternFuncArgument > &args, const std::vector< Type > &types, int dimensionality, NameMangling mangling, DeviceAPI device_api, bool uses_old_buffer_t)
 Add an external definition of this Func. More...
 
EXPORT const std::string & extern_function_name () const
 Get the name of the extern function called for an extern definition. More...
 
EXPORT DeviceAPI extern_function_device_api () const
 Get the DeviceAPI declared for an extern function. More...
 
bool same_as (const Function &other) const
 Test for equality of identity. More...
 
EXPORT const std::string & debug_file () const
 Get a const handle to the debug filename. More...
 
EXPORT std::string & debug_file ()
 Get a handle to the debug filename. More...
 
 operator ExternFuncArgument () const
 Use an an extern argument to another function. More...
 
EXPORT void freeze ()
 Mark function as frozen, which means it cannot accept new definitions. More...
 
EXPORT bool frozen () const
 Check if a function has been frozen. More...
 
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. More...
 
EXPORT const Callis_wrapper () const
 Check if a Function is a trivial wrapper around another Function, Buffer, or Parameter. More...
 
EXPORT Functionsubstitute_schedule_param_exprs ()
 Find all Vars that are placeholders for ScheduleParams and substitute in the corresponding constant value. More...
 
EXPORT bool is_pure_arg (const std::string &name) const
 Return true iff the name matches one of the Function's pure args. More...
 
EXPORT void deep_copy (FunctionPtr copy, std::map< FunctionPtr, FunctionPtr > &copied_map) const
 Deep copy this Function into 'copy'. More...
 
EXPORT void deep_copy (std::string name, FunctionPtr copy, std::map< FunctionPtr, FunctionPtr > &copied_map) const
 Deep copy this Function into 'copy'. More...
 
EXPORT Expr extern_definition_proxy_expr () const
 Get the proxy Expr for the extern stage. More...
 
EXPORT Exprextern_definition_proxy_expr ()
 Get the proxy Expr for the extern stage. More...
 
EXPORT const std::vector< ExternFuncArgument > & extern_arguments () const
 Retrive the arguments of the extern definition. More...
 
EXPORT std::vector< ExternFuncArgument > & extern_arguments ()
 Retrive the arguments of the extern definition. More...
 
EXPORT void trace_loads ()
 Tracing calls and accessors, passed down from the Func equivalents. More...
 
EXPORT void trace_stores ()
 Tracing calls and accessors, passed down from the Func equivalents. More...
 
EXPORT void trace_realizations ()
 Tracing calls and accessors, passed down from the Func equivalents. More...
 
EXPORT bool is_tracing_loads () const
 Tracing calls and accessors, passed down from the Func equivalents. More...
 
EXPORT bool is_tracing_stores () const
 Tracing calls and accessors, passed down from the Func equivalents. More...
 
EXPORT bool is_tracing_realizations () const
 Tracing calls and accessors, passed down from the Func equivalents. More...
 
EXPORT 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. More...
 
EXPORT const std::map< std::string, FunctionPtr > & wrappers () const
 Mark calls of this function by 'f' to be replaced with its wrapper during the lowering stage. More...
 
EXPORT Functionsubstitute_calls (const std::map< FunctionPtr, FunctionPtr > &substitutions)
 Replace every call to Functions in 'substitutions' keys by all Exprs referenced in this Function to call to their substitute Functions (i.e. More...
 
EXPORT Functionsubstitute_calls (const Function &orig, const Function &substitute)
 Replace every call to Functions in 'substitutions' keys by all Exprs referenced in this Function to call to their substitute Functions (i.e. More...
 

Detailed Description

A reference-counted handle to Halide's internal representation of a function.

Similar to a front-end Func object, but with no syntactic sugar to help with definitions.

Definition at line 67 of file Function.h.

Constructor & Destructor Documentation

◆ Function() [1/3]

EXPORT Halide::Internal::Function::Function ( )

Construct a new function with no definitions and no name.

This constructor only exists so that you can make vectors of functions, etc.

◆ Function() [2/3]

EXPORT Halide::Internal::Function::Function ( const std::string &  n)
explicit

Construct a new function with the given name.

◆ Function() [3/3]

EXPORT Halide::Internal::Function::Function ( const FunctionPtr )
explicit

Construct a Function from an existing FunctionContents pointer.

Must be non-null

Member Function Documentation

◆ get_contents()

FunctionPtr Halide::Internal::Function::get_contents ( ) const
inline

Get a handle on the halide function contents that this Function represents.

Definition at line 95 of file Function.h.

References Halide::Internal::deep_copy(), and EXPORT.

◆ deep_copy() [1/2]

EXPORT void Halide::Internal::Function::deep_copy ( FunctionPtr  copy,
std::map< FunctionPtr, FunctionPtr > &  copied_map 
) const

Deep copy this Function into 'copy'.

It recursively deep copies all called functions, schedules, update definitions, extern func arguments, specializations, and reduction domains. This method does not deep-copy the Parameter objects. This method also takes a map of <old Function, deep-copied version> as input and would use the deep-copied Function from the map if exists instead of creating a new deep-copy to avoid creating deep-copies of the same Function multiple times. If 'name' is specified, copy's name will be set to that.

◆ deep_copy() [2/2]

EXPORT void Halide::Internal::Function::deep_copy ( std::string  name,
FunctionPtr  copy,
std::map< FunctionPtr, FunctionPtr > &  copied_map 
) const

Deep copy this Function into 'copy'.

It recursively deep copies all called functions, schedules, update definitions, extern func arguments, specializations, and reduction domains. This method does not deep-copy the Parameter objects. This method also takes a map of <old Function, deep-copied version> as input and would use the deep-copied Function from the map if exists instead of creating a new deep-copy to avoid creating deep-copies of the same Function multiple times. If 'name' is specified, copy's name will be set to that.

◆ define()

EXPORT void Halide::Internal::Function::define ( const std::vector< std::string > &  args,
std::vector< Expr values 
)

Add a pure definition to this function.

It may not already have a definition. All the free variables in 'value' must appear in the args list. 'value' must not depend on any reduction domain

◆ define_update()

EXPORT void Halide::Internal::Function::define_update ( const std::vector< Expr > &  args,
std::vector< Expr values 
)

Add an update definition to this function.

It must already have a pure definition but not an update definition, and the length of args must match the length of args used in the pure definition. 'value' must depend on some reduction domain, and may contain variables from that domain as well as pure variables. Any pure variables must also appear as Variables in the args array, and they must have the same name as the pure definition's argument in the same index.

◆ accept()

EXPORT void Halide::Internal::Function::accept ( IRVisitor visitor) const

Accept a visitor to visit all of the definitions and arguments of this function.

◆ mutate()

EXPORT void Halide::Internal::Function::mutate ( IRMutator2 mutator)

Accept a mutator to mutator all of the definitions and arguments of this function.

◆ name()

EXPORT const std::string& Halide::Internal::Function::name ( ) const

Get the name of the function.

◆ definition() [1/2]

EXPORT Definition& Halide::Internal::Function::definition ( )

Get a mutable handle to the init definition.

◆ definition() [2/2]

EXPORT const Definition& Halide::Internal::Function::definition ( ) const

Get the init definition.

◆ args()

EXPORT const std::vector<std::string> Halide::Internal::Function::args ( ) const

Get the pure arguments.

◆ dimensions()

EXPORT int Halide::Internal::Function::dimensions ( ) const

Get the dimensionality.

◆ outputs()

int Halide::Internal::Function::outputs ( ) const
inline

Get the number of outputs.

Definition at line 153 of file Function.h.

References EXPORT.

◆ output_types()

EXPORT const std::vector<Type>& Halide::Internal::Function::output_types ( ) const

Get the types of the outputs.

◆ values()

EXPORT const std::vector<Expr>& Halide::Internal::Function::values ( ) const

Get the right-hand-side of the pure definition.

◆ has_pure_definition()

EXPORT bool Halide::Internal::Function::has_pure_definition ( ) const

Does this function have a pure definition?

◆ is_pure()

bool Halide::Internal::Function::is_pure ( ) const
inline

Does this function only have a pure definition?

Definition at line 167 of file Function.h.

References EXPORT.

◆ can_be_inlined()

EXPORT bool Halide::Internal::Function::can_be_inlined ( ) const

Is it legal to inline this function?

◆ schedule() [1/2]

EXPORT FuncSchedule& Halide::Internal::Function::schedule ( )

Get a handle to the function-specific schedule for the purpose of modifying it.

◆ schedule() [2/2]

EXPORT const FuncSchedule& Halide::Internal::Function::schedule ( ) const

Get a const handle to the function-specific schedule for inspecting it.

◆ output_buffers()

EXPORT const std::vector<Parameter>& Halide::Internal::Function::output_buffers ( ) const

Get a handle on the output buffer used for setting constraints on it.

◆ update_schedule()

EXPORT StageSchedule& Halide::Internal::Function::update_schedule ( int  idx = 0)

Get a mutable handle to the stage-specfic schedule for the update stage.

◆ update() [1/2]

EXPORT Definition& Halide::Internal::Function::update ( int  idx = 0)

Get a mutable handle to this function's update definition at index 'idx'.

◆ update() [2/2]

EXPORT const Definition& Halide::Internal::Function::update ( int  idx = 0) const

Get a const reference to this function's update definition at index 'idx'.

◆ updates()

EXPORT const std::vector<Definition>& Halide::Internal::Function::updates ( ) const

Get a const reference to this function's update definitions.

◆ has_update_definition()

EXPORT bool Halide::Internal::Function::has_update_definition ( ) const

Does this function have an update definition?

◆ has_extern_definition()

EXPORT bool Halide::Internal::Function::has_extern_definition ( ) const

Check if the function has an extern definition.

◆ extern_definition_name_mangling()

EXPORT NameMangling Halide::Internal::Function::extern_definition_name_mangling ( ) const

Get the name mangling specified for the extern definition.

◆ make_call_to_extern_definition()

EXPORT Expr Halide::Internal::Function::make_call_to_extern_definition ( const std::vector< Expr > &  args,
const Target t 
) const

Make a call node to the extern definition.

An error if the function has no extern definition.

◆ extern_definition_uses_old_buffer_t()

EXPORT bool Halide::Internal::Function::extern_definition_uses_old_buffer_t ( ) const

Check if the extern function being called expects the legacy buffer_t type.

◆ extern_definition_proxy_expr() [1/2]

EXPORT Expr Halide::Internal::Function::extern_definition_proxy_expr ( ) const

Get the proxy Expr for the extern stage.

This is an expression known to have the same data access pattern as the extern stage. It must touch at least all of the memory that the extern stage does, though it is permissible for it to be conservative and touch a superset. For most Functions, including those with extern definitions, this will be an undefined Expr.

◆ extern_definition_proxy_expr() [2/2]

EXPORT Expr& Halide::Internal::Function::extern_definition_proxy_expr ( )

Get the proxy Expr for the extern stage.

This is an expression known to have the same data access pattern as the extern stage. It must touch at least all of the memory that the extern stage does, though it is permissible for it to be conservative and touch a superset. For most Functions, including those with extern definitions, this will be an undefined Expr.

◆ define_extern()

EXPORT void Halide::Internal::Function::define_extern ( const std::string &  function_name,
const std::vector< ExternFuncArgument > &  args,
const std::vector< Type > &  types,
int  dimensionality,
NameMangling  mangling,
DeviceAPI  device_api,
bool  uses_old_buffer_t 
)

Add an external definition of this Func.

◆ extern_arguments() [1/2]

EXPORT const std::vector<ExternFuncArgument>& Halide::Internal::Function::extern_arguments ( ) const

Retrive the arguments of the extern definition.

◆ extern_arguments() [2/2]

EXPORT std::vector<ExternFuncArgument>& Halide::Internal::Function::extern_arguments ( )

Retrive the arguments of the extern definition.

◆ extern_function_name()

EXPORT const std::string& Halide::Internal::Function::extern_function_name ( ) const

Get the name of the extern function called for an extern definition.

◆ extern_function_device_api()

EXPORT DeviceAPI Halide::Internal::Function::extern_function_device_api ( ) const

Get the DeviceAPI declared for an extern function.

◆ same_as()

bool Halide::Internal::Function::same_as ( const Function other) const
inline

Test for equality of identity.

Definition at line 254 of file Function.h.

References EXPORT, and Halide::Internal::FunctionPtr::same_as().

◆ debug_file() [1/2]

EXPORT const std::string& Halide::Internal::Function::debug_file ( ) const

Get a const handle to the debug filename.

◆ debug_file() [2/2]

EXPORT std::string& Halide::Internal::Function::debug_file ( )

Get a handle to the debug filename.

◆ operator ExternFuncArgument()

Halide::Internal::Function::operator ExternFuncArgument ( ) const
inline

Use an an extern argument to another function.

Definition at line 265 of file Function.h.

References Halide::Internal::deep_copy(), EXPORT, Halide::ExternFuncArgument::ExternFuncArgument(), and Halide::Internal::substitute().

◆ trace_loads()

EXPORT void Halide::Internal::Function::trace_loads ( )

Tracing calls and accessors, passed down from the Func equivalents.

◆ trace_stores()

EXPORT void Halide::Internal::Function::trace_stores ( )

Tracing calls and accessors, passed down from the Func equivalents.

◆ trace_realizations()

EXPORT void Halide::Internal::Function::trace_realizations ( )

Tracing calls and accessors, passed down from the Func equivalents.

◆ is_tracing_loads()

EXPORT bool Halide::Internal::Function::is_tracing_loads ( ) const

Tracing calls and accessors, passed down from the Func equivalents.

◆ is_tracing_stores()

EXPORT bool Halide::Internal::Function::is_tracing_stores ( ) const

Tracing calls and accessors, passed down from the Func equivalents.

◆ is_tracing_realizations()

EXPORT bool Halide::Internal::Function::is_tracing_realizations ( ) const

Tracing calls and accessors, passed down from the Func equivalents.

◆ freeze()

EXPORT void Halide::Internal::Function::freeze ( )

Mark function as frozen, which means it cannot accept new definitions.

◆ frozen()

EXPORT bool Halide::Internal::Function::frozen ( ) const

Check if a function has been frozen.

If so, it is an error to add new definitions.

◆ new_function_in_same_group()

Function Halide::Internal::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.

Useful to create Functions which have circular references to this one - e.g. the wrappers produced by Func::in.

◆ add_wrapper()

EXPORT void Halide::Internal::Function::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.

If the string 'f' is empty, it means replace all calls to this function by all other functions (excluding itself) in the pipeline with the wrapper. This will also freeze 'wrapper' to prevent user from updating the values of the Function it wraps via the wrapper. See Func::in for more details.

◆ wrappers()

EXPORT const std::map<std::string, FunctionPtr>& Halide::Internal::Function::wrappers ( ) const

Mark calls of this function by 'f' to be replaced with its wrapper during the lowering stage.

If the string 'f' is empty, it means replace all calls to this function by all other functions (excluding itself) in the pipeline with the wrapper. This will also freeze 'wrapper' to prevent user from updating the values of the Function it wraps via the wrapper. See Func::in for more details.

◆ is_wrapper()

EXPORT const Call* Halide::Internal::Function::is_wrapper ( ) const

Check if a Function is a trivial wrapper around another Function, Buffer, or Parameter.

Returns the Call node if it is. Otherwise returns null.

◆ substitute_calls() [1/2]

EXPORT Function& Halide::Internal::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 call to their substitute Functions (i.e.

the corresponding values in 'substitutions' map).

◆ substitute_calls() [2/2]

EXPORT Function& Halide::Internal::Function::substitute_calls ( const Function orig,
const Function substitute 
)

Replace every call to Functions in 'substitutions' keys by all Exprs referenced in this Function to call to their substitute Functions (i.e.

the corresponding values in 'substitutions' map).

◆ substitute_schedule_param_exprs()

EXPORT Function& Halide::Internal::Function::substitute_schedule_param_exprs ( )

Find all Vars that are placeholders for ScheduleParams and substitute in the corresponding constant value.

◆ is_pure_arg()

EXPORT bool Halide::Internal::Function::is_pure_arg ( const std::string &  name) const

Return true iff the name matches one of the Function's pure args.


The documentation for this class was generated from the following file: