Class ObjectRef#
Defined in File object.h
Inheritance Relationships#
Derived Types#
public tvm::ffi::Array< tvm::ffi::Any >(Template Class Array)public tvm::ffi::Array< tvm::ffi::Tuple< int32_t, tvm::ffi::Function > >(Template Class Array)public tvm::ffi::Dict< tvm::ffi::Any, tvm::ffi::ObjectRef >(Template Class Dict)public tvm::ffi::Dict< tvm::ffi::String, tvm::ffi::Dict< tvm::ffi::ObjectRef, tvm::ffi::Any > >(Template Class Dict)public tvm::ffi::List< tvm::ffi::ObjectRef >(Template Class List)public tvm::ffi::Map< tvm::ffi::String, tvm::ffi::Function >(Template Class Map)public tvm::ffi::Array< T, typename >(Template Class Array)public tvm::ffi::Dict< K, V, typename >(Template Class Dict)public tvm::ffi::Enum(Class Enum)public tvm::ffi::EnumState(Class EnumState)public tvm::ffi::Error(Class Error)public tvm::ffi::Function(Class Function)public tvm::ffi::List< T, typename >(Template Class List)public tvm::ffi::Map< K, V, typename >(Template Class Map)public tvm::ffi::Module(Class Module)public tvm::ffi::Optional< T, std::enable_if_t< use_object_ref_optional_v< T > > >public tvm::ffi::Shape(Class Shape)public tvm::ffi::StructuralKey(Class StructuralKey)public tvm::ffi::StructuralMutator(Class StructuralMutator)public tvm::ffi::StructuralVisitor(Class StructuralVisitor)public tvm::ffi::Tensor(Class Tensor)public tvm::ffi::Tuple< Types >(Template Class Tuple)public tvm::ffi::VisitErrorContext(Class VisitErrorContext)public tvm::ffi::VisitInterrupt(Class VisitInterrupt)public tvm::ffi::reflection::AccessPath(Class AccessPath)public tvm::ffi::reflection::AccessStep(Class AccessStep)
Class Documentation#
-
class ObjectRef#
ObjectRef is the base class for named, managed references to TVM-FFI objects.
Each reference holds an
ObjectPtr<Object>, which manages the underlying object’s lifetime through reference counting. Useoperator->to access data members and member functions of the underlying object.A reference class can define its own constructors, member functions, and operators, and inherit from other reference classes to share and specialize its interface. It can also impose additional constraints on the underlying object.
Subclassed by tvm::ffi::Array< tvm::ffi::Any >, tvm::ffi::Array< tvm::ffi::Tuple< int32_t, tvm::ffi::Function > >, tvm::ffi::Dict< tvm::ffi::Any, tvm::ffi::ObjectRef >, tvm::ffi::Dict< tvm::ffi::String, tvm::ffi::Dict< tvm::ffi::ObjectRef, tvm::ffi::Any > >, tvm::ffi::List< tvm::ffi::ObjectRef >, tvm::ffi::Map< tvm::ffi::String, tvm::ffi::Function >, tvm::ffi::Array< T, typename >, tvm::ffi::Dict< K, V, typename >, tvm::ffi::Enum, tvm::ffi::EnumState, tvm::ffi::Error, tvm::ffi::Function, tvm::ffi::List< T, typename >, tvm::ffi::Map< K, V, typename >, tvm::ffi::Module, tvm::ffi::Optional< T, std::enable_if_t< use_object_ref_optional_v< T > > >, tvm::ffi::Shape, tvm::ffi::StructuralKey, tvm::ffi::StructuralMutator, tvm::ffi::StructuralVisitor, tvm::ffi::Tensor, tvm::ffi::Tuple< Types >, tvm::ffi::VisitErrorContext, tvm::ffi::VisitInterrupt, tvm::ffi::reflection::AccessPath, tvm::ffi::reflection::AccessStep
Public Functions
-
ObjectRef() = default#
default constructor
-
~ObjectRef() = default#
-
inline explicit ObjectRef(UnsafeInit)#
Constructor from UnsafeInit.
-
inline bool same_as(const ObjectRef &other) const#
Comparator.
- Parameters:
other – Another object ref.
- Returns:
the compare result.
-
inline bool defined() const#
- Returns:
whether the object is defined.
-
inline bool unique() const#
- Returns:
whether the reference is unique
-
inline int use_count() const#
- Returns:
The use count of the ptr, for debug purposes
-
template<typename ObjectType, typename = std::enable_if_t<std::is_base_of_v<Object, ObjectType>>>
inline const ObjectType *as() const &# 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:
ObjectType – the target type, must be a subtype of Object
- Returns:
The pointer to the requested type.
-
template<typename ObjectRefType, typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
inline std::optional<ObjectRefType> as() const &# Try to downcast the ObjectRef to Optional<T> of the requested type.
If the cast fails, returns std::nullopt. If this ObjectRef is null, returns a null ref for nullable target refs and std::nullopt for non-nullable targets.
- Template Parameters:
ObjectRefType – the target type, must be a subtype of ObjectRef.
- Returns:
The optional value of the requested type.
-
template<typename ObjectRefType, typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
inline std::optional<ObjectRefType> as() &&# Try to move-downcast the ObjectRef to Optional<T> of the requested type.
If the cast succeeds, moves the internal object pointer to the returned ObjectRefType. If the cast fails, returns std::nullopt. If this ObjectRef is null, returns a null ref for nullable target refs and std::nullopt for non-nullable targets.
- Template Parameters:
ObjectRefType – the target type, must be a subtype of ObjectRef.
- Returns:
The optional value of the requested type.
-
template<typename ObjectRefType, typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
ObjectRefType as_or_throw() const &# Downcast the ObjectRef to the requested type or throw.
- Template Parameters:
ObjectRefType – the target type, must be a subtype of ObjectRef
- Returns:
The requested value.
-
template<typename ObjectRefType, typename = std::enable_if_t<std::is_base_of_v<ObjectRef, ObjectRefType>>>
ObjectRefType as_or_throw() &&# Move-downcast the ObjectRef to the requested type or throw.
If the cast succeeds, moves the internal object pointer to the returned ObjectRefType.
- Template Parameters:
ObjectRefType – the target type, must be a subtype of ObjectRef
- Returns:
The requested value.
Public Static Attributes
-
static constexpr bool _type_container_is_exact = true#
Whether ContainerType exactly describes the objects this ref can hold.
-
static constexpr bool _type_is_nullable = true#
Whether the reference can point to nullptr.
Protected Functions
Friends
- friend struct ObjectPtrHash
-
ObjectRef() = default#