tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
object.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
23 #ifndef TVM_RUNTIME_OBJECT_H_
24 #define TVM_RUNTIME_OBJECT_H_
25 
27 #include <tvm/runtime/logging.h>
28 
29 #include <string>
30 #include <type_traits>
31 #include <utility>
32 
39 #ifndef TVM_OBJECT_ATOMIC_REF_COUNTER
40 #define TVM_OBJECT_ATOMIC_REF_COUNTER 1
41 #endif
42 
43 #if TVM_OBJECT_ATOMIC_REF_COUNTER
44 #include <atomic>
45 #endif // TVM_OBJECT_ATOMIC_REF_COUNTER
46 
47 namespace tvm {
48 namespace runtime {
49 
55 struct TypeIndex {
56  enum {
58  kRoot = 0,
59  // Standard static index assignments,
60  // Frontends can take benefit of these constants.
75  // static assignments that may subject to change.
81  };
82 }; // namespace TypeIndex
83 
167 class TVM_DLL Object {
168  public:
173  typedef void (*FDeleter)(Object* self);
175  uint32_t type_index() const { return type_index_; }
180  std::string GetTypeKey() const { return TypeIndex2Key(type_index_); }
184  size_t GetTypeKeyHash() const { return TypeIndex2KeyHash(type_index_); }
190  template <typename TargetType>
191  inline bool IsInstance() const;
196  inline bool unique() const;
202  static std::string TypeIndex2Key(uint32_t tindex);
208  static size_t TypeIndex2KeyHash(uint32_t tindex);
214  static uint32_t TypeKey2Index(const std::string& key);
215 
216 #if TVM_OBJECT_ATOMIC_REF_COUNTER
217  using RefCounterType = std::atomic<int32_t>;
218 #else
219  using RefCounterType = int32_t;
220 #endif
221 
222  static constexpr const char* _type_key = "runtime.Object";
223 
224  static uint32_t _GetOrAllocRuntimeTypeIndex() { return TypeIndex::kRoot; }
225  static uint32_t RuntimeTypeIndex() { return TypeIndex::kRoot; }
226 
227  // Default object type properties for sub-classes
228  static constexpr bool _type_final = false;
229  static constexpr uint32_t _type_child_slots = 0;
230  static constexpr bool _type_child_slots_can_overflow = true;
231  // member information
232  static constexpr bool _type_has_method_visit_attrs = true;
233  static constexpr bool _type_has_method_sequal_reduce = false;
234  static constexpr bool _type_has_method_shash_reduce = false;
235  // NOTE: the following field is not type index of Object
236  // but was intended to be used by sub-classes as default value.
237  // The type index of Object is TypeIndex::kRoot
238  static constexpr uint32_t _type_index = TypeIndex::kDynamic;
239 
240  // Default constructor and copy constructor
241  Object() {}
242  // Override the copy and assign constructors to do nothing.
243  // This is to make sure only contents, but not deleter and ref_counter
244  // are copied when a child class copies itself.
245  // This will enable us to use make_object<ObjectClass>(*obj_ptr)
246  // to copy an existing object.
247  Object(const Object& other) { // NOLINT(*)
248  }
249  Object(Object&& other) { // NOLINT(*)
250  }
251  Object& operator=(const Object& other) { // NOLINT(*)
252  return *this;
253  }
254  Object& operator=(Object&& other) { // NOLINT(*)
255  return *this;
256  }
257 
258  protected:
259  // The fields of the base object cell.
261  uint32_t type_index_{0};
263  RefCounterType ref_counter_{0};
269  FDeleter deleter_ = nullptr;
270  // Invariant checks.
271  static_assert(sizeof(int32_t) == sizeof(RefCounterType) &&
272  alignof(int32_t) == sizeof(RefCounterType),
273  "RefCounter ABI check.");
274 
292  static uint32_t GetOrAllocRuntimeTypeIndex(const std::string& key, uint32_t static_tindex,
293  uint32_t parent_tindex, uint32_t type_child_slots,
294  bool type_child_slots_can_overflow);
295 
296  // reference counter related operations
298  inline void IncRef();
303  inline void DecRef();
304 
305  private:
310  inline int use_count() const;
316  bool DerivedFrom(uint32_t parent_tindex) const;
317  // friend classes
318  template <typename>
319  friend class ObjAllocatorBase;
320  template <typename>
321  friend class ObjectPtr;
322  friend class TVMRetValue;
323  friend class ObjectInternal;
324 };
325 
338 template <typename RelayRefType, typename ObjectType>
339 inline RelayRefType GetRef(const ObjectType* ptr);
340 
349 template <typename SubRef, typename BaseRef>
350 inline SubRef Downcast(BaseRef ref);
351 
357 template <typename T>
358 class ObjectPtr {
359  public:
363  ObjectPtr(std::nullptr_t) {} // NOLINT(*)
368  ObjectPtr(const ObjectPtr<T>& other) // NOLINT(*)
369  : ObjectPtr(other.data_) {}
374  template <typename U>
375  ObjectPtr(const ObjectPtr<U>& other) // NOLINT(*)
376  : ObjectPtr(other.data_) {
377  static_assert(std::is_base_of<T, U>::value,
378  "can only assign of child class ObjectPtr to parent");
379  }
384  ObjectPtr(ObjectPtr<T>&& other) // NOLINT(*)
385  : data_(other.data_) {
386  other.data_ = nullptr;
387  }
392  template <typename Y>
393  ObjectPtr(ObjectPtr<Y>&& other) // NOLINT(*)
394  : data_(other.data_) {
395  static_assert(std::is_base_of<T, Y>::value,
396  "can only assign of child class ObjectPtr to parent");
397  other.data_ = nullptr;
398  }
400  ~ObjectPtr() { this->reset(); }
405  void swap(ObjectPtr<T>& other) { // NOLINT(*)
406  std::swap(data_, other.data_);
407  }
411  T* get() const { return static_cast<T*>(data_); }
415  T* operator->() const { return get(); }
419  T& operator*() const { // NOLINT(*)
420  return *get();
421  }
427  ObjectPtr<T>& operator=(const ObjectPtr<T>& other) { // NOLINT(*)
428  // takes in plane operator to enable copy elison.
429  // copy-and-swap idiom
430  ObjectPtr(other).swap(*this); // NOLINT(*)
431  return *this;
432  }
438  ObjectPtr<T>& operator=(ObjectPtr<T>&& other) { // NOLINT(*)
439  // copy-and-swap idiom
440  ObjectPtr(std::move(other)).swap(*this); // NOLINT(*)
441  return *this;
442  }
447  explicit operator bool() const { return get() != nullptr; }
449  void reset() {
450  if (data_ != nullptr) {
451  data_->DecRef();
452  data_ = nullptr;
453  }
454  }
456  int use_count() const { return data_ != nullptr ? data_->use_count() : 0; }
458  bool unique() const { return data_ != nullptr && data_->use_count() == 1; }
460  bool operator==(const ObjectPtr<T>& other) const { return data_ == other.data_; }
462  bool operator!=(const ObjectPtr<T>& other) const { return data_ != other.data_; }
464  bool operator==(std::nullptr_t null) const { return data_ == nullptr; }
466  bool operator!=(std::nullptr_t null) const { return data_ != nullptr; }
467 
468  private:
470  Object* data_{nullptr};
475  explicit ObjectPtr(Object* data) : data_(data) {
476  if (data != nullptr) {
477  data_->IncRef();
478  }
479  }
485  static ObjectPtr<T> MoveFromRValueRefArg(Object** ref) {
486  ObjectPtr<T> ptr;
487  ptr.data_ = *ref;
488  *ref = nullptr;
489  return ptr;
490  }
491  // friend classes
492  friend class Object;
493  friend class ObjectRef;
494  friend struct ObjectPtrHash;
495  template <typename>
496  friend class ObjectPtr;
497  template <typename>
498  friend class ObjAllocatorBase;
499  friend class TVMPODValue_;
500  friend class TVMArgsSetter;
501  friend class TVMRetValue;
502  friend class TVMArgValue;
503  friend class TVMMovableArgValue_;
504  template <typename RelayRefType, typename ObjType>
505  friend RelayRefType GetRef(const ObjType* ptr);
506  template <typename BaseType, typename ObjType>
507  friend ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr);
508 };
509 
511 class ObjectRef {
512  public:
514  ObjectRef() = default;
516  explicit ObjectRef(ObjectPtr<Object> data) : data_(data) {}
522  bool same_as(const ObjectRef& other) const { return data_ == other.data_; }
528  bool operator==(const ObjectRef& other) const { return data_ == other.data_; }
534  bool operator!=(const ObjectRef& other) const { return data_ != other.data_; }
540  bool operator<(const ObjectRef& other) const { return data_.get() < other.data_.get(); }
544  bool defined() const { return data_ != nullptr; }
546  const Object* get() const { return data_.get(); }
548  const Object* operator->() const { return get(); }
550  bool unique() const { return data_.unique(); }
552  int use_count() const { return data_.use_count(); }
564  template <typename ObjectType>
565  inline const ObjectType* as() const;
566 
569  // Default type properties for the reference class.
570  static constexpr bool _type_is_nullable = true;
571 
572  protected:
576  Object* get_mutable() const { return data_.get(); }
583  template <typename T>
584  static T DowncastNoCheck(ObjectRef ref) {
585  return T(std::move(ref.data_));
586  }
592  static void FFIClearAfterMove(ObjectRef* ref) { ref->data_.data_ = nullptr; }
599  template <typename ObjectType>
601  return ObjectPtr<ObjectType>(ref.data_.data_);
602  }
603  // friend classes.
604  friend struct ObjectPtrHash;
605  friend class TVMRetValue;
606  friend class TVMArgsSetter;
607  friend class ObjectInternal;
608  template <typename SubRef, typename BaseRef>
609  friend SubRef Downcast(BaseRef ref);
610 };
611 
620 template <typename BaseType, typename ObjectType>
621 inline ObjectPtr<BaseType> GetObjectPtr(ObjectType* ptr);
622 
625  size_t operator()(const ObjectRef& a) const { return operator()(a.data_); }
626 
627  template <typename T>
628  size_t operator()(const ObjectPtr<T>& a) const {
629  return std::hash<Object*>()(a.get());
630  }
631 };
632 
635  bool operator()(const ObjectRef& a, const ObjectRef& b) const { return a.same_as(b); }
636 
637  template <typename T>
638  size_t operator()(const ObjectPtr<T>& a, const ObjectPtr<T>& b) const {
639  return a == b;
640  }
641 };
642 
648 #define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \
649  static_assert(!ParentType::_type_final, "ParentObj marked as final"); \
650  static uint32_t RuntimeTypeIndex() { \
651  static_assert(TypeName::_type_child_slots == 0 || ParentType::_type_child_slots == 0 || \
652  TypeName::_type_child_slots < ParentType::_type_child_slots, \
653  "Need to set _type_child_slots when parent specifies it."); \
654  if (TypeName::_type_index != ::tvm::runtime::TypeIndex::kDynamic) { \
655  return TypeName::_type_index; \
656  } \
657  return _GetOrAllocRuntimeTypeIndex(); \
658  } \
659  static uint32_t _GetOrAllocRuntimeTypeIndex() { \
660  static uint32_t tindex = Object::GetOrAllocRuntimeTypeIndex( \
661  TypeName::_type_key, TypeName::_type_index, ParentType::_GetOrAllocRuntimeTypeIndex(), \
662  TypeName::_type_child_slots, TypeName::_type_child_slots_can_overflow); \
663  return tindex; \
664  }
665 
671 #define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType) \
672  static const constexpr bool _type_final = true; \
673  static const constexpr int _type_child_slots = 0; \
674  TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
675 
677 #if defined(__GNUC__)
678 #define TVM_ATTRIBUTE_UNUSED __attribute__((unused))
679 #else
680 #define TVM_ATTRIBUTE_UNUSED
681 #endif
682 
683 #define TVM_STR_CONCAT_(__x, __y) __x##__y
684 #define TVM_STR_CONCAT(__x, __y) TVM_STR_CONCAT_(__x, __y)
685 
686 #define TVM_OBJECT_REG_VAR_DEF static TVM_ATTRIBUTE_UNUSED uint32_t __make_Object_tid
687 
694 #define TVM_REGISTER_OBJECT_TYPE(TypeName) \
695  TVM_STR_CONCAT(TVM_OBJECT_REG_VAR_DEF, __COUNTER__) = TypeName::_GetOrAllocRuntimeTypeIndex()
696 
697 /*
698  * \brief Define the default copy/move constructor and assign operator
699  * \param TypeName The class typename.
700  */
701 #define TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName) \
702  TypeName(const TypeName& other) = default; \
703  TypeName(TypeName&& other) = default; \
704  TypeName& operator=(const TypeName& other) = default; \
705  TypeName& operator=(TypeName&& other) = default;
706 
707 /*
708  * \brief Define object reference methods.
709  * \param TypeName The object type name
710  * \param ParentType The parent type of the objectref
711  * \param ObjectName The type name of the object.
712  */
713 #define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
714  TypeName() = default; \
715  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
716  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
717  const ObjectName* operator->() const { return static_cast<const ObjectName*>(data_.get()); } \
718  const ObjectName* get() const { return operator->(); } \
719  using ContainerType = ObjectName;
720 
721 /*
722  * \brief Define object reference methods that is not nullable.
723  *
724  * \param TypeName The object type name
725  * \param ParentType The parent type of the objectref
726  * \param ObjectName The type name of the object.
727  */
728 #define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
729  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
730  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
731  const ObjectName* operator->() const { return static_cast<const ObjectName*>(data_.get()); } \
732  const ObjectName* get() const { return operator->(); } \
733  static constexpr bool _type_is_nullable = false; \
734  using ContainerType = ObjectName;
735 
736 /*
737  * \brief Define object reference methods of whose content is mutable.
738  * \param TypeName The object type name
739  * \param ParentType The parent type of the objectref
740  * \param ObjectName The type name of the object.
741  * \note We recommend making objects immutable when possible.
742  * This macro is only reserved for objects that stores runtime states.
743  */
744 #define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
745  TypeName() = default; \
746  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
747  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
748  ObjectName* operator->() const { return static_cast<ObjectName*>(data_.get()); } \
749  using ContainerType = ObjectName;
750 
751 /*
752  * \brief Define object reference methods that is both not nullable and mutable.
753  *
754  * \param TypeName The object type name
755  * \param ParentType The parent type of the objectref
756  * \param ObjectName The type name of the object.
757  */
758 #define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
759  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
760  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
761  ObjectName* operator->() const { return static_cast<ObjectName*>(data_.get()); } \
762  ObjectName* get() const { return operator->(); } \
763  static constexpr bool _type_is_nullable = false; \
764  using ContainerType = ObjectName;
765 
785 #define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName) \
786  ObjectName* CopyOnWrite() { \
787  ICHECK(data_ != nullptr); \
788  if (!data_.unique()) { \
789  auto n = make_object<ObjectName>(*(operator->())); \
790  ObjectPtr<Object>(std::move(n)).swap(data_); \
791  } \
792  return static_cast<ObjectName*>(data_.get()); \
793  }
794 
795 // Implementations details below
796 // Object reference counting.
797 #if TVM_OBJECT_ATOMIC_REF_COUNTER
798 
799 inline void Object::IncRef() { ref_counter_.fetch_add(1, std::memory_order_relaxed); }
800 
801 inline void Object::DecRef() {
802  if (ref_counter_.fetch_sub(1, std::memory_order_release) == 1) {
803  std::atomic_thread_fence(std::memory_order_acquire);
804  if (this->deleter_ != nullptr) {
805  (*this->deleter_)(this);
806  }
807  }
808 }
809 
810 inline int Object::use_count() const { return ref_counter_.load(std::memory_order_relaxed); }
811 
812 #else
813 
814 inline void Object::IncRef() { ++ref_counter_; }
815 
816 inline void Object::DecRef() {
817  if (--ref_counter_ == 0) {
818  if (this->deleter_ != nullptr) {
819  (*this->deleter_)(this);
820  }
821  }
822 }
823 
824 inline int Object::use_count() const { return ref_counter_; }
825 
826 #endif // TVM_OBJECT_ATOMIC_REF_COUNTER
827 
828 template <typename TargetType>
829 inline bool Object::IsInstance() const {
830  const Object* self = this;
831  // NOTE: the following code can be optimized by
832  // compiler dead-code elimination for already known constants.
833  if (self != nullptr) {
834  // Everything is a subclass of object.
835  if (std::is_same<TargetType, Object>::value) return true;
836  if (TargetType::_type_final) {
837  // if the target type is a final type
838  // then we only need to check the equivalence.
839  return self->type_index_ == TargetType::RuntimeTypeIndex();
840  } else {
841  // if target type is a non-leaf type
842  // Check if type index falls into the range of reserved slots.
843  uint32_t begin = TargetType::RuntimeTypeIndex();
844  // The condition will be optimized by constant-folding.
845  if (TargetType::_type_child_slots != 0) {
846  uint32_t end = begin + TargetType::_type_child_slots;
847  if (self->type_index_ >= begin && self->type_index_ < end) return true;
848  } else {
849  if (self->type_index_ == begin) return true;
850  }
851  if (!TargetType::_type_child_slots_can_overflow) return false;
852  // Invariance: parent index is always smaller than the child.
853  if (self->type_index_ < TargetType::RuntimeTypeIndex()) return false;
854  // The rare slower-path, check type hierarchy.
855  return self->DerivedFrom(TargetType::RuntimeTypeIndex());
856  }
857  } else {
858  return false;
859  }
860 }
861 
862 inline bool Object::unique() const { return use_count() == 1; }
863 
864 template <typename ObjectType>
865 inline const ObjectType* ObjectRef::as() const {
866  if (data_ != nullptr && data_->IsInstance<ObjectType>()) {
867  return static_cast<ObjectType*>(data_.get());
868  } else {
869  return nullptr;
870  }
871 }
872 
873 template <typename RefType, typename ObjType>
874 inline RefType GetRef(const ObjType* ptr) {
875  static_assert(std::is_base_of<typename RefType::ContainerType, ObjType>::value,
876  "Can only cast to the ref of same container type");
877  if (!RefType::_type_is_nullable) {
878  ICHECK(ptr != nullptr);
879  }
880  return RefType(ObjectPtr<Object>(const_cast<Object*>(static_cast<const Object*>(ptr))));
881 }
882 
883 template <typename BaseType, typename ObjType>
884 inline ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr) {
885  static_assert(std::is_base_of<BaseType, ObjType>::value,
886  "Can only cast to the ref of same container type");
887  return ObjectPtr<BaseType>(static_cast<Object*>(ptr));
888 }
889 
890 template <typename SubRef, typename BaseRef>
891 inline SubRef Downcast(BaseRef ref) {
892  if (ref.defined()) {
893  ICHECK(ref->template IsInstance<typename SubRef::ContainerType>())
894  << "Downcast from " << ref->GetTypeKey() << " to " << SubRef::ContainerType::_type_key
895  << " failed.";
896  } else {
897  ICHECK(SubRef::_type_is_nullable) << "Downcast from nullptr to not nullable reference of "
898  << SubRef::ContainerType::_type_key;
899  }
900  return SubRef(std::move(ref.data_));
901 }
902 
903 } // namespace runtime
904 } // namespace tvm
905 
906 #endif // TVM_RUNTIME_OBJECT_H_
runtime::Map.
Definition: object.h:70
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:799
Object(const Object &other)
Definition: object.h:247
A custom smart pointer for Object.
Definition: object.h:358
runtime::Module.
Definition: object.h:62
ObjectRef equal functor.
Definition: object.h:634
Internal base class to handle conversion to POD values.
Definition: packed_func.h:541
SubRef Downcast(BaseRef ref)
Downcast a base reference type to a more specific type.
Definition: object.h:891
bool operator!=(std::nullptr_t null) const
Definition: object.h:466
void reset()
reset the content of ptr to be nullptr
Definition: object.h:449
size_t operator()(const ObjectRef &a) const
Definition: object.h:625
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
runtime::String.
Definition: object.h:66
Object()
Definition: object.h:241
bool operator==(const ObjectRef &other) const
Comparator.
Definition: object.h:528
void IncRef()
developer function, increases reference counter.
Definition: object.h:799
size_t GetTypeKeyHash() const
Definition: object.h:184
bool operator!=(const ObjectRef &other) const
Comparator.
Definition: object.h:534
static ObjectPtr< ObjectType > GetDataPtr(const ObjectRef &ref)
Internal helper function get data_ as ObjectPtr of ObjectType.
Definition: object.h:600
base class of all object containers.
Definition: object.h:167
RelayRefType GetRef(const ObjectType *ptr)
Get a reference type from a raw object ptr type.
static void FFIClearAfterMove(ObjectRef *ref)
Clear the object ref data field without DecRef after we successfully moved the field.
Definition: object.h:592
Namespace for the list of type index.
Definition: object.h:55
void DecRef()
developer function, decrease reference counter.
Definition: object.h:801
bool IsInstance() const
Definition: object.h:829
static uint32_t RuntimeTypeIndex()
Definition: object.h:225
bool operator<(const ObjectRef &other) const
Comparator.
Definition: object.h:540
Internal auxiliary struct for TypedPackedFunc to indicate a movable argument.
Definition: packed_func.h:709
ObjectPtr< BaseType > GetObjectPtr(ObjectType *ptr)
Get an object ptr type from a raw object ptr.
bool defined() const
Definition: object.h:544
Object(Object &&other)
Definition: object.h:249
bool operator()(const ObjectRef &a, const ObjectRef &b) const
Definition: object.h:635
ObjectRef hash functor.
Definition: object.h:624
runtime::PackedFunc.
Definition: object.h:74
std::atomic< int32_t > RefCounterType
Definition: object.h:217
bool unique() const
Definition: object.h:862
T & operator*() const
Definition: object.h:419
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:574
const Object * operator->() const
Definition: object.h:548
T * operator->() const
Definition: object.h:415
bool same_as(const ObjectRef &other) const
Comparator.
Definition: object.h:522
static T DowncastNoCheck(ObjectRef ref)
Internal helper function downcast a ref without check.
Definition: object.h:584
ObjectPtr< T > & operator=(ObjectPtr< T > &&other)
move assignment
Definition: object.h:438
bool unique() const
Definition: object.h:550
ObjectPtr(std::nullptr_t)
default constructor
Definition: object.h:363
Object & operator=(const Object &other)
Definition: object.h:251
runtime::ShapeTuple.
Definition: object.h:72
static uint32_t _GetOrAllocRuntimeTypeIndex()
Definition: object.h:224
bool operator==(std::nullptr_t null) const
Definition: object.h:464
ObjectRef(ObjectPtr< Object > data)
Constructor from existing object ptr.
Definition: object.h:516
Base class of all object reference.
Definition: object.h:511
Base class of object allocators that implements make. Use curiously recurring template pattern...
Definition: memory.h:60
std::string GetTypeKey() const
Definition: object.h:180
Root object type.
Definition: object.h:58
T * get() const
Definition: object.h:411
ObjectPtr(const ObjectPtr< T > &other)
copy constructor
Definition: object.h:368
size_t operator()(const ObjectPtr< T > &a) const
Definition: object.h:628
uint32_t type_index() const
Definition: object.h:175
bool unique() const
Definition: object.h:458
runtime::Array.
Definition: object.h:68
void swap(ObjectPtr< T > &other)
Swap this array with another Object.
Definition: object.h:405
size_t operator()(const ObjectPtr< T > &a, const ObjectPtr< T > &b) const
Definition: object.h:638
A single argument value to PackedFunc. Containing both type_code and TVMValue.
Definition: packed_func.h:646
int use_count() const
Definition: object.h:456
ObjectPtr()
default constructor
Definition: object.h:361
ObjectPtr(ObjectPtr< Y > &&other)
move constructor
Definition: object.h:393
~ObjectPtr()
destructor
Definition: object.h:400
Definition: packed_func.h:1517
uint32_t type_index_
Type index(tag) that indicates the type of the object.
Definition: object.h:261
int use_count() const
Definition: object.h:552
Object & operator=(Object &&other)
Definition: object.h:254
bool operator!=(const ObjectPtr< T > &other) const
Definition: object.h:462
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:865
bool operator==(const ObjectPtr< T > &other) const
Definition: object.h:460
Object * get_mutable() const
Definition: object.h:576
Managed reference to RelayRefTypeNode.
Definition: type.h:576
ObjectPtr(ObjectPtr< T > &&other)
move constructor
Definition: object.h:384
ObjectPtr(const ObjectPtr< U > &other)
copy constructor
Definition: object.h:375
Type index is allocated during runtime.
Definition: object.h:80
ObjectPtr< T > & operator=(const ObjectPtr< T > &other)
copy assignment
Definition: object.h:427
runtime::NDArray.
Definition: object.h:64