tvm
Public Types | Public Member Functions | List of all members
tvm::runtime::PackedFunc Class Reference

Packed function is a type-erased function. The arguments are passed by packed format. More...

#include <packed_func.h>

Collaboration diagram for tvm::runtime::PackedFunc:

Public Types

using FType = std::function< void(TVMArgs args, TVMRetValue *rv)>
 The internal std::function. More...
 

Public Member Functions

 PackedFunc ()
 default constructor More...
 
 PackedFunc (std::nullptr_t null)
 constructor from null More...
 
 PackedFunc (FType body)
 constructing a packed function from a std::function. More...
 
template<typename... Args>
TVMRetValue operator() (Args &&... args) const
 Call packed function by directly passing in unpacked format. More...
 
void CallPacked (TVMArgs args, TVMRetValue *rv) const
 Call the function in packed format. More...
 
FType body () const
 
bool operator== (std::nullptr_t null) const
 
bool operator!= (std::nullptr_t null) const
 

Detailed Description

Packed function is a type-erased function. The arguments are passed by packed format.

This is an useful unified interface to call generated functions, It is the unified function function type of TVM. It corresponds to TVMFunctionHandle in C runtime API.

Member Typedef Documentation

◆ FType

using tvm::runtime::PackedFunc::FType = std::function<void(TVMArgs args, TVMRetValue* rv)>

The internal std::function.

Parameters
argsThe arguments to the function.
rvThe return value.
// Example code on how to implemented FType
void MyPackedFunc(TVMArgs args, TVMRetValue* rv) {
// automatically convert arguments to desired type.
int a0 = args[0];
float a1 = args[1];
...
// automatically assign values to rv
std::string my_return_value = "x";
*rv = my_return_value;
}

Constructor & Destructor Documentation

◆ PackedFunc() [1/3]

tvm::runtime::PackedFunc::PackedFunc ( )
inline

default constructor

◆ PackedFunc() [2/3]

tvm::runtime::PackedFunc::PackedFunc ( std::nullptr_t  null)
inline

constructor from null

◆ PackedFunc() [3/3]

tvm::runtime::PackedFunc::PackedFunc ( FType  body)
inlineexplicit

constructing a packed function from a std::function.

Parameters
bodythe internal container of packed function.

Member Function Documentation

◆ body()

PackedFunc::FType tvm::runtime::PackedFunc::body ( ) const
inline
Returns
the internal body function

◆ CallPacked()

void tvm::runtime::PackedFunc::CallPacked ( TVMArgs  args,
TVMRetValue rv 
) const
inline

Call the function in packed format.

Parameters
argsThe arguments
rvThe return value.

◆ operator!=()

bool tvm::runtime::PackedFunc::operator!= ( std::nullptr_t  null) const
inline
Returns
Whether the packed function is not nullptr

◆ operator()()

template<typename... Args>
TVMRetValue tvm::runtime::PackedFunc::operator() ( Args &&...  args) const
inline

Call packed function by directly passing in unpacked format.

Parameters
argsArguments to be passed.
Template Parameters
Argsarguments to be passed.
// Example code on how to call packed function
// call like normal functions by pass in arguments
// return value is automatically converted back
int rvalue = f(1, 2.0);
}

◆ operator==()

bool tvm::runtime::PackedFunc::operator== ( std::nullptr_t  null) const
inline
Returns
Whether the packed function is nullptr

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