mxnet
Public Types | Public Member Functions | List of all members
mxnet::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 mxnet::runtime::PackedFunc:
Collaboration graph

Public Types

using FType = std::function< void(MXNetArgs args, MXNetRetValue *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>
MXNetRetValue operator() (Args &&...args) const
 Call packed function by directly passing in unpacked format. More...
 
void CallPacked (MXNetArgs args, MXNetRetValue *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

using mxnet::runtime::PackedFunc::FType = std::function<void (MXNetArgs args, MXNetRetValue* rv)>

The internal std::function.

Parameters
argsThe arguments to the function.
rvThe return value.
// Example code on how to implemented FType
void MyPackedFunc(MXNetArgs args, MXNetRetValue* 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

mxnet::runtime::PackedFunc::PackedFunc ( )
inline

default constructor

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

constructor from null

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

constructing a packed function from a std::function.

Parameters
bodythe internal container of packed function.

Member Function Documentation

PackedFunc::FType mxnet::runtime::PackedFunc::body ( ) const
inline
Returns
the internal body function
void mxnet::runtime::PackedFunc::CallPacked ( MXNetArgs  args,
MXNetRetValue rv 
) const
inline

Call the function in packed format.

Parameters
argsThe arguments
rvThe return value.
bool mxnet::runtime::PackedFunc::operator!= ( std::nullptr_t  null) const
inline
Returns
Whether the packed function is not nullptr
template<typename... Args>
MXNetRetValue mxnet::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);
}
bool mxnet::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: