ArmNN
 23.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 GetDepthIndex () 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.

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;
29  m_DepthIndex = 1;
30  m_HeightIndex = 2;
31  m_WidthIndex = 3;
32  m_ChannelsIndex = 4;
33  break;
35  m_ChannelsIndex = 1;
36  m_DepthIndex = 2;
37  m_HeightIndex = 3;
38  m_WidthIndex = 4;
39  break;
40  default:
41  throw armnn::InvalidArgumentException("Unknown DataLayout value: " +
42  std::to_string(static_cast<int>(dataLayout)));
43  }
44 }

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

Member Function Documentation

◆ GetChannelsIndex()

◆ GetDataLayout()

armnn::DataLayout GetDataLayout ( ) const
inline

Definition at line 22 of file DataLayoutIndexed.hpp.

22 { return m_DataLayout; }

Referenced by armnn::Convolve(), armnn::Convolve3d(), armnn::GetOffset(), armnn::Offset(), armnnUtils::operator==(), and armnn::Pooling2d().

◆ GetDepthIndex()

unsigned int GetDepthIndex ( ) 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 28 of file DataLayoutIndexed.hpp.

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

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

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

◆ GetWidthIndex()


The documentation for this class was generated from the following files:
armnn::DataLayout::NCHW
@ NCHW
armnn::DataLayout::NCDHW
@ NCDHW
armnn::DataLayout::NHWC
@ NHWC
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::DataLayout::NDHWC
@ NDHWC
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80