mxnet
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 // Acknowledgement: This file originates from incubator-tvm
24 #ifndef MXNET_RUNTIME_OBJECT_H_
25 #define MXNET_RUNTIME_OBJECT_H_
26 
27 #include <dmlc/logging.h>
28 #include <type_traits>
29 #include <string>
30 #include <utility>
31 #include "c_runtime_api.h"
32 
39 #ifndef MXNET_OBJECT_ATOMIC_REF_COUNTER
40 #define MXNET_OBJECT_ATOMIC_REF_COUNTER 1
41 #endif
42 
43 #if MXNET_OBJECT_ATOMIC_REF_COUNTER
44 #include <atomic>
45 #endif // MXNET_OBJECT_ATOMIC_REF_COUNTER
46 
47 namespace mxnet {
48 namespace runtime {
49 
51 enum TypeIndex {
53  kRoot = 0,
56  kMXNetADT = 3,
57  kMXNetMap = 4,
59  kEllipsis = 6,
60  kSlice = 7,
61  kInteger = 8,
62  kFloat = 9,
66 };
67 
151 class Object {
152  public:
157  typedef void (*FDeleter)(Object* self);
159  uint32_t type_index() const {
160  return type_index_;
161  }
166  std::string GetTypeKey() const {
167  return TypeIndex2Key(type_index_);
168  }
172  size_t GetTypeKeyHash() const {
174  }
180  template <typename TargetType>
181  inline bool IsInstance() const;
182 
188  MXNET_DLL static std::string TypeIndex2Key(uint32_t tindex);
194  MXNET_DLL static size_t TypeIndex2KeyHash(uint32_t tindex);
200  MXNET_DLL static uint32_t TypeKey2Index(const std::string& key);
201 
202 #if MXNET_OBJECT_ATOMIC_REF_COUNTER
203  using RefCounterType = std::atomic<int32_t>;
204 #else
205  using RefCounterType = int32_t;
206 #endif
207 
208  static constexpr const char* _type_key = "Object";
209 
210  static uint32_t _GetOrAllocRuntimeTypeIndex() {
211  return TypeIndex::kRoot;
212  }
213  static uint32_t RuntimeTypeIndex() {
214  return TypeIndex::kRoot;
215  }
216 
217  // Default object type properties for sub-classes
218  static constexpr bool _type_final = false;
219  static constexpr uint32_t _type_child_slots = 0;
220  static constexpr bool _type_child_slots_can_overflow = true;
221  // NOTE: the following field is not type index of Object
222  // but was intended to be used by sub-classes as default value.
223  // The type index of Object is TypeIndex::kRoot
224  static constexpr uint32_t _type_index = TypeIndex::kDynamic;
225 
226  // Default constructor and copy constructor
227  Object() {}
228  // Override the copy and assign constructors to do nothing.
229  // This is to make sure only contents, but not deleter and ref_counter
230  // are copied when a child class copies itself.
231  // This will enable us to use make_object<ObjectClass>(*obj_ptr)
232  // to copy an existing object.
233  Object(const Object& other) { // NOLINT(*)
234  }
235  Object(Object&& other) { // NOLINT(*)
236  }
237  Object& operator=(const Object& other) { // NOLINT(*)
238  return *this;
239  }
240  Object& operator=(Object&& other) { // NOLINT(*)
241  return *this;
242  }
243 
244  protected:
245  // The fields of the base object cell.
247  uint32_t type_index_{0};
255  FDeleter deleter_ = nullptr;
256  // Invariant checks.
257  static_assert(sizeof(int32_t) == sizeof(RefCounterType) &&
258  alignof(int32_t) == sizeof(RefCounterType),
259  "RefCounter ABI check.");
260 
278  MXNET_DLL static uint32_t GetOrAllocRuntimeTypeIndex(const std::string& key,
279  uint32_t static_tindex,
280  uint32_t parent_tindex,
281  uint32_t type_child_slots,
282  bool type_child_slots_can_overflow);
283 
284  // reference counter related operations
286  inline void IncRef();
291  inline void DecRef();
292 
293  private:
298  inline int use_count() const;
304  MXNET_DLL bool DerivedFrom(uint32_t parent_tindex) const;
305  // friend classes
306  template <typename>
307  friend class ObjAllocatorBase;
308  template <typename>
309  friend class ObjectPtr;
310  friend class MXNetRetValue;
311  friend class ObjectInternal;
312 };
313 
326 template <typename RefType, typename ObjectType>
327 inline RefType GetRef(const ObjectType* ptr);
328 
337 template <typename SubRef, typename BaseRef>
338 inline SubRef Downcast(BaseRef ref);
339 
345 template <typename T>
346 class ObjectPtr {
347  public:
351  ObjectPtr(std::nullptr_t) {} // NOLINT(*)
356  ObjectPtr(const ObjectPtr<T>& other) // NOLINT(*)
357  : ObjectPtr(other.data_) {}
362  template <typename U>
363  ObjectPtr(const ObjectPtr<U>& other) // NOLINT(*)
364  : ObjectPtr(other.data_) {
365  static_assert(std::is_base_of<T, U>::value,
366  "can only assign of child class ObjectPtr to parent");
367  }
372  ObjectPtr(ObjectPtr<T>&& other) // NOLINT(*)
373  : data_(other.data_) {
374  other.data_ = nullptr;
375  }
380  template <typename Y>
381  ObjectPtr(ObjectPtr<Y>&& other) // NOLINT(*)
382  : data_(other.data_) {
383  static_assert(std::is_base_of<T, Y>::value,
384  "can only assign of child class ObjectPtr to parent");
385  other.data_ = nullptr;
386  }
389  this->reset();
390  }
395  void swap(ObjectPtr<T>& other) { // NOLINT(*)
396  std::swap(data_, other.data_);
397  }
401  T* get() const {
402  return static_cast<T*>(data_);
403  }
407  T* operator->() const {
408  return get();
409  }
413  T& operator*() const { // NOLINT(*)
414  return *get();
415  }
421  ObjectPtr<T>& operator=(const ObjectPtr<T>& other) { // NOLINT(*)
422  // takes in plane operator to enable copy elison.
423  // copy-and-swap idiom
424  ObjectPtr(other).swap(*this); // NOLINT(*)
425  return *this;
426  }
432  ObjectPtr<T>& operator=(ObjectPtr<T>&& other) { // NOLINT(*)
433  // copy-and-swap idiom
434  ObjectPtr(std::move(other)).swap(*this); // NOLINT(*)
435  return *this;
436  }
438  void reset() {
439  if (data_ != nullptr) {
440  data_->DecRef();
441  data_ = nullptr;
442  }
443  }
445  int use_count() const {
446  return data_ != nullptr ? data_->use_count() : 0;
447  }
449  bool unique() const {
450  return data_ != nullptr && data_->use_count() == 1;
451  }
453  bool operator==(const ObjectPtr<T>& other) const {
454  return data_ == other.data_;
455  }
457  bool operator!=(const ObjectPtr<T>& other) const {
458  return data_ != other.data_;
459  }
461  bool operator==(std::nullptr_t null) const {
462  return data_ == nullptr;
463  }
465  bool operator!=(std::nullptr_t null) const {
466  return data_ != nullptr;
467  }
468 
469  private:
471  Object* data_{nullptr};
476  explicit ObjectPtr(Object* data) : data_(data) {
477  if (data != nullptr) {
478  data_->IncRef();
479  }
480  }
481  // friend classes
482  friend class Object;
483  friend class ObjectRef;
484  friend struct ObjectHash;
485  template <typename>
486  friend class ObjectPtr;
487  template <typename>
488  friend class ObjAllocatorBase;
489  friend class MXNetPODValue_;
490  friend class MXNetArgsSetter;
491  friend class MXNetRetValue;
492  friend class MXNetArgValue;
493  template <typename RefType, typename ObjType>
494  friend RefType GetRef(const ObjType* ptr);
495  template <typename BaseType, typename ObjType>
496  friend ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr);
497 };
498 
500 class ObjectRef {
501  public:
503  ObjectRef() = default;
505  explicit ObjectRef(ObjectPtr<Object> data) : data_(data) {}
511  bool same_as(const ObjectRef& other) const {
512  return data_ == other.data_;
513  }
519  bool operator==(const ObjectRef& other) const {
520  return data_ == other.data_;
521  }
527  bool operator!=(const ObjectRef& other) const {
528  return data_ != other.data_;
529  }
535  bool operator<(const ObjectRef& other) const {
536  return data_.get() < other.data_.get();
537  }
539  bool defined() const {
540  return data_ != nullptr;
541  }
543  const Object* get() const {
544  return data_.get();
545  }
547  const Object* operator->() const {
548  return get();
549  }
551  bool unique() const {
552  return data_.unique();
553  }
565  template <typename ObjectType>
566  inline const ObjectType* as() const;
567 
570  // Default type properties for the reference class.
571  static constexpr bool _type_is_nullable = true;
572 
573  protected:
577  Object* get_mutable() const {
578  return data_.get();
579  }
586  template <typename T>
587  static T DowncastNoCheck(ObjectRef ref) {
588  return T(std::move(ref.data_));
589  }
596  template <typename ObjectType>
598  return ObjectPtr<ObjectType>(ref.data_.data_);
599  }
600  // friend classes.
601  friend struct ObjectHash;
602  friend class MXNetRetValue;
603  friend class MXNetArgsSetter;
604  template <typename SubRef, typename BaseRef>
605  friend SubRef Downcast(BaseRef ref);
606 };
607 
616 template <typename BaseType, typename ObjectType>
617 inline ObjectPtr<BaseType> GetObjectPtr(ObjectType* ptr);
618 
620 struct ObjectHash {
621  size_t operator()(const ObjectRef& a) const {
622  return operator()(a.data_);
623  }
624 
625  template <typename T>
626  size_t operator()(const ObjectPtr<T>& a) const {
627  return std::hash<Object*>()(a.get());
628  }
629 };
630 
632 struct ObjectEqual {
633  bool operator()(const ObjectRef& a, const ObjectRef& b) const {
634  return a.same_as(b);
635  }
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 MXNET_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \
649  static uint32_t RuntimeTypeIndex() { \
650  return TypeName::_type_index != ::mxnet::runtime::TypeIndex::kDynamic ? \
651  TypeName::_type_index : \
652  _GetOrAllocRuntimeTypeIndex(); \
653  } \
654  static uint32_t _GetOrAllocRuntimeTypeIndex() { \
655  static uint32_t tidx = GetOrAllocRuntimeTypeIndex(TypeName::_type_key, \
656  TypeName::_type_index, \
657  ParentType::_GetOrAllocRuntimeTypeIndex(), \
658  TypeName::_type_child_slots, \
659  TypeName::_type_child_slots_can_overflow); \
660  return tidx; \
661  }
662 
668 #define MXNET_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType) \
669  static const constexpr bool _type_final = true; \
670  static const constexpr int _type_child_slots = 0; \
671  MXNET_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
672 
679 #define MXNET_REGISTER_OBJECT_TYPE(TypeName) \
680  static DMLC_ATTRIBUTE_UNUSED uint32_t __make_Object_tidx##_##TypeName##__ = \
681  TypeName::_GetOrAllocRuntimeTypeIndex()
682 
683 #define MXNET_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName) \
684  TypeName(const TypeName& other) = default; \
685  TypeName(TypeName&& other) = default; \
686  TypeName& operator=(const TypeName& other) = default; \
687  TypeName& operator=(TypeName&& other) = default;
688 
689 #define MXNET_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
690  TypeName() {} \
691  explicit TypeName(::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) : ParentType(n) {} \
692  const ObjectName* operator->() const { \
693  return static_cast<const ObjectName*>(data_.get()); \
694  } \
695  operator bool() const { \
696  return data_ != nullptr; \
697  } \
698  using ContainerType = ObjectName;
699 
700 #define MXNET_DEFINE_OBJECT_REF_METHODS_MUT(TypeName, ParentType, ObjectName) \
701  TypeName() {} \
702  explicit TypeName(::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) : ParentType(n) {} \
703  ObjectName* operator->() { \
704  return static_cast<ObjectName*>(data_.get()); \
705  } \
706  operator bool() const { \
707  return data_ != nullptr; \
708  } \
709  using ContainerType = ObjectName;
710 
711 #define MXNET_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \
712  explicit TypeName(::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) : ParentType(n) {} \
713  MXNET_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TypeName); \
714  const ObjectName* operator->() const { \
715  return static_cast<const ObjectName*>(data_.get()); \
716  } \
717  const ObjectName* get() const { \
718  return operator->(); \
719  } \
720  static constexpr bool _type_is_nullable = false; \
721  using ContainerType = ObjectName;
722 
723 // Implementations details below
724 // Object reference counting.
725 #if MXNET_OBJECT_ATOMIC_REF_COUNTER
726 
727 inline void Object::IncRef() {
728  ref_counter_.fetch_add(1, std::memory_order_relaxed);
729 }
730 
731 inline void Object::DecRef() {
732  if (ref_counter_.fetch_sub(1, std::memory_order_release) == 1) {
733  std::atomic_thread_fence(std::memory_order_acquire);
734  if (this->deleter_ != nullptr) {
735  (*this->deleter_)(this);
736  }
737  }
738 }
739 
740 inline int Object::use_count() const {
741  return ref_counter_.load(std::memory_order_relaxed);
742 }
743 
744 #else
745 
746 inline void Object::IncRef() {
747  ++ref_counter_;
748 }
749 
750 inline void Object::DecRef() {
751  if (--ref_counter == 0) {
752  if (this->deleter_ != nullptr) {
753  (*this->deleter_)(this);
754  }
755  }
756 }
757 
758 inline int Object::use_count() const {
759  return ref_counter_;
760 }
761 
762 #endif // MXNET_OBJECT_ATOMIC_REF_COUNTER
763 
764 template <typename TargetType>
765 inline bool Object::IsInstance() const {
766  const Object* self = this;
767  // NOTE: the following code can be optimized by
768  // compiler dead-code elimination for already known constants.
769  if (self != nullptr) {
770  // Everything is a subclass of object.
771  if (std::is_same<TargetType, Object>::value)
772  return true;
773  if (TargetType::_type_final) {
774  // if the target type is a final type
775  // then we only need to check the equivalence.
776  return self->type_index_ == TargetType::RuntimeTypeIndex();
777  } else {
778  // if target type is a non-leaf type
779  // Check if type index falls into the range of reserved slots.
780  uint32_t begin = TargetType::RuntimeTypeIndex();
781  // The condition will be optimized by constant-folding.
782  if (TargetType::_type_child_slots != 0) {
783  uint32_t end = begin + TargetType::_type_child_slots;
784  if (self->type_index_ >= begin && self->type_index_ < end)
785  return true;
786  } else {
787  if (self->type_index_ == begin)
788  return true;
789  }
790  if (!TargetType::_type_child_slots_can_overflow)
791  return false;
792  // Invariance: parent index is always smaller than the child.
793  if (self->type_index_ < TargetType::RuntimeTypeIndex())
794  return false;
795  // The rare slower-path, check type hierachy.
796  return self->DerivedFrom(TargetType::RuntimeTypeIndex());
797  }
798  } else {
799  return false;
800  }
801 }
802 
803 template <typename ObjectType>
804 inline const ObjectType* ObjectRef::as() const {
805  if (data_ != nullptr && data_->IsInstance<ObjectType>()) {
806  return static_cast<ObjectType*>(data_.get());
807  } else {
808  return nullptr;
809  }
810 }
811 
812 template <typename RefType, typename ObjType>
813 inline RefType GetRef(const ObjType* ptr) {
814  static_assert(std::is_base_of<typename RefType::ContainerType, ObjType>::value,
815  "Can only cast to the ref of same container type");
816  if (!RefType::_type_is_nullable) {
817  CHECK(ptr != nullptr);
818  }
819  return RefType(ObjectPtr<Object>(const_cast<Object*>(static_cast<const Object*>(ptr))));
820 }
821 
822 template <typename BaseType, typename ObjType>
823 inline ObjectPtr<BaseType> GetObjectPtr(ObjType* ptr) {
824  static_assert(std::is_base_of<BaseType, ObjType>::value,
825  "Can only cast to the ref of same container type");
826  return ObjectPtr<BaseType>(static_cast<Object*>(ptr));
827 }
828 
829 template <typename SubRef, typename BaseRef>
830 inline SubRef Downcast(BaseRef ref) {
831  if (ref.defined()) {
832  CHECK(ref->template IsInstance<typename SubRef::ContainerType>())
833  << "Downcast from " << ref->GetTypeKey() << " to " << SubRef::ContainerType::_type_key
834  << " failed.";
835  } else {
836  CHECK(SubRef::_type_is_nullable) << "Downcast from nullptr to not nullable reference of "
837  << SubRef::ContainerType::_type_key;
838  }
839  return SubRef(std::move(ref.data_));
840 }
841 
842 } // namespace runtime
843 
844 template <typename T>
846 
847 } // namespace mxnet
848 
849 #endif // MXNET_RUNTIME_OBJECT_H_
mxnet::runtime::Object::GetOrAllocRuntimeTypeIndex
static MXNET_DLL uint32_t GetOrAllocRuntimeTypeIndex(const std::string &key, uint32_t static_tindex, uint32_t parent_tindex, uint32_t type_child_slots, bool type_child_slots_can_overflow)
Get the type index using type key.
mxnet
namespace of mxnet
Definition: api_registry.h:33
mxnet::runtime::ObjectPtr::ObjectPtr
ObjectPtr(ObjectPtr< T > &&other)
move constructor
Definition: object.h:372
mxnet::runtime::TypeIndex
TypeIndex
list of the type index.
Definition: object.h:51
mxnet::runtime::Object::RuntimeTypeIndex
static uint32_t RuntimeTypeIndex()
Definition: object.h:213
mxnet::runtime::ObjectEqual::operator()
size_t operator()(const ObjectPtr< T > &a, const ObjectPtr< T > &b) const
Definition: object.h:638
mxnet::runtime::ObjectRef::get
const Object * get() const
Definition: object.h:543
mxnet::runtime::Object
base class of all object containers.
Definition: object.h:151
mxnet::runtime::Object::IncRef
void IncRef()
developer function, increases reference counter.
Definition: object.h:727
c_runtime_api.h
mxnet::runtime::ObjectPtr::ObjectPtr
ObjectPtr(std::nullptr_t)
default constructor
Definition: object.h:351
mxnet::runtime::Object::FDeleter
void(* FDeleter)(Object *self)
Object deleter.
Definition: object.h:157
mxnet::runtime::GetObjectPtr
ObjectPtr< BaseType > GetObjectPtr(ObjectType *ptr)
Get an object ptr type from a raw object ptr.
mxnet::runtime::ObjectPtr::ObjectPtr
ObjectPtr(ObjectPtr< Y > &&other)
move constructor
Definition: object.h:381
mxnet::runtime::ObjectHash::operator()
size_t operator()(const ObjectPtr< T > &a) const
Definition: object.h:626
mxnet::runtime::Object::TypeIndex2Key
static MXNET_DLL std::string TypeIndex2Key(uint32_t tindex)
Get the type key of the corresponding index from runtime.
mxnet::runtime::ObjectPtr
A custom smart pointer for Object.
Definition: object.h:346
mxnet::runtime::MXNetArgValue
A single argument value to PackedFunc. Containing both type_code and MXNetValue.
Definition: packed_func.h:480
mxnet::runtime::kMXNetADT
@ kMXNetADT
Definition: object.h:56
mxnet::runtime::ObjectPtr::operator!=
bool operator!=(std::nullptr_t null) const
Definition: object.h:465
mxnet::runtime::Object::RefCounterType
std::atomic< int32_t > RefCounterType
Definition: object.h:203
mxnet::runtime::MXNetPODValue_
Internal base class to handle conversion to POD values.
Definition: packed_func.h:401
mxnet::runtime::ObjectRef::GetDataPtr
static ObjectPtr< ObjectType > GetDataPtr(const ObjectRef &ref)
Internal helper function get data_ as ObjectPtr of ObjectType.
Definition: object.h:597
mxnet::runtime::GetRef
RefType GetRef(const ObjectType *ptr)
Get a reference type from a raw object ptr type.
mxnet::runtime::ObjectPtr::operator=
ObjectPtr< T > & operator=(const ObjectPtr< T > &other)
copy assignmemt
Definition: object.h:421
mxnet::runtime::ObjectPtr::get
T * get() const
Definition: object.h:401
mxnet::runtime::ObjectPtr::GetRef
friend RefType GetRef(const ObjType *ptr)
Definition: object.h:813
mxnet::runtime::ObjectRef::same_as
bool same_as(const ObjectRef &other) const
Comparator.
Definition: object.h:511
mxnet::runtime::ObjectPtr::GetObjectPtr
friend ObjectPtr< BaseType > GetObjectPtr(ObjType *ptr)
Definition: object.h:823
mxnet::runtime::Downcast
SubRef Downcast(BaseRef ref)
Downcast a base reference type to a more specific type.
Definition: object.h:830
mxnet::runtime::Object::_type_child_slots_can_overflow
static constexpr bool _type_child_slots_can_overflow
Definition: object.h:220
mxnet::runtime::Object::_GetOrAllocRuntimeTypeIndex
static uint32_t _GetOrAllocRuntimeTypeIndex()
Definition: object.h:210
mxnet::runtime::Object::operator=
Object & operator=(Object &&other)
Definition: object.h:240
mxnet::runtime::Object::TypeIndex2KeyHash
static MXNET_DLL size_t TypeIndex2KeyHash(uint32_t tindex)
Get the type key hash of the corresponding index from runtime.
mxnet::runtime::Object::IsInstance
bool IsInstance() const
Definition: object.h:765
mxnet::runtime::kRoot
@ kRoot
Root object type.
Definition: object.h:53
mxnet::runtime::MXNetRetValue
Return Value container, Unlike MXNetArgValue, which only holds reference and do not delete the underl...
Definition: packed_func.h:555
mxnet::runtime::Object::TypeKey2Index
static MXNET_DLL uint32_t TypeKey2Index(const std::string &key)
Get the type index of the corresponding key from runtime.
mxnet::runtime::kMXNetClosure
@ kMXNetClosure
Definition: object.h:55
mxnet::runtime::ObjectPtr::ObjectPtr
friend class ObjectPtr
we always used ObjectPtr for a reference pointer to the node, so this alias can be changed in case.
Definition: object.h:486
mxnet::runtime::ObjectPtr::operator*
T & operator*() const
Definition: object.h:413
mxnet::runtime::kSlice
@ kSlice
Definition: object.h:60
mxnet::runtime::kEllipsis
@ kEllipsis
Definition: object.h:59
mxnet::runtime::ObjectRef::DowncastNoCheck
static T DowncastNoCheck(ObjectRef ref)
Internal helper function downcast a ref without check.
Definition: object.h:587
mxnet::runtime::ObjectPtr::operator==
bool operator==(std::nullptr_t null) const
Definition: object.h:461
mxnet::runtime::Object::GetTypeKeyHash
size_t GetTypeKeyHash() const
Definition: object.h:172
mxnet::runtime::Object::_type_index
static constexpr uint32_t _type_index
Definition: object.h:224
mxnet::runtime::Object::_type_child_slots
static constexpr uint32_t _type_child_slots
Definition: object.h:219
mxnet::runtime::ObjectPtr::unique
bool unique() const
Definition: object.h:449
mxnet::runtime::ObjectPtr::use_count
int use_count() const
Definition: object.h:445
mxnet::runtime::kFloat
@ kFloat
Definition: object.h:62
mxnet::runtime::ObjectPtr::ObjectPtr
ObjectPtr(const ObjectPtr< U > &other)
copy constructor
Definition: object.h:363
mxnet::runtime::kStaticIndexEnd
@ kStaticIndexEnd
Definition: object.h:63
mxnet::runtime::kInteger
@ kInteger
Definition: object.h:61
mxnet::runtime::ObjectRef::as
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:804
mxnet::runtime::Object::Object
Object(const Object &other)
Definition: object.h:233
MXNET_DLL
#define MXNET_DLL
MXNET_DLL prefix for windows.
Definition: c_api.h:53
mxnet::runtime::ObjectEqual::operator()
bool operator()(const ObjectRef &a, const ObjectRef &b) const
Definition: object.h:633
mxnet::runtime::ObjectPtr::operator=
ObjectPtr< T > & operator=(ObjectPtr< T > &&other)
move assignmemt
Definition: object.h:432
mxnet::runtime::ObjectRef::ObjectRef
ObjectRef()=default
default constructor
mxnet::runtime::ObjectPtr::reset
void reset()
reset the content of ptr to be nullptr
Definition: object.h:438
mxnet::runtime::ObjectRef::unique
bool unique() const
Definition: object.h:551
mxnet::runtime::ObjectRef::data_
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:575
mxnet::runtime::Object::operator=
Object & operator=(const Object &other)
Definition: object.h:237
mxnet::runtime::ObjectHash
ObjectRef hash functor.
Definition: object.h:620
mxnet::runtime::ObjectPtr::operator->
T * operator->() const
Definition: object.h:407
mxnet::runtime::ObjectRef::operator->
const Object * operator->() const
Definition: object.h:547
mxnet::runtime::ObjectRef::ObjectRef
ObjectRef(ObjectPtr< Object > data)
Constructor from existing object ptr.
Definition: object.h:505
mxnet::runtime::Object::Object
Object()
Definition: object.h:227
mxnet::runtime::Object::_type_key
static constexpr const char * _type_key
Definition: object.h:208
mxnet::runtime::ObjAllocatorBase
Base class of object allocators that implements make. Use curiously recurring template pattern.
Definition: memory.h:60
mxnet::runtime::ObjectRef::operator<
bool operator<(const ObjectRef &other) const
Comparator.
Definition: object.h:535
mxnet::runtime::ObjectRef::operator!=
bool operator!=(const ObjectRef &other) const
Comparator.
Definition: object.h:527
mxnet::runtime::kMXNetMap
@ kMXNetMap
Definition: object.h:57
mxnet::runtime::Object::Object
Object(Object &&other)
Definition: object.h:235
mxnet::runtime::ObjectRef
Base class of all object reference.
Definition: object.h:500
mxnet::runtime::ObjectHash::operator()
size_t operator()(const ObjectRef &a) const
Definition: object.h:621
mxnet::runtime::Object::ref_counter_
RefCounterType ref_counter_
The internal reference counter.
Definition: object.h:249
mxnet::runtime::Object::_type_final
static constexpr bool _type_final
Definition: object.h:218
mxnet::runtime::ObjectRef::get_mutable
Object * get_mutable() const
Definition: object.h:577
mxnet::runtime::Object::deleter_
FDeleter deleter_
deleter of this object to enable customized allocation. If the deleter is nullptr,...
Definition: object.h:255
mxnet::runtime::Object::DecRef
void DecRef()
developer function, decrease reference counter.
Definition: object.h:731
mxnet::runtime::ObjectPtr::ObjectPtr
ObjectPtr(const ObjectPtr< T > &other)
copy constructor
Definition: object.h:356
mxnet::runtime::ObjectEqual
ObjectRef equal functor.
Definition: object.h:632
mxnet::runtime::Object::GetTypeKey
std::string GetTypeKey() const
Definition: object.h:166
mxnet::runtime::kDynamic
@ kDynamic
Type index is allocated during runtime.
Definition: object.h:65
mxnet::runtime::ObjectPtr::~ObjectPtr
~ObjectPtr()
destructor
Definition: object.h:388
mxnet::runtime::Object::type_index_
uint32_t type_index_
Type index(tag) that indicates the type of the object.
Definition: object.h:247
mxnet::runtime::ObjectRef::defined
bool defined() const
Definition: object.h:539
mxnet::runtime::kMXNetTensor
@ kMXNetTensor
Definition: object.h:54
mxnet::runtime::ObjectPtr::operator!=
bool operator!=(const ObjectPtr< T > &other) const
Definition: object.h:457
mxnet::runtime::ObjectPtr::operator==
bool operator==(const ObjectPtr< T > &other) const
Definition: object.h:453
mxnet::runtime::ObjectRef::Downcast
friend SubRef Downcast(BaseRef ref)
Downcast a base reference type to a more specific type.
Definition: object.h:830
mxnet::runtime::Object::type_index
uint32_t type_index() const
Definition: object.h:159
mxnet::runtime::MXNetArgsSetter
Definition: packed_func.h:1013
mxnet::runtime::ObjectPtr::swap
void swap(ObjectPtr< T > &other)
Swap this array with another Object.
Definition: object.h:395
mxnet::runtime::ObjectRef::_type_is_nullable
static constexpr bool _type_is_nullable
Definition: object.h:571
mxnet::runtime::ObjectPtr::ObjectPtr
ObjectPtr()
default constructor
Definition: object.h:349
mxnet::runtime::Object::ObjectInternal
friend class ObjectInternal
Definition: object.h:311
mxnet::runtime::kMXNetString
@ kMXNetString
Definition: object.h:58
mxnet::runtime::ObjectRef::operator==
bool operator==(const ObjectRef &other) const
Comparator.
Definition: object.h:519