ArmNN
 25.11
Loading...
Searching...
No Matches
Broadcast.cpp
Go to the documentation of this file.
1//
2// Copyright © 2019,2024 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "Broadcast.hpp"
7
8namespace armnn
9{
10
11BroadcastLoop::BroadcastLoop(const TensorShape& inShape0, const TensorShape& inShape1, const TensorShape& outShape)
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}
32
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}
69
70} // namespace armnn
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition Tensor.cpp:174
Copyright (c) 2021 ARM Limited and Contributors.
unsigned int GetNumDimensions()
Definition Broadcast.hpp:20
BroadcastLoop(const TensorShape &inShape0, const TensorShape &inShape1, const TensorShape &outShape)
Definition Broadcast.cpp:11