tvm
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.
73  // static assignments that may subject to change.
79  };
80 }; // namespace TypeIndex
81 
165 class TVM_DLL Object {
166  public:
171  typedef void (*FDeleter)(Object* self);
173  uint32_t type_index() const { return type_index_; }
178  std::string GetTypeKey() const { return TypeIndex2Key(type_index_); }
182  size_t GetTypeKeyHash() const { return TypeIndex2KeyHash(type_index_); }
188  template <typename TargetType>
189  inline bool IsInstance() const;
194  inline bool unique() const;
200  static std::string TypeIndex2Key(uint32_t tindex);
206  static size_t TypeIndex2KeyHash(uint32_t tindex);
212  static uint32_t TypeKey2Index(const std::string& key);
213 
214 #if TVM_OBJECT_ATOMIC_REF_COUNTER
215  using RefCounterType = std::atomic<int32_t>;
216 #else
217  using RefCounterType = int32_t;
218 #endif
219 
220  static constexpr const char* _type_key = "runtime.Object";
221 
222  static uint32_t _GetOrAllocRuntimeTypeIndex() { return TypeIndex::kRoot; }
223  static uint32_t RuntimeTypeIndex() { return TypeIndex::kRoot; }
224 
225  // Default object type properties for sub-classes
226  static constexpr bool _type_final = false;
227  static constexpr uint32_t _type_child_slots = 0;
228  static constexpr bool _type_child_slots_can_overflow = true;
229  // member information
230  static constexpr bool _type_has_method_visit_attrs = true;
231  static constexpr bool _type_has_method_sequal_reduce = false;
232  static constexpr bool _type_has_method_shash_reduce = false;
233  // NOTE: the following field is not type index of Object
234  // but was intended to be used by sub-classes as default value.
235  // The type index of Object is TypeIndex::kRoot
236  static constexpr uint32_t _type_index = TypeIndex::kDynamic;
237 
238  // Default constructor and copy constructor
239  Object() {}
240  // Override the copy and assign constructors to do nothing.
241  // This is to make sure only contents, but not deleter and ref_counter
242  // are copied when a child class copies itself.
243  // This will enable us to use make_object<ObjectClass>(*obj_ptr)
244  // to copy an existing object.
245  Object(const Object& other) { // NOLINT(*)
246  }
247  Object(Object&& other) { // NOLINT(*)
248  }
249  Object& operator=(const Object& other) { // NOLINT(*)
250  return *this;
251  }
252  Object& operator=(Object&& other) { // NOLINT(*)
253  return *this;
254  }
255 
256  protected:
257  // The fields of the base object cell.
259  uint32_t type_index_{0};
261  RefCounterType ref_counter_{0};
267  FDeleter deleter_ = nullptr;
268  // Invariant checks.
269  static_assert(sizeof(int32_t) == sizeof(RefCounterType) &&
270  alignof(int32_t) == sizeof(RefCounterType),
271  "RefCounter ABI check.");
272 
290  static uint32_t GetOrAllocRuntimeTypeIndex(const std::string& key, uint32_t static_tindex,
291  uint32_t parent_tindex, uint32_t type_child_slots,
292  bool type_child_slots_can_overflow);
293 
294  // reference counter related operations
296  inline void IncRef();
301  inline void DecRef();
302 
303  private:
308  inline int use_count() const;
314  bool DerivedFrom(uint32_t parent_tindex) const;
315  // friend classes
316  template <typename>
317  friend class ObjAllocatorBase;
318  template <typename>
319  friend class ObjectPtr;
320  friend class TVMRetValue;
321  friend class ObjectInternal;
322 };
323 
336 template <typename RelayRefType, typename ObjectType>
337 inline RelayRefType GetRef(const ObjectType* ptr);
338 
347 template <typename SubRef, typename BaseRef>
348 inline SubRef Downcast(BaseRef ref);
349 
355 template <typename T>
356 class ObjectPtr {
357  public:
361  ObjectPtr(std::nullptr_t) {} // NOLINT(*)
366  ObjectPtr(const ObjectPtr<T>& other) // NOLINT(*)
367  : ObjectPtr(other.data_) {}
372  template <typename U>
373  ObjectPtr(const ObjectPtr<U>& other) // NOLINT(*)
374  : ObjectPtr(other.data_) {
375  static_assert(std::is_base_of<T, U>::value,
376  "can only assign of child class ObjectPtr to parent");
377  }
382  ObjectPtr(ObjectPtr<T>&& other) // NOLINT(*)
383  : data_(other.data_) {
384  other.data_ = nullptr;
385  }
390  template <typename Y>
391  ObjectPtr(ObjectPtr<Y>&& other) // NOLINT(*)
392  : data_(other.data_) {
393  static_assert(std::is_base_of<T, Y>::value,
394  "can only assign of child class ObjectPtr to parent");
395  other.data_ = nullptr;
396  }
398  ~ObjectPtr() { this->reset(); }
403  void swap(ObjectPtr<T>& other) { // NOLINT(*)
404  std::swap(data_, other.data_);
405  }
409  T* get() const { return static_cast<T*>(data_); }
413  T* operator->() const { return get(); }
417  T& operator*() const { // NOLINT(*)
418  return *get();
419  }
425  ObjectPtr<T>& operator=(const ObjectPtr<T>& other) { // NOLINT(*)
426  // takes in plane operator to enable copy elison.
427  // copy-and-swap idiom
428  ObjectPtr(other).swap(*this); // NOLINT(*)
429  return *this;
430  }
436  ObjectPtr<T>& operator=(ObjectPtr<T>&& other) { // NOLINT(*)
437  // copy-and-swap idiom
438  ObjectPtr(std::move(other)).swap(*this); // NOLINT(*)
439  return *this;
440  }
442  void reset() {
443  if (data_ != nullptr) {
444  data_->DecRef();
445  data_ = nullptr;
446  }
447  }
449  int use_count() const { return data_ != nullptr ? data_->use_count() : 0; }
451  bool unique() const { return data_ != nullptr && data_->use_count() == 1; }
453  bool operator==(const ObjectPtr<T>& other) const { return data_ == other.data_; }
455  bool operator!=(const ObjectPtr<T>& other) const { return data_ != other.data_; }
457  bool operator==(std::nullptr_t null) const { return data_ == nullptr; }
459  bool operator!=(std::nullptr_t null) const { return data_ != nullptr; }
460 
461  private:
463  Object* data_{nullptr};
468  explicit ObjectPtr(Object* data) : data_(data) {
469  if (data != nullptr) {
470  data_->IncRef();
471  }
472  }
478  static ObjectPtr<T> MoveFromRValueRefArg(Object** ref) {
479  ObjectPtr<T> ptr;
480  ptr.data_ = *ref;
481  *ref = nullptr;
482  return ptr;
483  }
484  // friend classes
485  friend class Object;
486  friend class ObjectRef;
487  friend struct ObjectPtrHash;
488  template <typename>
489  friend class ObjectPtr;
490  template <typename>
491  friend class ObjAllocatorBase;
492  friend class TVMPODValue_;
493  friend class TVMArgsSetter;
494  friend class TVMRetValue;
495  friend class TVMArgValue;
496  friend class TVMMovableArgValue_;
497  template <typename RelayRefType, typename ObjType>
498  friend RelayRefType GetRef(const ObjType* ptr);
499  template <typename BaseType, typename ObjType>
500  friend ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr);
501 };
502 
504 class ObjectRef {
505  public:
507  ObjectRef() = default;
509  explicit ObjectRef(ObjectPtr<Object> data) : data_(data) {}
515  bool same_as(const ObjectRef& other) const { return data_ == other.data_; }
521  bool operator==(const ObjectRef& other) const { return data_ == other.data_; }
527  bool operator!=(const ObjectRef& other) const { return data_ != other.data_; }
533  bool operator<(const ObjectRef& other) const { return data_.get() < other.data_.get(); }
537  bool defined() const { return data_ != nullptr; }
539  const Object* get() const { return data_.get(); }
541  const Object* operator->() const { return get(); }
543  bool unique() const { return data_.unique(); }
545  int use_count() const { return data_.use_count(); }
557  template <typename ObjectType>
558  inline const ObjectType* as() const;
559 
562  // Default type properties for the reference class.
563  static constexpr bool _type_is_nullable = true;
564 
565  protected:
569  Object* get_mutable() const { return data_.get(); }
576  template <typename T>
577  static T DowncastNoCheck(ObjectRef ref) {
578  return T(std::move(ref.data_));
579  }
585  static void FFIClearAfterMove(ObjectRef* ref) { ref->data_.data_ = nullptr; }
592  template <typename ObjectType>
594  return ObjectPtr<ObjectType>(ref.data_.data_);
595  }
596  // friend classes.
597  friend struct ObjectPtrHash;
598  friend class TVMRetValue;
599  friend class TVMArgsSetter;
600  friend class ObjectInternal;
601  template <typename SubRef, typename BaseRef>
602  friend SubRef Downcast(BaseRef ref);
603 };
604 
613 template <typename BaseType, typename ObjectType>
614 inline ObjectPtr<BaseType> GetObjectPtr(ObjectType* ptr);
615 
618  size_t operator()(const ObjectRef& a) const { return operator()(a.data_); }
619 
620  template <typename T>
621  size_t operator()(const ObjectPtr<T>& a) const {
622  return std::hash<Object*>()(a.get());
623  }
624 };
625 
628  bool operator()(const ObjectRef& a, const ObjectRef& b) const { return a.same_as(b); }
629 
630  template <typename T>
631  size_t operator()(const ObjectPtr<T>& a, const ObjectPtr<T>& b) const {
632  return a == b;
633  }
634 };
635 
641 #define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \
642  static_assert(!ParentType::_type_final, "ParentObj marked as final"); \
643  static uint32_t RuntimeTypeIndex() { \
644  static_assert(TypeName::_type_child_slots == 0 || ParentType::_type_child_slots == 0 || \
645  TypeName::_type_child_slots < ParentType::_type_child_slots, \
646  "Need to set _type_child_slots when parent specifies it."); \
647  if (TypeName::_type_index != ::tvm::runtime::TypeIndex::kDynamic) { \
648  return TypeName::_type_index; \
649  } \
650  return _GetOrAllocRuntimeTypeIndex(); \
651  } \
652  static uint32_t _GetOrAllocRuntimeTypeIndex() { \
653  static uint32_t tindex = Object::GetOrAllocRuntimeTypeIndex( \
654  TypeName::_type_key, TypeName::_type_index, ParentType::_GetOrAllocRuntimeTypeIndex(), \
655  TypeName::_type_child_slots, TypeName::_type_child_slots_can_overflow); \
656  return tindex; \
657  }
658 
664 #define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType) \
665  static const constexpr bool _type_final = true; \
666  static const constexpr int _type_child_slots = 0; \
667  TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
668 
670 #if defined(__GNUC__)
671 #define TVM_ATTRIBUTE_UNUSED __attribute__((unused))
672 #else
673 #define TVM_ATTRIBUTE_UNUSED
674 #endif
675 
676 #define TVM_STR_CONCAT_(__x, __y) __x##__y
677 #define TVM_STR_CONCAT(__x, __y) TVM_STR_CONCAT_(__x, __y)
678 
679 #define TVM_OBJECT_REG_VAR_DEF static TVM_ATTRIBUTE_UNUSED uint32_t __make_Object_tid
680 
687 #define TVM_REGISTER_OBJECT_TYPE(TypeName) \
688  TVM_STR_CONCAT(TVM_OBJECT_REG_VAR_DEF, __COUNTER__) = TypeName::_GetOrAllocRuntimeTypeIndex()
689 
690 /*
691  * \brief Define the default copy/move constructor and assign operator
692  * \param TypeName The class typename.
693  */
694 #define TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName) \
695  TypeName(const TypeName& other) = default; \
696  TypeName(TypeName&& other) = default; \
697  TypeName& operator=(const TypeName& other) = default; \
698  TypeName& operator=(TypeName&& other) = default;
699 
700 /*
701  * \brief Define object reference methods.
702  * \param TypeName The object type name
703  * \param ParentType The parent type of the objectref
704  * \param ObjectName The type name of the object.
705  */
706 #define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
707  TypeName() = default; \
708  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
709  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
710  const ObjectName* operator->() const { return static_cast<const ObjectName*>(data_.get()); } \
711  const ObjectName* get() const { return operator->(); } \
712  using ContainerType = ObjectName;
713 
714 /*
715  * \brief Define object reference methods that is not nullable.
716  *
717  * \param TypeName The object type name
718  * \param ParentType The parent type of the objectref
719  * \param ObjectName The type name of the object.
720  */
721 #define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
722  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
723  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
724  const ObjectName* operator->() const { return static_cast<const ObjectName*>(data_.get()); } \
725  const ObjectName* get() const { return operator->(); } \
726  static constexpr bool _type_is_nullable = false; \
727  using ContainerType = ObjectName;
728 
729 /*
730  * \brief Define object reference methods of whose content is mutable.
731  * \param TypeName The object type name
732  * \param ParentType The parent type of the objectref
733  * \param ObjectName The type name of the object.
734  * \note We recommend making objects immutable when possible.
735  * This macro is only reserved for objects that stores runtime states.
736  */
737 #define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
738  TypeName() = default; \
739  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
740  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
741  ObjectName* operator->() const { return static_cast<ObjectName*>(data_.get()); } \
742  using ContainerType = ObjectName;
743 
744 /*
745  * \brief Define object reference methods that is both not nullable and mutable.
746  *
747  * \param TypeName The object type name
748  * \param ParentType The parent type of the objectref
749  * \param ObjectName The type name of the object.
750  */
751 #define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
752  explicit TypeName(::tvm::runtime::ObjectPtr<::tvm::runtime::Object> n) : ParentType(n) {} \
753  TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
754  ObjectName* operator->() const { return static_cast<ObjectName*>(data_.get()); } \
755  ObjectName* get() const { return operator->(); } \
756  static constexpr bool _type_is_nullable = false; \
757  using ContainerType = ObjectName;
758 
778 #define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName) \
779  ObjectName* CopyOnWrite() { \
780  ICHECK(data_ != nullptr); \
781  if (!data_.unique()) { \
782  auto n = make_object<ObjectName>(*(operator->())); \
783  ObjectPtr<Object>(std::move(n)).swap(data_); \
784  } \
785  return static_cast<ObjectName*>(data_.get()); \
786  }
787 
788 // Implementations details below
789 // Object reference counting.
790 #if TVM_OBJECT_ATOMIC_REF_COUNTER
791 
792 inline void Object::IncRef() { ref_counter_.fetch_add(1, std::memory_order_relaxed); }
793 
794 inline void Object::DecRef() {
795  if (ref_counter_.fetch_sub(1, std::memory_order_release) == 1) {
796  std::atomic_thread_fence(std::memory_order_acquire);
797  if (this->deleter_ != nullptr) {
798  (*this->deleter_)(this);
799  }
800  }
801 }
802 
803 inline int Object::use_count() const { return ref_counter_.load(std::memory_order_relaxed); }
804 
805 #else
806 
807 inline void Object::IncRef() { ++ref_counter_; }
808 
809 inline void Object::DecRef() {
810  if (--ref_counter_ == 0) {
811  if (this->deleter_ != nullptr) {
812  (*this->deleter_)(this);
813  }
814  }
815 }
816 
817 inline int Object::use_count() const { return ref_counter_; }
818 
819 #endif // TVM_OBJECT_ATOMIC_REF_COUNTER
820 
821 template <typename TargetType>
822 inline bool Object::IsInstance() const {
823  const Object* self = this;
824  // NOTE: the following code can be optimized by
825  // compiler dead-code elimination for already known constants.
826  if (self != nullptr) {
827  // Everything is a subclass of object.
828  if (std::is_same<TargetType, Object>::value) return true;
829  if (TargetType::_type_final) {
830  // if the target type is a final type
831  // then we only need to check the equivalence.
832  return self->type_index_ == TargetType::RuntimeTypeIndex();
833  } else {
834  // if target type is a non-leaf type
835  // Check if type index falls into the range of reserved slots.
836  uint32_t begin = TargetType::RuntimeTypeIndex();
837  // The condition will be optimized by constant-folding.
838  if (TargetType::_type_child_slots != 0) {
839  uint32_t end = begin + TargetType::_type_child_slots;
840  if (self->type_index_ >= begin && self->type_index_ < end) return true;
841  } else {
842  if (self->type_index_ == begin) return true;
843  }
844  if (!TargetType::_type_child_slots_can_overflow) return false;
845  // Invariance: parent index is always smaller than the child.
846  if (self->type_index_ < TargetType::RuntimeTypeIndex()) return false;
847  // The rare slower-path, check type hierarchy.
848  return self->DerivedFrom(TargetType::RuntimeTypeIndex());
849  }
850  } else {
851  return false;
852  }
853 }
854 
855 inline bool Object::unique() const { return use_count() == 1; }
856 
857 template <typename ObjectType>
858 inline const ObjectType* ObjectRef::as() const {
859  if (data_ != nullptr && data_->IsInstance<ObjectType>()) {
860  return static_cast<ObjectType*>(data_.get());
861  } else {
862  return nullptr;
863  }
864 }
865 
866 template <typename RefType, typename ObjType>
867 inline RefType GetRef(const ObjType* ptr) {
868  static_assert(std::is_base_of<typename RefType::ContainerType, ObjType>::value,
869  "Can only cast to the ref of same container type");
870  if (!RefType::_type_is_nullable) {
871  ICHECK(ptr != nullptr);
872  }
873  return RefType(ObjectPtr<Object>(const_cast<Object*>(static_cast<const Object*>(ptr))));
874 }
875 
876 template <typename BaseType, typename ObjType>
877 inline ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr) {
878  static_assert(std::is_base_of<BaseType, ObjType>::value,
879  "Can only cast to the ref of same container type");
880  return ObjectPtr<BaseType>(static_cast<Object*>(ptr));
881 }
882 
883 template <typename SubRef, typename BaseRef>
884 inline SubRef Downcast(BaseRef ref) {
885  if (ref.defined()) {
886  ICHECK(ref->template IsInstance<typename SubRef::ContainerType>())
887  << "Downcast from " << ref->GetTypeKey() << " to " << SubRef::ContainerType::_type_key
888  << " failed.";
889  } else {
890  ICHECK(SubRef::_type_is_nullable) << "Downcast from nullptr to not nullable reference of "
891  << SubRef::ContainerType::_type_key;
892  }
893  return SubRef(std::move(ref.data_));
894 }
895 
896 } // namespace runtime
897 } // namespace tvm
898 
899 #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:734
Object(const Object &other)
Definition: object.h:245
A custom smart pointer for Object.
Definition: object.h:356
runtime::Module.
Definition: object.h:62
ObjectRef equal functor.
Definition: object.h:627
Internal base class to handle conversion to POD values.
Definition: packed_func.h:485
SubRef Downcast(BaseRef ref)
Downcast a base reference type to a more specific type.
Definition: object.h:884
bool operator!=(std::nullptr_t null) const
Definition: object.h:459
void reset()
reset the content of ptr to be nullptr
Definition: object.h:442
size_t operator()(const ObjectRef &a) const
Definition: object.h:618
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
runtime::String.
Definition: object.h:66
Object()
Definition: object.h:239
bool operator==(const ObjectRef &other) const
Comparator.
Definition: object.h:521
void IncRef()
developer function, increases reference counter.
Definition: object.h:792
size_t GetTypeKeyHash() const
Definition: object.h:182
bool operator!=(const ObjectRef &other) const
Comparator.
Definition: object.h:527
static ObjectPtr< ObjectType > GetDataPtr(const ObjectRef &ref)
Internal helper function get data_ as ObjectPtr of ObjectType.
Definition: object.h:593
base class of all object containers.
Definition: object.h:165
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:585
Namespace for the list of type index.
Definition: object.h:55
void DecRef()
developer function, decrease reference counter.
Definition: object.h:794
bool IsInstance() const
Definition: object.h:822
static uint32_t RuntimeTypeIndex()
Definition: object.h:223
bool operator<(const ObjectRef &other) const
Comparator.
Definition: object.h:533
Internal auxiliary struct for TypedPackedFunc to indicate a movable argument.
Definition: packed_func.h:650
ObjectPtr< BaseType > GetObjectPtr(ObjectType *ptr)
Get an object ptr type from a raw object ptr.
bool defined() const
Definition: object.h:537
Object(Object &&other)
Definition: object.h:247
bool operator()(const ObjectRef &a, const ObjectRef &b) const
Definition: object.h:628
ObjectRef hash functor.
Definition: object.h:617
std::atomic< int32_t > RefCounterType
Definition: object.h:215
bool unique() const
Definition: object.h:855
T & operator*() const
Definition: object.h:417
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:567
const Object * operator->() const
Definition: object.h:541
T * operator->() const
Definition: object.h:413
bool same_as(const ObjectRef &other) const
Comparator.
Definition: object.h:515
static T DowncastNoCheck(ObjectRef ref)
Internal helper function downcast a ref without check.
Definition: object.h:577
ObjectPtr< T > & operator=(ObjectPtr< T > &&other)
move assignment
Definition: object.h:436
bool unique() const
Definition: object.h:543
ObjectPtr(std::nullptr_t)
default constructor
Definition: object.h:361
Object & operator=(const Object &other)
Definition: object.h:249
runtime::ShapeTuple.
Definition: object.h:72
static uint32_t _GetOrAllocRuntimeTypeIndex()
Definition: object.h:222
bool operator==(std::nullptr_t null) const
Definition: object.h:457
ObjectRef(ObjectPtr< Object > data)
Constructor from existing object ptr.
Definition: object.h:509
Base class of all object reference.
Definition: object.h:504
Base class of object allocators that implements make. Use curiously recurring template pattern...
Definition: memory.h:60
std::string GetTypeKey() const
Definition: object.h:178
Root object type.
Definition: object.h:58
T * get() const
Definition: object.h:409
ObjectPtr(const ObjectPtr< T > &other)
copy constructor
Definition: object.h:366
size_t operator()(const ObjectPtr< T > &a) const
Definition: object.h:621
uint32_t type_index() const
Definition: object.h:173
bool unique() const
Definition: object.h:451
runtime::Array.
Definition: object.h:68
void swap(ObjectPtr< T > &other)
Swap this array with another Object.
Definition: object.h:403
size_t operator()(const ObjectPtr< T > &a, const ObjectPtr< T > &b) const
Definition: object.h:631
A single argument value to PackedFunc. Containing both type_code and TVMValue.
Definition: packed_func.h:583
int use_count() const
Definition: object.h:449
ObjectPtr()
default constructor
Definition: object.h:359
ObjectPtr(ObjectPtr< Y > &&other)
move constructor
Definition: object.h:391
~ObjectPtr()
destructor
Definition: object.h:398
Definition: packed_func.h:1257
uint32_t type_index_
Type index(tag) that indicates the type of the object.
Definition: object.h:259
int use_count() const
Definition: object.h:545
Object & operator=(Object &&other)
Definition: object.h:252
bool operator!=(const ObjectPtr< T > &other) const
Definition: object.h:455
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:858
bool operator==(const ObjectPtr< T > &other) const
Definition: object.h:453
Object * get_mutable() const
Definition: object.h:569
Managed reference to RelayRefTypeNode.
Definition: type.h:557
ObjectPtr(ObjectPtr< T > &&other)
move constructor
Definition: object.h:382
ObjectPtr(const ObjectPtr< U > &other)
copy constructor
Definition: object.h:373
Type index is allocated during runtime.
Definition: object.h:78
ObjectPtr< T > & operator=(const ObjectPtr< T > &other)
copy assignment
Definition: object.h:425
runtime::NDArray.
Definition: object.h:64