ArmNN
 25.11
Loading...
Searching...
No Matches
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.

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}

References GetNumDimensions().

◆ BroadcastLoop() [2/2]

BroadcastLoop ( const TensorShape & inShape,
const TensorShape & outShape )

Definition at line 33 of file Broadcast.cpp.

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 // Get the difference between the output dimension and input dimension
42 const unsigned int dimDifference = numDims - inShape.GetNumDimensions();
43
44 for (unsigned int j = numDims - 1, k = 0; k < numDims ; k++, j--)
45 {
46
47 m_DimData[j].m_DimSize = outShape[j];
48 // Pretend there are extra 1-dimensional tensors prepended
49 if (dimDifference > 0 && j < dimDifference)
50 {
51 m_DimData[j].m_Stride1 = 0;
52 sIn *= 1;
53 }
54 else if (dimDifference > 0)
55 {
56 m_DimData[j].m_Stride1 = (inShape[j - dimDifference] > 1) ? sIn : 0;
57 sIn *= inShape[j - dimDifference];
58 }
59 else
60 {
61 m_DimData[j].m_Stride1 = (inShape[j] > 1) ? sIn : 0;
62 sIn *= inShape[j];
63 }
64 m_DimData[j].m_StrideOut = sOut;
65
66 sOut *= outShape[j];
67 }
68}

References GetNumDimensions(), and TensorShape::GetNumDimensions().

Member Function Documentation

◆ GetNumDimensions()

unsigned int GetNumDimensions ( )
inline

Definition at line 20 of file Broadcast.hpp.

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

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

◆ Unroll() [1/2]

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

Definition at line 62 of file Broadcast.hpp.

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 }

References GetNumDimensions(), and Unroll().

◆ Unroll() [2/2]

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

Definition at line 26 of file Broadcast.hpp.

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 }

References GetNumDimensions(), and Unroll().

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


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