ArmNN  NotReleased
DataLayoutIndexed Class Reference

#include <DataLayoutIndexed.hpp>

Public Member Functions

 DataLayoutIndexed (armnn::DataLayout dataLayout)
 
armnn::DataLayout GetDataLayout () const
 
unsigned int GetChannelsIndex () const
 
unsigned int GetHeightIndex () const
 
unsigned int GetWidthIndex () const
 
unsigned int GetIndex (const armnn::TensorShape &shape, unsigned int batchIndex, unsigned int channelIndex, unsigned int heightIndex, unsigned int widthIndex) const
 

Detailed Description

Definition at line 17 of file DataLayoutIndexed.hpp.

Constructor & Destructor Documentation

◆ DataLayoutIndexed()

Definition at line 13 of file DataLayoutIndexed.cpp.

References armnn::NCHW, and armnn::NHWC.

14  : m_DataLayout(dataLayout)
15 {
16  switch (dataLayout)
17  {
19  m_ChannelsIndex = 3;
20  m_HeightIndex = 1;
21  m_WidthIndex = 2;
22  break;
24  m_ChannelsIndex = 1;
25  m_HeightIndex = 2;
26  m_WidthIndex = 3;
27  break;
28  default:
29  throw armnn::InvalidArgumentException("Unknown DataLayout value: " +
30  std::to_string(static_cast<int>(dataLayout)));
31  }
32 }

Member Function Documentation

◆ GetChannelsIndex()

◆ GetDataLayout()

armnn::DataLayout GetDataLayout ( ) const
inline

Definition at line 22 of file DataLayoutIndexed.hpp.

Referenced by CompareDepthwiseConvolution2dTestImpl(), armnn::GetOffset(), armnn::Offset(), and armnnUtils::operator==().

22 { return m_DataLayout; }

◆ GetHeightIndex()

◆ GetIndex()

unsigned int GetIndex ( const armnn::TensorShape shape,
unsigned int  batchIndex,
unsigned int  channelIndex,
unsigned int  heightIndex,
unsigned int  widthIndex 
) const
inline

Definition at line 27 of file DataLayoutIndexed.hpp.

References armnn::NCHW, armnn::NHWC, and armnnUtils::operator==().

Referenced by armnn::BatchNormImpl(), armnn::Convolve(), TensorBufferArrayView< DataType >::Get(), armnn::InstanceNorm(), armnn::Pooling2d(), armnn::Resize(), and armnn::TransposeConvolution2dImpl().

30  {
31  BOOST_ASSERT( batchIndex < shape[0] || ( shape[0] == 0 && batchIndex == 0 ) );
32  BOOST_ASSERT( channelIndex < shape[m_ChannelsIndex] ||
33  ( shape[m_ChannelsIndex] == 0 && channelIndex == 0) );
34  BOOST_ASSERT( heightIndex < shape[m_HeightIndex] ||
35  ( shape[m_HeightIndex] == 0 && heightIndex == 0) );
36  BOOST_ASSERT( widthIndex < shape[m_WidthIndex] ||
37  ( shape[m_WidthIndex] == 0 && widthIndex == 0) );
38 
39  // Offset the given indices appropriately depending on the data layout
40  switch (m_DataLayout)
41  {
43  batchIndex *= shape[1] * shape[2] * shape[3]; // batchIndex *= heightIndex * widthIndex * channelIndex
44  heightIndex *= shape[m_WidthIndex] * shape[m_ChannelsIndex];
45  widthIndex *= shape[m_ChannelsIndex];
46  // channelIndex stays unchanged
47  break;
49  default:
50  batchIndex *= shape[1] * shape[2] * shape[3]; // batchIndex *= heightIndex * widthIndex * channelIndex
51  channelIndex *= shape[m_HeightIndex] * shape[m_WidthIndex];
52  heightIndex *= shape[m_WidthIndex];
53  // widthIndex stays unchanged
54  break;
55  }
56 
57  // Get the value using the correct offset
58  return batchIndex + channelIndex + heightIndex + widthIndex;
59  }

◆ GetWidthIndex()


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