Loading...
Searching...
No Matches
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

| Function ()=default
| Construct a new function with no definitions and no name.
| Function (const std::string &n)
| Construct a new function with the given name.
| 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) of the given type(s), and must have exactly the give nnumber of dimensions.
| Function (const FunctionPtr &)
| Construct a Function from an existing FunctionContents pointer.

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.
FunctionPtr | get_contents () const
| Get a handle on the halide function contents that this Function represents.
void | deep_copy (const FunctionPtr &copy, std::map< FunctionPtr, FunctionPtr > &copied_map) const
| Deep copy this Function into 'copy'.
void | deep_copy (std::string name, const FunctionPtr &copy, std::map< FunctionPtr, FunctionPtr > &copied_map) const
void | define (const std::vector< std::string > &args, std::vector< Expr > values)
| Add a pure definition to this function.
void | define_update (const std::vector< Expr > &args, std::vector< Expr > values, const ReductionDomain &rdom=ReductionDomain{})
| Add an update definition to this function.
void | accept (IRVisitor *visitor) const
| Accept a visitor to visit all of the definitions and arguments of this function.
void | mutate (IRMutator *mutator)
| Accept a mutator to mutator all of the definitions and arguments of this function.
const std::string & | name () const
| Get the name of the function.
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 the original Func.
Definition & | definition ()
| Get a mutable handle to the init definition.
const Definition & | definition () const
| Get the init definition.
const std::vector< std::string > & | args () const
| Get the pure arguments.
int | dimensions () const
| Get the dimensionality.
int | outputs () const
| Get the number of outputs.
const std::vector< Type > & | output_types () const
| Get the types of the outputs.
const std::vector< Type > & | required_types () const
| Get the type constaints on the outputs (if any).
int | required_dimensions () const
| Get the dimensionality constaints on the outputs (if any).
const std::vector< Expr > & | values () const
| Get the right-hand-side of the pure definition.
bool | has_pure_definition () const
| Does this function have a pure definition?
bool | is_pure () const
| Does this function only have a pure definition?
bool | can_be_inlined () const
| Is it legal to inline this function?
FuncSchedule & | schedule ()
| Get a handle to the function-specific schedule for the purpose of modifying it.
const FuncSchedule & | schedule () const
| Get a const handle to the function-specific schedule for inspecting it.
const std::vector< Parameter > & | output_buffers () const
| Get a handle on the output buffer used for setting constraints on it.
StageSchedule & | update_schedule (int idx=0)
| Get a mutable handle to the stage-specfic schedule for the update stage.
Definition & | update (int idx=0)
| Get a mutable handle to this function's update definition at index 'idx'.
const Definition & | update (int idx=0) const
| Get a const reference to this function's update definition at index 'idx'.
const std::vector< Definition > & | updates () const
| Get a const reference to this function's update definitions.
bool | has_update_definition () const
| Does this function have an update definition?
bool | has_extern_definition () const
| Check if the function has an extern definition.
NameMangling | extern_definition_name_mangling () const
| Get the name mangling specified for the extern definition.
Expr | make_call_to_extern_definition (const std::vector< Expr > &args, const Target &t) const
| Make a call node to the extern definition.
Expr | extern_definition_proxy_expr () const
| Get the proxy Expr for the extern stage.
Expr & | extern_definition_proxy_expr ()
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.
const std::vector< ExternFuncArgument > & | extern_arguments () const
| Retrive the arguments of the extern definition.
std::vector< ExternFuncArgument > & | extern_arguments ()
const std::string & | extern_function_name () const
| Get the name of the extern function called for an extern definition.
DeviceAPI | extern_function_device_api () const
| Get the DeviceAPI declared for an extern function.
bool | same_as (const Function &other) const
| Test for equality of identity.
const std::string & | debug_file () const
| Get a const handle to the debug filename.
std::string & | debug_file ()
| Get a handle to the debug filename.
| operator ExternFuncArgument () const
| Use an an extern argument to another function.
void | trace_loads ()
| Tracing calls and accessors, passed down from the Func equivalents.
void | trace_stores ()
void | trace_realizations ()
void | add_trace_tag (const std::string &trace_tag)
bool | is_tracing_loads () const
bool | is_tracing_stores () const
bool | is_tracing_realizations () const
const std::vector< std::string > & | get_trace_tags () const
void | lock_loop_levels ()
| Replace this Function's LoopLevels with locked copies that cannot be mutated further.
void | do_not_profile ()
| Mark the function as too small for meaningful profiling.
bool | should_not_profile () const
| Check if the function is marked as one that should not be profiled.
void | freeze ()
| Mark function as frozen, which means it cannot accept new definitions.
bool | frozen () const
| Check if a function has been frozen.
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.
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.
const std::map< std::string, FunctionPtr > & | wrappers () const
const Call * | is_wrapper () const
| Check if a Function is a trivial wrapper around another Function, Buffer, or Parameter.
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.
Function & | substitute_calls (const Function &orig, const Function &substitute)
bool | is_pure_arg (const std::string &name) const
| Return true iff the name matches one of the Function's pure args.
void | check_types (const Expr &e) const
| If the Function has type requirements, check that the given argument is compatible with them.
void | check_types (const Tuple &t) const
void | check_types (const Type &t) const
void | check_types (const std::vector< Expr > &exprs) const
void | check_types (const std::vector< Type > &types) const
void | check_dims (int dims) const
| If the Function has dimension requirements, check that the given argument is compatible with them.
void | create_output_buffers (const std::vector< Type > &types, int dims) const
| Define the output buffers.

