tvm
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
tvm::GenericFunc Class Reference

Generic function that can be specialized on a per-target basis. More...

#include <generic_func.h>

Inheritance diagram for tvm::GenericFunc:
Collaboration diagram for tvm::GenericFunc:

Public Types

using ContainerType = GenericFuncNode
 
- Public Types inherited from tvm::runtime::ObjectRef
using ContainerType = Object
 type indicate the container type. More...
 

Public Member Functions

 GenericFunc ()
 
 GenericFunc (ObjectPtr< Object > n)
 
GenericFuncset_default (const runtime::PackedFunc value, bool allow_override=false)
 Set the default function implementaiton. More...
 
GenericFuncregister_func (const std::vector< std::string > &tags, const runtime::PackedFunc value, bool allow_override=false)
 Register a specialized function. More...
 
template<typename... Args>
runtime::TVMRetValue operator() (Args &&... args) const
 Call generic function by directly passing in unpacked format. More...
 
void CallPacked (runtime::TVMArgs args, runtime::TVMRetValue *ret) const
 Invoke the relevant function for the current target context, set by set_target_context. Arguments are passed in packed format. More...
 
PackedFunc GetPacked () const
 Get the packed function specified for the current target context. More...
 
GenericFuncNodeoperator-> ()
 access the internal node container More...
 
- 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...
 

Static Public Member Functions

static GenericFunc Get (const std::string &name)
 Find or register the GenericFunc instance corresponding to the give name. More...
 
static void RegisterGenericFunc (GenericFunc func, const std::string &name)
 Add a GenericFunc instance to the registry. More...
 

Friends

struct Manager
 

Additional Inherited Members

- 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

Generic function that can be specialized on a per-target basis.

Member Typedef Documentation

◆ ContainerType

Constructor & Destructor Documentation

◆ GenericFunc() [1/2]

tvm::GenericFunc::GenericFunc ( )
inline

◆ GenericFunc() [2/2]

tvm::GenericFunc::GenericFunc ( ObjectPtr< Object n)
inlineexplicit

Member Function Documentation

◆ CallPacked()

void tvm::GenericFunc::CallPacked ( runtime::TVMArgs  args,
runtime::TVMRetValue ret 
) const

Invoke the relevant function for the current target context, set by set_target_context. Arguments are passed in packed format.

Parameters
argsThe arguments to pass to the function.
retThe return value

◆ Get()

static GenericFunc tvm::GenericFunc::Get ( const std::string &  name)
static

Find or register the GenericFunc instance corresponding to the give name.

Parameters
nameThe name of the registered GenericFunc
Returns
The GenericFunc instance

◆ GetPacked()

PackedFunc tvm::GenericFunc::GetPacked ( ) const

Get the packed function specified for the current target context.

◆ operator()()

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

Call generic function by directly passing in unpacked format.

Parameters
argsArguments to be passed.
Template Parameters
Argsarguments to be passed.
// Example code on how to call generic function
void CallGeneric(GenericFunc f) {
// call like normal functions by pass in arguments
// return value is automatically converted back
int rvalue = f(1, 2.0);
}
GenericFunc()
Definition: generic_func.h:45

◆ operator->()

GenericFuncNode * tvm::GenericFunc::operator-> ( )
inline

access the internal node container

Returns
the pointer to the internal node container

◆ register_func()

GenericFunc& tvm::GenericFunc::register_func ( const std::vector< std::string > &  tags,
const runtime::PackedFunc  value,
bool  allow_override = false 
)

Register a specialized function.

Parameters
tagsThe tags for this specialization
valueThe specialized function
allow_overrideIf true, this call may override previously registered tags. If false, an error will be logged if the call would override previously registered tags.
Returns
reference to self.

◆ RegisterGenericFunc()

static void tvm::GenericFunc::RegisterGenericFunc ( GenericFunc  func,
const std::string &  name 
)
static

Add a GenericFunc instance to the registry.

Parameters
funcThe GenericFunc instance
nameThe name of the registered GenericFunc

◆ set_default()

GenericFunc& tvm::GenericFunc::set_default ( const runtime::PackedFunc  value,
bool  allow_override = false 
)

Set the default function implementaiton.

Parameters
valueThe default function
allow_overrideIf true, this call may override a previously registered function. If false, an error will be logged if the call would override a previously registered function.
Returns
reference to self.

Friends And Related Function Documentation

◆ Manager

friend struct Manager
friend

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