ArmNN
 24.08
ConstTensor Class Reference

A tensor defined by a TensorInfo (shape and data type) and an immutable backing store. More...

#include <Tensor.hpp>

Inheritance diagram for ConstTensor:
[legend]
Collaboration diagram for ConstTensor:
[legend]

Public Member Functions

 ConstTensor ()
 
 ConstTensor (const Tensor &other)
 ConstTensor implicitly constructed from non-const Tensor. More...
 
template<template< typename, typename... > class ContainerType, typename T , typename... ContainerArgs>
 ConstTensor (const TensorInfo &info, const ContainerType< T, ContainerArgs... > &container)
 Constructor from a backing container. More...
 
template<typename MemoryType >
 ConstTensor (const TensorInfo &info, MemoryType memoryArea)
 ConstTensor constructed from TensorInfo and MemoryType template (a raw memory pointer). More...
 
- Public Member Functions inherited from BaseTensor< const void * >
 BaseTensor ()
 Empty (invalid) constructor. More...
 
 BaseTensor (const TensorInfo &info, const void * memoryArea)
 Constructor from a raw memory pointer. More...
 
 BaseTensor (const BaseTensor &other)
 Tensors are copyable. More...
 
BaseTensoroperator= (const BaseTensor &)
 Tensors are copyable. More...
 
const TensorInfoGetInfo () const
 
TensorInfoGetInfo ()
 
const TensorShapeGetShape () const
 
TensorShapeGetShape ()
 
DataType GetDataType () const
 
unsigned int GetNumDimensions () const
 
unsigned int GetNumBytes () const
 
unsigned int GetNumElements () const
 
const void * GetMemoryArea () const
 

Additional Inherited Members

- Protected Member Functions inherited from BaseTensor< const void * >
 ~BaseTensor ()
 Protected destructor to stop users from making these (could still new one on the heap and then leak it...) More...
 
- Protected Attributes inherited from BaseTensor< const void * >
const void * m_MemoryArea
 

Detailed Description

A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.

Examples
AsyncExecutionSample.cpp, CustomMemoryAllocatorSample.cpp, DynamicSample.cpp, and SimpleSample.cpp.

Definition at line 329 of file Tensor.hpp.

Constructor & Destructor Documentation

◆ ConstTensor() [1/4]

ConstTensor ( )
inline

Definition at line 334 of file Tensor.hpp.

334  : BaseTensor<const void*>()
335  {
336  this->GetInfo().SetConstant();
337  }

References BaseTensor< const void * >::GetInfo(), and TensorInfo::SetConstant().

◆ ConstTensor() [2/4]

ConstTensor ( const Tensor other)
inline

ConstTensor implicitly constructed from non-const Tensor.

Parameters
other- reference to a constant Tensor.
Exceptions
InvalidArgumentExceptionwhen Tensor parameter TensorInfo is non-constant.

Definition at line 344 of file Tensor.hpp.

344  : BaseTensor<const void*>(other.GetInfo(), other.GetMemoryArea())
345  {
346  if (!this->GetInfo().IsConstant())
347  {
348  throw InvalidArgumentException("Invalid attempt to construct ConstTensor "
349  "from Tensor due to non-constant TensorInfo");
350  }
351  }

References BaseTensor< const void * >::GetInfo().

◆ ConstTensor() [3/4]

ConstTensor ( const TensorInfo info,
const ContainerType< T, ContainerArgs... > &  container 
)
inline

Constructor from a backing container.

Parameters
container- An stl-like container type which implements data() and size() methods. Presence of data() and size() is a strong indicator of the continuous memory layout of the container, which is a requirement for Tensor data. Tensor instances do not claim ownership of referenced memory regions, that is, no attempt will be made by ArmNN to free these memory regions automatically.
Exceptions
InvalidArgumentExceptionwhen isConstant parameter of input TensorInfo is false.

Definition at line 362 of file Tensor.hpp.

363  : BaseTensor<const void*>(info, container.data())
364  {
365  if (!this->GetInfo().IsConstant())
366  {
367  throw InvalidArgumentException("Invalid attempt to construct ConstTensor from non-constant TensorInfo.");
368  }
369  if (container.size() * sizeof(T) != info.GetNumBytes())
370  {
371  throw InvalidArgumentException("Container size is not correct");
372  }
373  }

References BaseTensor< const void * >::GetInfo(), and armnn::info.

◆ ConstTensor() [4/4]

ConstTensor ( const TensorInfo info,
MemoryType  memoryArea 
)
inline

ConstTensor constructed from TensorInfo and MemoryType template (a raw memory pointer).

Parameters
info- reference to a constant TensorInfo.
memoryArea- Region of CPU-addressable memory where tensor data will be stored. Must be valid while workloads are on the fly. Tensor instances do not claim ownership of referenced memory regions, that is, no attempt will be made by ArmNN to free these memory regions automatically.
Exceptions
InvalidArgumentExceptionwhen TensorInfo isConstant parameter is false.

Definition at line 384 of file Tensor.hpp.

385  : BaseTensor<const void*>(info, memoryArea)
386  {
387  if (!this->GetInfo().IsConstant())
388  {
389  throw InvalidArgumentException("Invalid attempt to construct ConstTensor from non-constant TensorInfo.");
390  }
391  }

References BaseTensor< const void * >::GetInfo(), and armnn::info.


The documentation for this class was generated from the following file:
armnn::BaseTensor< const void * >::GetInfo
const TensorInfo & GetInfo() const
Definition: Tensor.hpp:297
armnn::BoostLogSeverityMapping::info
@ info
armnn::TensorInfo::SetConstant
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
Definition: Tensor.cpp:518