tvm
Public Member Functions | List of all members
tvm::script::printer::TracedObjectFunctor< R, Args > Class Template Reference

Dynamic dispatch functor based on TracedObject. More...

#include <traced_object_functor.h>

Collaboration diagram for tvm::script::printer::TracedObjectFunctor< R, Args >:

Public Member Functions

template<class TObjectRef >
operator() (const String &token, TracedObject< TObjectRef > traced_object, Args... args) const
 Call the dispatch function. More...
 
TSelfset_dispatch (String token, uint32_t type_index, runtime::PackedFunc f)
 Set the dispatch function. More...
 
template<typename TObjectRef , typename TCallable , typename = std::enable_if_t<IsDispatchFunction<TObjectRef, TCallable>::value>>
TSelfset_dispatch (String token, TCallable f)
 Set the dispatch function. More...
 
template<typename TObjectRef , typename TCallable , typename = std::enable_if_t<IsDispatchFunction<TObjectRef, TCallable>::value>>
TSelfset_dispatch (TCallable &&f)
 Set the default dispatch function. More...
 
void remove_dispatch (String token, uint32_t type_index)
 Remove dispatch function. More...
 

Detailed Description

template<typename R, typename... Args>
class tvm::script::printer::TracedObjectFunctor< R, Args >

Dynamic dispatch functor based on TracedObject.

This functor dispatches based on the type of object ref inside the input TracedObject, and the input dispatch token.

Member Function Documentation

◆ operator()()

template<typename R , typename... Args>
template<class TObjectRef >
R tvm::script::printer::TracedObjectFunctor< R, Args >::operator() ( const String token,
TracedObject< TObjectRef >  traced_object,
Args...  args 
) const
inline

Call the dispatch function.

Parameters
tokenThe dispatch token.
traced_objectThe traced object.
argsOther args.
Returns
The return value of the dispatch function

If the TObjectRef isn't registered with the token, it will try to find dispatch function for TObjectRef with kDefaultDispatchToken.

◆ remove_dispatch()

template<typename R , typename... Args>
void tvm::script::printer::TracedObjectFunctor< R, Args >::remove_dispatch ( String  token,
uint32_t  type_index 
)
inline

Remove dispatch function.

Parameters
tokenThe dispatch token.
type_indexThe TVM object type index for the dispatch function to be removed.

This is useful when dispatch function comes from other language's runtime, and those function should be removed before that language runtime shuts down.

◆ set_dispatch() [1/3]

template<typename R , typename... Args>
TSelf& tvm::script::printer::TracedObjectFunctor< R, Args >::set_dispatch ( String  token,
uint32_t  type_index,
runtime::PackedFunc  f 
)
inline

Set the dispatch function.

Parameters
tokenThe dispatch token.
type_indexThe TVM object type index for this dispatch function.
fThe dispatch function.

This takes a type-erased packed function as input. It should be used through FFI boundary, for example, registering dispatch function from Python.

◆ set_dispatch() [2/3]

template<typename R , typename... Args>
template<typename TObjectRef , typename TCallable , typename = std::enable_if_t<IsDispatchFunction<TObjectRef, TCallable>::value>>
TSelf& tvm::script::printer::TracedObjectFunctor< R, Args >::set_dispatch ( String  token,
TCallable  f 
)
inline

Set the dispatch function.

Parameters
tokenThe dispatch token.
fThe dispatch function.

The diaptch function should have signature R(TracedObject<TObjectRef>, Args...).

◆ set_dispatch() [3/3]

template<typename R , typename... Args>
template<typename TObjectRef , typename TCallable , typename = std::enable_if_t<IsDispatchFunction<TObjectRef, TCallable>::value>>
TSelf& tvm::script::printer::TracedObjectFunctor< R, Args >::set_dispatch ( TCallable &&  f)
inline

Set the default dispatch function.

Parameters
fThe dispatch function.

Default dispatch function will be used if there is no function registered with the requested dispatch token.

Default dispatch function has an empty string as dispatch token.


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