tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
tvm::runtime::ObjectRef Class Reference

Base class of all object reference. More...

#include <object.h>

Inheritance diagram for tvm::runtime::ObjectRef:
Collaboration diagram for tvm::runtime::ObjectRef:

Public Types

using ContainerType = Object
 type indicate the container type. More...
 

Public Member Functions

 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 Attributes

static constexpr bool _type_is_nullable = true
 

Protected Member Functions

Objectget_mutable () const
 

Static Protected Member Functions

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

ObjectPtr< Objectdata_
 Internal pointer that backs the reference. More...
 

Friends

struct ObjectPtrHash
 
class TVMRetValue
 
class TVMArgsSetter
 
class ObjectInternal
 
template<typename SubRef , typename BaseRef >
SubRef Downcast (BaseRef ref)
 Downcast a base reference type to a more specific type. More...
 

Detailed Description

Base class of all object reference.

Member Typedef Documentation

◆ ContainerType

type indicate the container type.

Constructor & Destructor Documentation

◆ ObjectRef() [1/2]

tvm::runtime::ObjectRef::ObjectRef ( )
default

◆ ObjectRef() [2/2]

tvm::runtime::ObjectRef::ObjectRef ( ObjectPtr< Object data)
inlineexplicit

Constructor from existing object ptr.

Member Function Documentation

◆ as() [1/2]

template<typename ObjectType , typename >
const ObjectType * tvm::runtime::ObjectRef::as
inline

Try to downcast the internal Object to a raw pointer of a corresponding type.

The function will return a nullptr if the cast failed.

if (const AddNode *ptr = node_ref.as<AddNode>()) {
  // This is an add node
}
Template Parameters
ObjectTypethe target type, must be a subtype of Object

◆ as() [2/2]

template<typename ObjectRefType , typename >
Optional< ObjectRefType > tvm::runtime::ObjectRef::as
inline

Try to downcast the ObjectRef to a Optional<T> of the requested type.

The function will return a NullOpt if the cast failed.

if (Optional<Add> opt = node_ref.as<Add>()) {
  // This is an add node
}
Note
While this method is declared in <tvm/runtime/object.h>, the implementation is in <tvm/runtime/container/optional.h> to prevent circular includes. This additional include file is only required in compilation units that uses this method.
Template Parameters
ObjectRefTypethe target type, must be a subtype of ObjectRef

◆ defined()

bool tvm::runtime::ObjectRef::defined ( ) const
inline
Returns
whether the object is defined(not null).

◆ DowncastNoCheck()

template<typename T >
static T tvm::runtime::ObjectRef::DowncastNoCheck ( ObjectRef  ref)
inlinestaticprotected

Internal helper function downcast a ref without check.

Note
Only used for internal dev purposes.
Template Parameters
TThe target reference type.
Returns
The casted result.

◆ FFIClearAfterMove()

static void tvm::runtime::ObjectRef::FFIClearAfterMove ( ObjectRef ref)
inlinestaticprotected

Clear the object ref data field without DecRef after we successfully moved the field.

Parameters
refThe reference data.

◆ get()

const Object* tvm::runtime::ObjectRef::get ( ) const
inline
Returns
the internal object pointer

◆ get_mutable()

Object* tvm::runtime::ObjectRef::get_mutable ( ) const
inlineprotected
Returns
return a mutable internal ptr, can be used by sub-classes.

◆ GetDataPtr()

template<typename ObjectType >
static ObjectPtr<ObjectType> tvm::runtime::ObjectRef::GetDataPtr ( const ObjectRef ref)
inlinestaticprotected

Internal helper function get data_ as ObjectPtr of ObjectType.

Note
only used for internal dev purpose.
Template Parameters
ObjectTypeThe corresponding object type.
Returns
the corresponding type.

◆ operator!=()

bool tvm::runtime::ObjectRef::operator!= ( const ObjectRef other) const
inline

Comparator.

Parameters
otherAnother object ref.
Returns
the compare result.

◆ operator->()

const Object* tvm::runtime::ObjectRef::operator-> ( ) const
inline
Returns
the internal object pointer

◆ operator<()

bool tvm::runtime::ObjectRef::operator< ( const ObjectRef other) const
inline

Comparator.

Parameters
otherAnother object ref by address.
Returns
the compare result.

◆ operator==()

bool tvm::runtime::ObjectRef::operator== ( const ObjectRef other) const
inline

Comparator.

Parameters
otherAnother object ref.
Returns
the compare result.

◆ same_as()

bool tvm::runtime::ObjectRef::same_as ( const ObjectRef other) const
inline

Comparator.

Parameters
otherAnother object ref.
Returns
the compare result.

◆ unique()

bool tvm::runtime::ObjectRef::unique ( ) const
inline
Returns
whether the reference is unique

◆ use_count()

int tvm::runtime::ObjectRef::use_count ( ) const
inline
Returns
The use count of the ptr, for debug purposes

Friends And Related Function Documentation

◆ Downcast

template<typename SubRef , typename BaseRef >
SubRef Downcast ( BaseRef  ref)
friend

Downcast a base reference type to a more specific type.

Parameters
refThe input reference
Returns
The corresponding SubRef.
Template Parameters
SubRefThe target specific reference type.
BaseRefthe current reference type.

◆ ObjectInternal

friend class ObjectInternal
friend

◆ ObjectPtrHash

friend struct ObjectPtrHash
friend

◆ TVMArgsSetter

friend class TVMArgsSetter
friend

◆ TVMRetValue

friend class TVMRetValue
friend

Member Data Documentation

◆ _type_is_nullable

constexpr bool tvm::runtime::ObjectRef::_type_is_nullable = true
staticconstexpr

◆ data_

ObjectPtr<Object> tvm::runtime::ObjectRef::data_
protected

Internal pointer that backs the reference.

Examples
/workspace/include/tvm/script/ir_builder/base.h.

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