Go to the documentation of this file.
25 #ifndef MXNET_RUNTIME_CONTAINER_H_
26 #define MXNET_RUNTIME_CONTAINER_H_
27 #include <dmlc/logging.h>
31 #include <initializer_list>
32 #include <type_traits>
79 template <
typename ArrayType,
typename ElemType>
88 size_t size = Self()->GetSize();
89 CHECK_LT(idx, size) <<
"Index " << idx <<
" out of bounds " << size <<
"\n";
90 return *(
reinterpret_cast<ElemType*
>(AddressOf(idx)));
99 size_t size = Self()->GetSize();
100 CHECK_LT(idx, size) <<
"Index " << idx <<
" out of bounds " << size <<
"\n";
101 return *(
reinterpret_cast<ElemType*
>(AddressOf(idx)));
108 if (!(std::is_standard_layout<ElemType>::value && std::is_trivial<ElemType>::value)) {
109 size_t size = Self()->GetSize();
110 for (
size_t i = 0; i < size; ++i) {
111 ElemType* fp =
reinterpret_cast<ElemType*
>(AddressOf(i));
112 fp->ElemType::~ElemType();
129 template <
typename... Args>
131 void* field_ptr = AddressOf(idx);
132 new (field_ptr) ElemType(std::forward<Args>(args)...);
141 inline ArrayType* Self()
const {
151 void* AddressOf(
size_t idx)
const {
153 alignof(ArrayType) %
alignof(ElemType) == 0 &&
sizeof(ArrayType) %
alignof(ElemType) == 0,
154 "The size and alignment of ArrayType should respect "
155 "ElemType's alignment.");
157 size_t kDataStart =
sizeof(ArrayType);
158 ArrayType*
self = Self();
159 char* data_start =
reinterpret_cast<char*
>(
self) + kDataStart;
160 return data_start + idx *
sizeof(ElemType);
181 size_t GetSize()
const {
192 template <
typename Iterator>
193 void Init(Iterator begin, Iterator end) {
194 size_t num_elems = std::distance(begin, end);
197 for (
size_t i = 0; i < num_elems; ++i) {
217 ADT(uint32_t
tag, std::vector<ObjectRef> fields) :
ADT(
tag, fields.begin(), fields.end()){};
226 template <
typename Iterator>
227 ADT(uint32_t
tag, Iterator begin, Iterator end) {
228 size_t num_elems = std::distance(begin, end);
229 auto ptr = make_inplace_array_object<ADTObj, ObjectRef>(num_elems);
231 ptr->Init(begin, end);
232 data_ = std::move(ptr);
241 ADT(uint32_t
tag, std::initializer_list<ObjectRef> init) :
ADT(
tag, init.begin(), init.end()){};
274 template <
typename... Args>
276 return ADT(0, std::forward<Args>(args)...);
285 #endif // MXNET_RUNTIME_CONTAINER_H_
namespace of mxnet
Definition: api_registry.h:33
const ObjectRef & operator[](size_t idx) const
Access element at index.
Definition: container.h:249
base class of all object containers.
Definition: object.h:151
const ElemType & operator[](size_t idx) const
Access element at index.
Definition: container.h:87
size_t tag() const
Return the ADT tag.
Definition: container.h:256
uint32_t tag
The tag representing the constructor used.
Definition: container.h:168
static ADT Tuple(Args &&... args)
Construct a tuple object.
Definition: container.h:275
size_t size() const
Return the number of fields.
Definition: container.h:263
@ kMXNetADT
Definition: object.h:56
~InplaceArrayBase()
Destroy the Inplace Array Base object.
Definition: container.h:107
ADT(uint32_t tag, std::vector< ObjectRef > fields)
construct an ADT object reference.
Definition: container.h:217
#define MXNET_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:668
Base template for classes with array like memory layout.
Definition: container.h:80
reference to algebraic data type objects.
Definition: container.h:209
void EmplaceInit(size_t idx, Args &&... args)
Construct a value in place with the arguments.
Definition: container.h:130
ADT(uint32_t tag, std::initializer_list< ObjectRef > init)
construct an ADT object reference.
Definition: container.h:241
ElemType & operator[](size_t idx)
Access element at index.
Definition: container.h:98
Runtime memory management.
ADT(uint32_t tag, Iterator begin, Iterator end)
construct an ADT object reference.
Definition: container.h:227
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:575
static constexpr const uint32_t _type_index
Definition: container.h:174
const Object * operator->() const
Definition: object.h:547
An object representing a structure or enumeration.
Definition: container.h:165
uint32_t size
Number of fields in the ADT object.
Definition: container.h:170
static constexpr const char * _type_key
Definition: container.h:173
Base class of all object reference.
Definition: object.h:500
#define MXNET_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:689
A builder class that helps to incrementally build ADT.
Definition: ffi_helper.h:122
A managed object in MXNet runtime.