tvm
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>

Inheritance diagram for tvm::runtime::PackedFunc:
Collaboration diagram for tvm::runtime::PackedFunc:

Public Member Functions

 PackedFunc (std::nullptr_t null)
 Constructor from null. More...
 
template<typename TCallable , typename = std::enable_if_t< std::is_convertible<TCallable, std::function<void(TVMArgs, TVMRetValue*)>>::value && !std::is_base_of<TCallable, PackedFunc>::value>>
 PackedFunc (TCallable data)
 Constructing a packed function from a callable type whose signature is consistent with PackedFunc More...
 
template<typename... Args>
TVMRetValue operator() (Args &&... args) const
 Call packed function by directly passing in unpacked format. More...
 
TVM_ALWAYS_INLINE void CallPacked (TVMArgs args, TVMRetValue *rv) const
 Call the function in packed format. More...
 
bool operator== (std::nullptr_t null) const
 
bool operator!= (std::nullptr_t null) const
 
 TVM_DEFINE_OBJECT_REF_METHODS (PackedFunc, ObjectRef, PackedFuncObj)
 
- Public Member Functions inherited from tvm::runtime::ObjectRef
 ObjectRef ()=default
 default constructor More...
 
 ObjectRef (ObjectPtr< Object > data)
 Constructor from existing object ptr. More...
 
bool same_as (const ObjectRef &other) const
 Comparator. More...
 
bool operator== (const ObjectRef &other) const
 Comparator. More...
 
bool operator!= (const ObjectRef &other) const
 Comparator. More...
 
bool operator< (const ObjectRef &other) const
 Comparator. More...
 
bool defined () const
 
const Objectget () const
 
const Objectoperator-> () const
 
bool unique () const
 
int use_count () const
 
template<typename ObjectType , typename = std::enable_if_t<std::is_base_of_v<Object, ObjectType>>>
const ObjectType * as () const
 Try to downcast the internal Object to a raw pointer of a corresponding type. More...
 
template<typename ObjectRefType , typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
Optional< ObjectRefType > as () const
 Try to downcast the ObjectRef to a Optional<T> of the requested type. More...
 

Additional Inherited Members

- Public Types inherited from tvm::runtime::ObjectRef
using ContainerType = Object
 type indicate the container type. More...
 
- Static Public Attributes inherited from tvm::runtime::ObjectRef
static constexpr bool _type_is_nullable = true
 
- Protected Member Functions inherited from tvm::runtime::ObjectRef
Objectget_mutable () const
 
- Static Protected Member Functions inherited from tvm::runtime::ObjectRef
template<typename T >
static T DowncastNoCheck (ObjectRef ref)
 Internal helper function downcast a ref without check. More...
 
static void FFIClearAfterMove (ObjectRef *ref)
 Clear the object ref data field without DecRef after we successfully moved the field. More...
 
template<typename ObjectType >
static ObjectPtr< ObjectType > GetDataPtr (const ObjectRef &ref)
 Internal helper function get data_ as ObjectPtr of ObjectType. More...
 
- Protected Attributes inherited from tvm::runtime::ObjectRef
ObjectPtr< Objectdata_
 Internal pointer that backs the reference. More...
 

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 type of TVM. It corresponds to TVMFunctionHandle in C runtime API.

Constructor & Destructor Documentation

◆ PackedFunc() [1/2]

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

Constructor from null.

◆ PackedFunc() [2/2]

template<typename TCallable , typename = std::enable_if_t< std::is_convertible<TCallable, std::function<void(TVMArgs, TVMRetValue*)>>::value && !std::is_base_of<TCallable, PackedFunc>::value>>
tvm::runtime::PackedFunc::PackedFunc ( TCallable  data)
inlineexplicit

Constructing a packed function from a callable type whose signature is consistent with PackedFunc

Parameters
datathe internal container of packed function.

Member Function Documentation

◆ CallPacked()

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

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);
}
TVM_ALWAYS_INLINE void CallPacked(TVMArgs args, TVMRetValue *rv) const
Call the function in packed format.
Definition: packed_func.h:1259
PackedFunc(std::nullptr_t null)
Constructor from null.
Definition: packed_func.h:142

◆ operator==()

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

◆ TVM_DEFINE_OBJECT_REF_METHODS()

tvm::runtime::PackedFunc::TVM_DEFINE_OBJECT_REF_METHODS ( PackedFunc  ,
ObjectRef  ,
PackedFuncObj   
)

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