ArmNN
 24.02
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  if (batchIndex >= shape[0] && !( shape[0] == 0 && batchIndex == 0))
33  {
34  throw armnn::Exception("Unable to get batch index", CHECK_LOCATION());
35  }
36  if (channelIndex >= shape[m_ChannelsIndex] &&
37  !(shape[m_ChannelsIndex] == 0 && channelIndex == 0))
38  {
39  throw armnn::Exception("Unable to get channel index", CHECK_LOCATION());
40 
41  }
42  if (heightIndex >= shape[m_HeightIndex] &&
43  !( shape[m_HeightIndex] == 0 && heightIndex == 0))
44  {
45  throw armnn::Exception("Unable to get height index", CHECK_LOCATION());
46  }
47  if (widthIndex >= shape[m_WidthIndex] &&
48  ( shape[m_WidthIndex] == 0 && widthIndex == 0))
49  {
50  throw armnn::Exception("Unable to get width index", CHECK_LOCATION());
51  }
52 
53  /// Offset the given indices appropriately depending on the data layout
54  switch (m_DataLayout)
55  {
57  batchIndex *= shape[1] * shape[2] * shape[3]; // batchIndex *= heightIndex * widthIndex * channelIndex
58  heightIndex *= shape[m_WidthIndex] * shape[m_ChannelsIndex];
59  widthIndex *= shape[m_ChannelsIndex];
60  /// channelIndex stays unchanged
61  break;
63  default:
64  batchIndex *= shape[1] * shape[2] * shape[3]; // batchIndex *= heightIndex * widthIndex * channelIndex
65  channelIndex *= shape[m_HeightIndex] * shape[m_WidthIndex];
66  heightIndex *= shape[m_WidthIndex];
67  /// widthIndex stays unchanged
68  break;
69  }
70 
71  /// Get the value using the correct offset
72  return batchIndex + channelIndex + heightIndex + widthIndex;
73  }

References CHECK_LOCATION, 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::NCDHW
@ NCDHW
armnn::DataLayout::NHWC
@ NHWC
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::DataLayout::NDHWC
@ NDHWC
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::DataLayout::NCHW
@ NCHW