24 #ifndef TVM_RUNTIME_CONTAINER_BASE_H_
25 #define TVM_RUNTIME_CONTAINER_BASE_H_
27 #include <dmlc/logging.h>
28 #include <tvm/runtime/logging.h>
33 #include <initializer_list>
99 template <
typename ArrayType,
typename ElemType>
108 size_t size =
Self()->GetSize();
109 ICHECK_LT(idx, size) <<
"Index " << idx <<
" out of bounds " << size <<
"\n";
110 return *(
reinterpret_cast<ElemType*
>(
AddressOf(idx)));
119 size_t size =
Self()->GetSize();
120 ICHECK_LT(idx, size) <<
"Index " << idx <<
" out of bounds " << size <<
"\n";
121 return *(
reinterpret_cast<ElemType*
>(
AddressOf(idx)));
128 if (!(std::is_standard_layout<ElemType>::value && std::is_trivial<ElemType>::value)) {
129 size_t size =
Self()->GetSize();
130 for (
size_t i = 0; i < size; ++i) {
131 ElemType* fp =
reinterpret_cast<ElemType*
>(
AddressOf(i));
132 fp->ElemType::~ElemType();
148 template <
typename... Args>
151 new (field_ptr) ElemType(std::forward<Args>(args)...);
159 inline ArrayType*
Self()
const {
171 alignof(ArrayType) %
alignof(ElemType) == 0 &&
sizeof(ArrayType) %
alignof(ElemType) == 0,
172 "The size and alignment of ArrayType should respect "
173 "ElemType's alignment.");
175 size_t kDataStart =
sizeof(ArrayType);
176 ArrayType*
self =
Self();
177 char* data_start =
reinterpret_cast<char*
>(
self) + kDataStart;
178 return data_start + idx *
sizeof(ElemType);
187 template <
typename Converter,
typename TIter>
192 using pointer =
typename Converter::ResultType*;
220 template <
typename T = IterAdapter>
221 typename std::enable_if<std::is_same<iterator_category, std::random_access_iterator_tag>::value,
222 typename T::difference_type>::type
inline
224 return iter_ - rhs.iter_;
240 template <
typename Converter,
typename TIter>
245 using pointer =
typename Converter::ResultType*;
272 template <
typename T = ReverseIterAdapter>
273 typename std::enable_if<std::is_same<iterator_category, std::random_access_iterator_tag>::value,
274 typename T::difference_type>::type
inline
276 return rhs.iter_ - iter_;
291 using runtime::IterAdapter;
293 using runtime::Object;
294 using runtime::ObjectEqual;
295 using runtime::ObjectHash;
296 using runtime::ObjectPtr;
297 using runtime::ObjectPtrEqual;
298 using runtime::ObjectPtrHash;
299 using runtime::ObjectRef;
Base template for classes with array like memory layout.
Definition: base.h:100
void * AddressOf(size_t idx) const
Return the raw pointer to the element at idx.
Definition: base.h:169
const ElemType & operator[](size_t idx) const
Access element at index.
Definition: base.h:107
void EmplaceInit(size_t idx, Args &&... args)
Construct a value in place with the arguments.
Definition: base.h:149
ElemType & operator[](size_t idx)
Access element at index.
Definition: base.h:118
~InplaceArrayBase()
Destroy the Inplace Array Base object.
Definition: base.h:127
ArrayType * Self() const
Return the self object for the array.
Definition: base.h:159
iterator adapter that adapts TIter to return another type.
Definition: base.h:188
typename Converter::ResultType value_type
Definition: base.h:191
IterAdapter & operator++()
Definition: base.h:197
const value_type operator*() const
Definition: base.h:229
std::enable_if< std::is_same< iterator_category, std::random_access_iterator_tag >::value, typename T::difference_type >::type operator-(const IterAdapter &rhs) const
Definition: base.h:223
typename Converter::ResultType & reference
Definition: base.h:193
bool operator!=(IterAdapter other) const
Definition: base.h:228
IterAdapter operator++(int)
Definition: base.h:205
IterAdapter operator+(difference_type offset) const
Definition: base.h:216
typename std::iterator_traits< TIter >::difference_type difference_type
Definition: base.h:190
IterAdapter operator-(difference_type offset) const
Definition: base.h:218
IterAdapter(TIter iter)
Definition: base.h:196
bool operator==(IterAdapter other) const
Definition: base.h:227
IterAdapter & operator--()
Definition: base.h:201
typename std::iterator_traits< TIter >::iterator_category iterator_category
Definition: base.h:194
IterAdapter operator--(int)
Definition: base.h:210
typename Converter::ResultType * pointer
Definition: base.h:192
Base class of all object reference.
Definition: object.h:519
iterator adapter that adapts TIter to return another type.
Definition: base.h:241
const value_type operator*() const
Definition: base.h:281
typename Converter::ResultType & reference
Definition: base.h:246
bool operator!=(ReverseIterAdapter other) const
Definition: base.h:280
ReverseIterAdapter operator+(difference_type offset) const
Definition: base.h:268
ReverseIterAdapter & operator++()
Definition: base.h:250
ReverseIterAdapter operator--(int)
Definition: base.h:263
typename std::iterator_traits< TIter >::iterator_category iterator_category
Definition: base.h:247
ReverseIterAdapter(TIter iter)
Definition: base.h:249
std::enable_if< std::is_same< iterator_category, std::random_access_iterator_tag >::value, typename T::difference_type >::type operator-(const ReverseIterAdapter &rhs) const
Definition: base.h:275
ReverseIterAdapter operator++(int)
Definition: base.h:258
typename std::iterator_traits< TIter >::difference_type difference_type
Definition: base.h:243
typename Converter::ResultType value_type
Definition: base.h:244
typename Converter::ResultType * pointer
Definition: base.h:245
bool operator==(ReverseIterAdapter other) const
Definition: base.h:279
ReverseIterAdapter & operator--()
Definition: base.h:254
ObjectPtr< ArrayNode > make_object()
Definition: array.h:908
SubRef Downcast(BaseRef ref)
Downcast a base reference type to a more specific type.
Definition: object.h:936
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.
Runtime memory management.
String-aware ObjectRef hash functor.
Definition: base.h:50
bool operator()(const ObjectRef &a, const ObjectRef &b) const
Check if the two ObjectRef are equal.
Definition: string.h:517
String-aware ObjectRef equal functor.
Definition: base.h:40
size_t operator()(const ObjectRef &a) const
Calculate the hash code of an ObjectRef.
Definition: string.h:510