## 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 39 of file Function.h.

## Constructor & Destructor Documentation

## Function() [1/4]

Halide::Internal::Function::Function | ( |  | ) |

default

Construct a new function with no definitions and no name.

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

Referenced by add_wrapper(), new_function_in_same_group(), Halide::Internal::Function::Compare::operator()(), same_as(), substitute_calls(), and substitute_calls().

## Function() [2/4]

Halide::Internal::Function::Function | ( | const std::string & | n | ) |

explicit

Construct a new function with the given name.

## Function() [3/4]

Halide::Internal::Function::Function | ( | const std::vector< Type > & | required_types,
|  | int | required_dims,
|  | const std::string & | n )

explicit

Construct a new function with the given name, with a requirement that it can only represent Expr(s) of the given type(s), and must have exactly the give nnumber of dimensions.

required_types.empty() means there are no constraints on the type(s). required_dims == AnyDims means there are no constraints on the dimensions.

References required_types().

## Function() [4/4]

Halide::Internal::Function::Function | ( | const FunctionPtr & |  | ) |

explicit

Construct a Function from an existing FunctionContents pointer.

Must be non-null

## Member Function Documentation

## update_with_deserialization()

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

References args(), debug_file(), extern_arguments(), extern_function_name(), frozen(), name(), origin_name(), output_buffers(), output_types(), required_types(), trace_loads(), trace_realizations(), trace_stores(), and updates().

## 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 97 of file Function.h.

## deep_copy() [1/2]

void Halide::Internal::Function::deep_copy | ( | const 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]

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

References name().

## define()

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

References args(), and values().

## define_update()

void Halide::Internal::Function::define_update | ( | const std::vector< Expr > & | args,
|  | std::vector< Expr > | values,
|  | const ReductionDomain & | rdom = ReductionDomain{} )

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' may depend on some reduction domain may contain variables from that domain as well as pure variables. A reduction domain may also be introduced by passing it as the last argument. 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.

References args(), and values().

## accept()

void Halide::Internal::Function::accept | ( | IRVisitor * | visitor | ) | const

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

## mutate()

void Halide::Internal::Function::mutate | ( | IRMutator * | mutator | ) |

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

Referenced by Halide::SimdOpCheckTest::check_one().

## name()

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

Get the name of the function.

Referenced by deep_copy(), Halide::Internal::Autoscheduler::LoopNestParser::is_in_partial_schedule(), is_pure_arg(), and update_with_deserialization().

## origin_name()

const std::string & Halide::Internal::Function::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 the original Func.

Otherwise returns the name.

Referenced by update_with_deserialization().

## definition() [1/2]

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

Get a mutable handle to the init definition.

## definition() [2/2]

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

Get the init definition.

## args()

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

Get the pure arguments.

Referenced by define(), define_extern(), define_update(), make_call_to_extern_definition(), and update_with_deserialization().

## dimensions()

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

Get the dimensionality.

## outputs()

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

Get the number of outputs.

## output_types()

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

Get the types of the outputs.

Referenced by update_with_deserialization().

## required_types()

const std::vector< Type > & Halide::Internal::Function::required_types | ( |  | ) | const

Get the type constaints on the outputs (if any).

Referenced by Function(), and update_with_deserialization().

## required_dimensions()

int Halide::Internal::Function::required_dimensions | ( |  | ) | const

Get the dimensionality constaints on the outputs (if any).

## values()

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

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

Returns an empty vector if there is no pure definition.

Warning: Any Vars in the Exprs are not qualified with the Func name, so the Exprs may contain names which collide with names provided by unique_name.

Referenced by define(), and define_update().

## has_pure_definition()

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

Does this function have a pure definition?

Referenced by is_pure().

## is_pure()

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

inline

Does this function only have a pure definition?

Definition at line 184 of file Function.h.

References has_extern_definition(), has_pure_definition(), and has_update_definition().

## can_be_inlined()

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

Is it legal to inline this function?

## schedule() [1/2]

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

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

## schedule() [2/2]

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

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

## output_buffers()

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

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

Referenced by update_with_deserialization().

## update_schedule()

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]

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

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

Referenced by Halide::SimdOpCheckTest::check_one().

## update() [2/2]

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

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

## updates()

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

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

Referenced by update_with_deserialization().

## has_update_definition()

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

Does this function have an update definition?

Referenced by Halide::SimdOpCheckTest::check_one(), and is_pure().

## has_extern_definition()

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

Check if the function has an extern definition.

Referenced by is_pure().

## extern_definition_name_mangling()

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

Get the name mangling specified for the extern definition.

## make_call_to_extern_definition()

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.

References args().

## extern_definition_proxy_expr() [1/2]

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]

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

## define_extern()

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

References args().

## extern_arguments() [1/2]

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

Retrive the arguments of the extern definition.

Referenced by update_with_deserialization().

## extern_arguments() [2/2]

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

## extern_function_name()

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

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

Referenced by update_with_deserialization().

## extern_function_device_api()

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 265 of file Function.h.

References Function().

## debug_file() [1/2]

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

Get a const handle to the debug filename.

Referenced by update_with_deserialization().

## debug_file() [2/2]

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

Get a handle to the debug filename.

## operator ExternFuncArgument()

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

Use an an extern argument to another function.

## trace_loads()

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

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

Referenced by update_with_deserialization().

## trace_stores()

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

Referenced by update_with_deserialization().

## trace_realizations()

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

Referenced by update_with_deserialization().

## add_trace_tag()

void Halide::Internal::Function::add_trace_tag | ( | const std::string & | trace_tag | ) |

## is_tracing_loads()

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

## is_tracing_stores()

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

## is_tracing_realizations()

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

## get_trace_tags()

const std::vector< std::string > & Halide::Internal::Function::get_trace_tags | ( |  | ) | const

## lock_loop_levels()

void Halide::Internal::Function::lock_loop_levels | ( |  | ) |

Replace this Function's LoopLevels with locked copies that cannot be mutated further.

## do_not_profile()

void Halide::Internal::Function::do_not_profile | ( |  | ) |

Mark the function as too small for meaningful profiling.

## should_not_profile()

bool Halide::Internal::Function::should_not_profile | ( |  | ) | const

Check if the function is marked as one that should not be profiled.

## freeze()

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

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

## frozen()

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

Check if a function has been frozen.

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

Referenced by update_with_deserialization().

## 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.

References Function().

## add_wrapper()

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.

References Function().

## wrappers()

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

## is_wrapper()

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]

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).

References Function().

## substitute_calls() [2/2]

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

References Function(), and Halide::Internal::substitute().

## is_pure_arg()

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.

References name().

## check_types() [1/5]

void Halide::Internal::Function::check_types | ( | const Expr & | e | ) | const

If the Function has type requirements, check that the given argument is compatible with them.

If not, assert-fail. (If there are no type requirements, do nothing.)

## check_types() [2/5]

void Halide::Internal::Function::check_types | ( | const Tuple & | t | ) | const

## check_types() [3/5]

void Halide::Internal::Function::check_types | ( | const Type & | t | ) | const

## check_types() [4/5]

void Halide::Internal::Function::check_types | ( | const std::vector< Expr > & | exprs | ) | const

## check_types() [5/5]

void Halide::Internal::Function::check_types | ( | const std::vector< Type > & | types | ) | const

## check_dims()

void Halide::Internal::Function::check_dims | ( | int | dims | ) | const

If the Function has dimension requirements, check that the given argument is compatible with them.

If not, assert-fail. (If there are no dimension requirements, do nothing.)

## create_output_buffers()

void Halide::Internal::Function::create_output_buffers | ( | const std::vector< Type > & | types,
|  | int | dims ) const

Define the output buffers.

If the Function has types specified, this can be called at any time. If not, it can only be called for a Function with a pure definition.

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

- src/Function.h