ArmNN
 21.05
DataLayoutIndexed Class Reference

Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout. More...

#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

Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.

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

◆ GetHeightIndex()

◆ GetIndex()

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

Offset the given indices appropriately depending on the data layout

channelIndex stays unchanged

widthIndex stays unchanged

Get the value using the correct offset

Definition at line 27 of file DataLayoutIndexed.hpp.

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

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

30  {
31  ARMNN_ASSERT( batchIndex < shape[0] || ( shape[0] == 0 && batchIndex == 0 ) );
32  ARMNN_ASSERT( channelIndex < shape[m_ChannelsIndex] ||
33  ( shape[m_ChannelsIndex] == 0 && channelIndex == 0) );
34  ARMNN_ASSERT( heightIndex < shape[m_HeightIndex] ||
35  ( shape[m_HeightIndex] == 0 && heightIndex == 0) );
36  ARMNN_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  }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

◆ GetWidthIndex()


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