Class Function#

Inheritance Relationships#

Base Type#

Class Documentation#

class Function : public tvm::ffi::ObjectRef#

ffi::Function is a type-erased function. The arguments are passed by “packed format” via AnyView

Public Functions

inline Function(std::nullptr_t)#

Constructor from null.

template<typename TCallable>
inline explicit Function(TCallable packed_call)#

Constructing a packed function from a callable type whose signature is consistent with ffi::Function

Note

legacy purpose, should change to Function::FromPacked for mostfuture use.

Parameters:

packed_call – The packed function signature

inline void CallPacked(const AnyView *args, int32_t num_args, Any *result) const#

Call the function in packed format.

Parameters:
  • args – The arguments

  • num_args – The number of arguments

  • result – The return value.

inline void CallPacked(PackedArgs args, Any *result) const#

Call the function in packed format.

Parameters:
  • args – The arguments

  • result – The return value.

Public Static Functions

template<typename TCallable>
static inline Function FromPacked(TCallable packed_call)#

Constructing a packed function from a callable type whose signature is consistent with ffi::Function

Parameters:

packed_call – The packed function signature

static inline Function FromExternC(void *self, TVMFFISafeCallType safe_call, void (*deleter)(void *self))#

Create ffi::Function from a C style callbacks.

self and deleter can be nullptr if the function do not need closure support and corresponds to a raw function pointer.

Parameters:
  • self – Resource handle to the function

  • safe_call – The safe_call definition in C.

  • deleter – The deleter to release the resource of self.

Returns:

The created function.

static inline std::optional<Function> GetGlobal(std::string_view name)#

Get global function by name.

Note

This function will return std::nullopt if the function is not found.

Parameters:

name – The function name

Returns:

The global function.

static inline std::optional<Function> GetGlobal(const std::string &name)#

Get global function by name.

Note

This function will return std::nullopt if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline std::optional<Function> GetGlobal(const String &name)#

Get global function by name.

Note

This function will return std::nullopt if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline std::optional<Function> GetGlobal(const char *name)#

Get global function by name.

Note

This function will return std::nullopt if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline Function GetGlobalRequired(std::string_view name)#

Get global function by name and throw an error if it is not found.

Note

This function will throw an error if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline Function GetGlobalRequired(const std::string &name)#

Get global function by name.

Note

This function will throw an error if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline Function GetGlobalRequired(const String &name)#

Get global function by name.

Note

This function will throw an error if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline Function GetGlobalRequired(const char *name)#

Get global function by name.

Note

This function will throw an error if the function is not found.

Parameters:

name – The name of the function

Returns:

The global function

static inline void SetGlobal(std::string_view name, Function func, bool override = false)#

Set global function by name.

Parameters:
  • name – The name of the function

  • func – The function

  • override – Whether to override when there is duplication.

static inline std::vector<String> ListGlobalNames()#

List all global names.

Note

This function do not depend on Array so core do not have container dep.

Returns:

A vector of all global names

static inline void RemoveGlobal(const String &name)#

Remove a global function by name.

Parameters:

name – The name of the function

template<typename TCallable>
static inline Function FromTyped(TCallable callable)#

Constructing a packed function from a normal function.

Parameters:

callable – the internal container of packed function.

template<typename TCallable>
static inline Function FromTyped(TCallable callable, std::string name)#

Constructing a packed function from a normal function.

Parameters:
  • callable – the internal container of packed function.

  • name – optional name attacked to the function.