tvm
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
tvm::runtime::Registry Class Reference

Registry for global function. More...

#include <registry.h>

Collaboration diagram for tvm::runtime::Registry:

Public Member Functions

Registryset_body (PackedFunc f)
 set the body of the function to be f More...
 
template<typename TCallable , typename = typename std::enable_if_t< std::is_convertible<TCallable, std::function<void(TVMArgs, TVMRetValue*)>>::value && !std::is_base_of<PackedFunc, TCallable>::value>>
Registryset_body (TCallable f)
 set the body of the function to be f More...
 
template<typename FLambda >
Registryset_body_typed (FLambda f)
 set the body of the function to the given function. Note that this will ignore default arg values and always require all arguments to be provided. More...
 
template<typename T , typename R , typename... Args>
Registryset_body_method (R(T::*f)(Args...))
 set the body of the function to be the passed method pointer. Note that this will ignore default arg values and always require all arguments to be provided. More...
 
template<typename T , typename R , typename... Args>
Registryset_body_method (R(T::*f)(Args...) const)
 set the body of the function to be the passed method pointer. Note that this will ignore default arg values and always require all arguments to be provided. More...
 
template<typename TObjectRef , typename TNode , typename R , typename... Args, typename = typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
Registryset_body_method (R(TNode::*f)(Args...))
 set the body of the function to be the passed method pointer. Used when calling a method on a Node subclass through a ObjectRef subclass. Note that this will ignore default arg values and always require all arguments to be provided. More...
 
template<typename TObjectRef , typename TNode , typename R , typename... Args, typename = typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
Registryset_body_method (R(TNode::*f)(Args...) const)
 set the body of the function to be the passed method pointer. Used when calling a method on a Node subclass through a ObjectRef subclass. Note that this will ignore default arg values and always require all arguments to be provided. More...
 

Static Public Member Functions

static RegistryRegister (const String &name, bool override=false)
 Register a function with given name. More...
 
static bool Remove (const String &name)
 Erase global function from registry, if exist. More...
 
static const PackedFuncGet (const String &name)
 Get the global function by name. More...
 
static std::vector< StringListNames ()
 Get the names of currently registered global function. More...
 

Protected Attributes

String name_
 name of the function More...
 
PackedFunc func_
 internal packed function More...
 

Friends

struct Manager
 

Detailed Description

Registry for global function.

Member Function Documentation

◆ Get()

static const PackedFunc* tvm::runtime::Registry::Get ( const String name)
static

Get the global function by name.

Parameters
nameThe name of the function.
Returns
pointer to the registered function, nullptr if it does not exist.

◆ ListNames()

static std::vector<String> tvm::runtime::Registry::ListNames ( )
static

Get the names of currently registered global function.

Returns
The names

◆ Register()

static Registry& tvm::runtime::Registry::Register ( const String name,
bool  override = false 
)
static

Register a function with given name.

Parameters
nameThe name of the function.
overrideWhether allow override existing function.
Returns
Reference to the registry.

◆ Remove()

static bool tvm::runtime::Registry::Remove ( const String name)
static

Erase global function from registry, if exist.

Parameters
nameThe name of the function.
Returns
Whether function exist.

◆ set_body() [1/2]

Registry& tvm::runtime::Registry::set_body ( PackedFunc  f)

set the body of the function to be f

Parameters
fThe body of the function.

◆ set_body() [2/2]

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

set the body of the function to be f

Parameters
fThe body of the function.

◆ set_body_method() [1/4]

template<typename T , typename R , typename... Args>
Registry& tvm::runtime::Registry::set_body_method ( R(T::*)(Args...) const  f)
inline

set the body of the function to be the passed method pointer. Note that this will ignore default arg values and always require all arguments to be provided.

// node subclass:
struct Example {
int doThing(int x);
}
TVM_REGISTER_GLOBAL("Example_doThing")
.set_body_method(&Example::doThing); // will have type int(Example, int)
#define TVM_REGISTER_GLOBAL(OpName)
Register a function globally.
Definition: registry.h:384
Parameters
fthe method pointer to forward to.
Template Parameters
Tthe type containing the method (inferred).
Rthe return type of the function (inferred).
Argsthe argument types of the function (inferred).

◆ set_body_method() [2/4]

template<typename T , typename R , typename... Args>
Registry& tvm::runtime::Registry::set_body_method ( R(T::*)(Args...)  f)
inline

set the body of the function to be the passed method pointer. Note that this will ignore default arg values and always require all arguments to be provided.

// node subclass:
struct Example {
int doThing(int x);
}
TVM_REGISTER_GLOBAL("Example_doThing")
.set_body_method(&Example::doThing); // will have type int(Example, int)
Parameters
fthe method pointer to forward to.
Template Parameters
Tthe type containing the method (inferred).
Rthe return type of the function (inferred).
Argsthe argument types of the function (inferred).

◆ set_body_method() [3/4]

template<typename TObjectRef , typename TNode , typename R , typename... Args, typename = typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
Registry& tvm::runtime::Registry::set_body_method ( R(TNode::*)(Args...) const  f)
inline

set the body of the function to be the passed method pointer. Used when calling a method on a Node subclass through a ObjectRef subclass. Note that this will ignore default arg values and always require all arguments to be provided.

// node subclass:
struct ExampleNode: BaseNode {
int doThing(int x);
}
// noderef subclass
struct Example;
TVM_REGISTER_GLOBAL("Example_doThing")
.set_body_method<Example>(&ExampleNode::doThing); // will have type int(Example, int)
// note that just doing:
// .set_body_method(&ExampleNode::doThing);
// wouldn't work, because ExampleNode can't be taken from a TVMArgValue.
Parameters
fthe method pointer to forward to.
Template Parameters
TObjectRefthe node reference type to call the method on
TNodethe node type containing the method (inferred).
Rthe return type of the function (inferred).
Argsthe argument types of the function (inferred).

◆ set_body_method() [4/4]

template<typename TObjectRef , typename TNode , typename R , typename... Args, typename = typename std::enable_if<std::is_base_of<ObjectRef, TObjectRef>::value>::type>
Registry& tvm::runtime::Registry::set_body_method ( R(TNode::*)(Args...)  f)
inline

set the body of the function to be the passed method pointer. Used when calling a method on a Node subclass through a ObjectRef subclass. Note that this will ignore default arg values and always require all arguments to be provided.

// node subclass:
struct ExampleNode: BaseNode {
int doThing(int x);
}
// noderef subclass
struct Example;
TVM_REGISTER_GLOBAL("Example_doThing")
.set_body_method<Example>(&ExampleNode::doThing); // will have type int(Example, int)
// note that just doing:
// .set_body_method(&ExampleNode::doThing);
// wouldn't work, because ExampleNode can't be taken from a TVMArgValue.
Parameters
fthe method pointer to forward to.
Template Parameters
TObjectRefthe node reference type to call the method on
TNodethe node type containing the method (inferred).
Rthe return type of the function (inferred).
Argsthe argument types of the function (inferred).

◆ set_body_typed()

template<typename FLambda >
Registry& tvm::runtime::Registry::set_body_typed ( FLambda  f)
inline

set the body of the function to the given function. Note that this will ignore default arg values and always require all arguments to be provided.

int multiply(int x, int y) {
return x * y;
}
.set_body_typed(multiply); // will have type int(int, int)
// will have type int(int, int)
.set_body_typed([](int a, int b) -> int { return a - b; });
tvm::PrimExpr multiply(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:225
Parameters
fThe function to forward to.
Template Parameters
FLambdaThe signature of the function.

Friends And Related Function Documentation

◆ Manager

friend struct Manager
friend

Member Data Documentation

◆ func_

PackedFunc tvm::runtime::Registry::func_
protected

internal packed function

◆ name_

String tvm::runtime::Registry::name_
protected

name of the function


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