ArmNN
 20.02
BroadcastLoop Struct Reference

#include <Broadcast.hpp>

Public Member Functions

 BroadcastLoop (const TensorShape &inShape0, const TensorShape &inShape1, const TensorShape &outShape)
 
 BroadcastLoop (const TensorShape &inShape, const TensorShape &outShape)
 
unsigned int GetNumDimensions ()
 
template<typename Func , typename DecoderOp , typename EncoderOp >
void Unroll (Func operationFunc, unsigned int dimension, DecoderOp &inData0, DecoderOp &inData1, EncoderOp &outData)
 
template<typename Func , typename DecoderOp , typename EncoderOp >
void Unroll (Func operationFunc, unsigned int dimension, DecoderOp &inData, EncoderOp &outData)
 

Detailed Description

Definition at line 14 of file Broadcast.hpp.

Constructor & Destructor Documentation

◆ BroadcastLoop() [1/2]

BroadcastLoop ( const TensorShape inShape0,
const TensorShape inShape1,
const TensorShape outShape 
)

Definition at line 11 of file Broadcast.cpp.

References BroadcastLoop::GetNumDimensions().

12 : m_DimData(outShape.GetNumDimensions())
13 {
14  const unsigned int numDims = GetNumDimensions();
15 
16  unsigned int sIn0 = 1;
17  unsigned int sIn1 = 1;
18  unsigned int sOut = 1;
19 
20  for (unsigned int j = numDims - 1, k = 0; k < numDims ; k++, j--)
21  {
22  m_DimData[j].m_DimSize = outShape[j];
23  m_DimData[j].m_Stride1 = (inShape0[j] > 1) ? sIn0 : 0;
24  m_DimData[j].m_Stride2 = (inShape1[j] > 1) ? sIn1 : 0;
25  m_DimData[j].m_StrideOut = sOut;
26 
27  sIn0 *= inShape0[j];
28  sIn1 *= inShape1[j];
29  sOut *= outShape[j];
30  }
31 }
unsigned int GetNumDimensions()
Definition: Broadcast.hpp:20

◆ BroadcastLoop() [2/2]

BroadcastLoop ( const TensorShape inShape,
const TensorShape outShape 
)

Definition at line 33 of file Broadcast.cpp.

References BroadcastLoop::GetNumDimensions().

34 : m_DimData(outShape.GetNumDimensions())
35 {
36  const unsigned int numDims = GetNumDimensions();
37 
38  unsigned int sIn = 1;
39  unsigned int sOut = 1;
40 
41  for (unsigned int j = numDims - 1, k = 0; k < numDims ; k++, j--)
42  {
43  m_DimData[j].m_DimSize = outShape[j];
44  m_DimData[j].m_Stride1 = (inShape[j] > 1) ? sIn : 0;
45  m_DimData[j].m_StrideOut = sOut;
46 
47  sIn *= inShape[j];
48  sOut *= outShape[j];
49  }
50 }
unsigned int GetNumDimensions()
Definition: Broadcast.hpp:20

Member Function Documentation

◆ GetNumDimensions()

unsigned int GetNumDimensions ( )
inline

Definition at line 20 of file Broadcast.hpp.

Referenced by BroadcastLoop::BroadcastLoop(), and BroadcastLoop::Unroll().

21  {
22  return static_cast<unsigned int>(m_DimData.size());
23  }

◆ Unroll() [1/2]

void Unroll ( Func  operationFunc,
unsigned int  dimension,
DecoderOp &  inData0,
DecoderOp &  inData1,
EncoderOp &  outData 
)
inline

Definition at line 26 of file Broadcast.hpp.

References BroadcastLoop::GetNumDimensions().

Referenced by ElementwiseBinaryFunction< Functor >::ElementwiseBinaryFunction(), ElementwiseUnaryFunction< Functor >::ElementwiseUnaryFunction(), armnn::PreluImpl(), and BroadcastLoop::Unroll().

31  {
32  if (dimension >= GetNumDimensions())
33  {
34  outData.Set(operationFunc(inData0.Get(), inData1.Get()));
35  return;
36  }
37 
38  unsigned int inData0Movement = 0;
39  unsigned int inData1Movement = 0;
40  unsigned int outDataMovement = 0;
41 
42  for (unsigned int i = 0; i < m_DimData[dimension].m_DimSize; i++)
43  {
44  Unroll(operationFunc, dimension + 1, inData0, inData1, outData);
45 
46  inData0 += m_DimData[dimension].m_Stride1;
47  inData1 += m_DimData[dimension].m_Stride2;
48  outData += m_DimData[dimension].m_StrideOut;
49 
50  inData0Movement += m_DimData[dimension].m_Stride1;
51  inData1Movement += m_DimData[dimension].m_Stride2;
52  outDataMovement += m_DimData[dimension].m_StrideOut;
53  }
54 
55  // move iterator back to the start
56  inData0 -= inData0Movement;
57  inData1 -= inData1Movement;
58  outData -= outDataMovement;
59  }
unsigned int GetNumDimensions()
Definition: Broadcast.hpp:20
void Unroll(Func operationFunc, unsigned int dimension, DecoderOp &inData0, DecoderOp &inData1, EncoderOp &outData)
Definition: Broadcast.hpp:26

◆ Unroll() [2/2]

void Unroll ( Func  operationFunc,
unsigned int  dimension,
DecoderOp &  inData,
EncoderOp &  outData 
)
inline

Definition at line 62 of file Broadcast.hpp.

References BroadcastLoop::GetNumDimensions(), and BroadcastLoop::Unroll().

66  {
67  if (dimension >= GetNumDimensions())
68  {
69  outData.Set(operationFunc(inData.Get()));
70  return;
71  }
72 
73  unsigned int inDataMovement = 0;
74  unsigned int outDataMovement = 0;
75 
76  for (unsigned int i = 0; i < m_DimData[dimension].m_DimSize; i++)
77  {
78  Unroll(operationFunc, dimension + 1, inData, outData);
79 
80  inData += m_DimData[dimension].m_Stride1;
81  outData += m_DimData[dimension].m_StrideOut;
82 
83  inDataMovement += m_DimData[dimension].m_Stride1;
84  outDataMovement += m_DimData[dimension].m_StrideOut;
85  }
86 
87  // move iterator back to the start
88  inData -= inDataMovement;
89  outData -= outDataMovement;
90  }
unsigned int GetNumDimensions()
Definition: Broadcast.hpp:20
void Unroll(Func operationFunc, unsigned int dimension, DecoderOp &inData0, DecoderOp &inData1, EncoderOp &outData)
Definition: Broadcast.hpp:26

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