tvm
Public Member Functions | Protected Member Functions | List of all members
tvm::runtime::InplaceArrayBase< ArrayType, ElemType > Class Template Reference

Base template for classes with array like memory layout. More...

#include <base.h>

Collaboration diagram for tvm::runtime::InplaceArrayBase< ArrayType, ElemType >:

Public Member Functions

const ElemType & operator[] (size_t idx) const
 Access element at index. More...
 
ElemType & operator[] (size_t idx)
 Access element at index. More...
 
 ~InplaceArrayBase ()
 Destroy the Inplace Array Base object. More...
 

Protected Member Functions

template<typename... Args>
void EmplaceInit (size_t idx, Args &&... args)
 Construct a value in place with the arguments. More...
 
ArrayType * Self () const
 Return the self object for the array. More...
 
void * AddressOf (size_t idx) const
 Return the raw pointer to the element at idx. More...
 

Detailed Description

template<typename ArrayType, typename ElemType>
class tvm::runtime::InplaceArrayBase< ArrayType, ElemType >

Base template for classes with array like memory layout.

   It provides general methods to access the memory. The memory
   layout is ArrayType + [ElemType]. The alignment of ArrayType
   and ElemType is handled by the memory allocator.
Template Parameters
ArrayTypeThe array header type, contains object specific metadata.
ElemTypeThe type of objects stored in the array right after ArrayType.
// Example usage of the template to define a simple array wrapper
class ArrayObj : public InplaceArrayBase<ArrayObj, Elem> {
public:
// Wrap EmplaceInit to initialize the elements
template <typename Iterator>
void Init(Iterator begin, Iterator end) {
size_t num_elems = std::distance(begin, end);
auto it = begin;
this->size = 0;
for (size_t i = 0; i < num_elems; ++i) {
this->size++;
}
}
}
void test_function() {
vector<Elem> fields;
auto ptr = make_inplace_array_object<ArrayObj, Elem>(fields.size());
ptr->Init(fields.begin(), fields.end());
// Access the 0th element in the array.
assert(ptr->operator[](0) == fields[0]);
}
void EmplaceInit(size_t idx, Args &&... args)
Construct a value in place with the arguments.
Definition: base.h:149
BlockInitFrame Init()
The block initialization statement.

Constructor & Destructor Documentation

◆ ~InplaceArrayBase()

template<typename ArrayType , typename ElemType >
tvm::runtime::InplaceArrayBase< ArrayType, ElemType >::~InplaceArrayBase ( )
inline

Destroy the Inplace Array Base object.

Member Function Documentation

◆ AddressOf()

template<typename ArrayType , typename ElemType >
void* tvm::runtime::InplaceArrayBase< ArrayType, ElemType >::AddressOf ( size_t  idx) const
inlineprotected

Return the raw pointer to the element at idx.

Parameters
idxThe index of the element.
Returns
Raw pointer to the element.

◆ EmplaceInit()

template<typename ArrayType , typename ElemType >
template<typename... Args>
void tvm::runtime::InplaceArrayBase< ArrayType, ElemType >::EmplaceInit ( size_t  idx,
Args &&...  args 
)
inlineprotected

Construct a value in place with the arguments.

Template Parameters
ArgsType parameters of the arguments.
Parameters
idxIndex of the element.
argsArguments to construct the new value.
Note
Please make sure ArrayType::GetSize returns 0 before first call of EmplaceInit, and increment GetSize by 1 each time EmplaceInit succeeds.

◆ operator[]() [1/2]

template<typename ArrayType , typename ElemType >
ElemType& tvm::runtime::InplaceArrayBase< ArrayType, ElemType >::operator[] ( size_t  idx)
inline

Access element at index.

Parameters
idxThe index of the element.
Returns
Reference to ElemType at the index.

◆ operator[]() [2/2]

template<typename ArrayType , typename ElemType >
const ElemType& tvm::runtime::InplaceArrayBase< ArrayType, ElemType >::operator[] ( size_t  idx) const
inline

Access element at index.

Parameters
idxThe index of the element.
Returns
Const reference to ElemType at the index.

◆ Self()

template<typename ArrayType , typename ElemType >
ArrayType* tvm::runtime::InplaceArrayBase< ArrayType, ElemType >::Self ( ) const
inlineprotected

Return the self object for the array.

Returns
Pointer to ArrayType.

The documentation for this class was generated from the following file: