2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
8 #include "RefWorkloadUtils.hpp"
10 #include <backendsCommon/WorkloadData.hpp>
11 #include <armnn/Tensor.hpp>
16 template <typename DataType>
17 void Merger(const MergerQueueDescriptor& data)
19 const TensorInfo& outputInfo0 = GetTensorInfo(data.m_Outputs[0]);
21 for (unsigned int index = 0 ; index < outputInfo0.GetNumElements(); ++index)
23 unsigned int indices[MaxNumOfTensorDimensions] = { 0 };
25 unsigned int indexRemainder = index;
26 unsigned int dimensionStride = outputInfo0.GetNumElements();
28 for (unsigned int i=0; i<outputInfo0.GetNumDimensions(); i++)
30 dimensionStride /= outputInfo0.GetShape()[i];
31 indices[i] = indexRemainder / dimensionStride; // Use integer division to round down.
32 indexRemainder -= indices[i] * dimensionStride;
35 for (unsigned int viewIdx = 0; viewIdx < data.m_ViewOrigins.size(); ++viewIdx)
37 MergerQueueDescriptor::ViewOrigin const& view = data.m_ViewOrigins[viewIdx];
39 //Split view extents are defined by the size of (the corresponding) input tensor.
40 const TensorInfo& inputInfo = GetTensorInfo(data.m_Inputs[viewIdx]);
41 BOOST_ASSERT(inputInfo.GetNumDimensions() == outputInfo0.GetNumDimensions());
43 // Check all dimensions to see if this element is inside the given input view.
44 bool insideView = true;
45 for (unsigned int i=0; i<inputInfo.GetNumDimensions(); i++)
47 if (indices[i] < view.m_Origin[i])
51 if (indices[i] >= view.m_Origin[i] + inputInfo.GetShape()[i])
59 unsigned int inIndex = 0;
60 unsigned int dimensionStride = 1;
62 for (unsigned int i = inputInfo.GetNumDimensions(); i-- > 0;)
64 inIndex += dimensionStride * (indices[i] - view.m_Origin[i]);
65 dimensionStride *= inputInfo.GetShape()[i];
68 //We are within the view, copy input data to the output corresponding to this view.
69 (GetOutputTensorData<DataType>(0, data))[index] =
70 (GetInputTensorData<DataType>(viewIdx, data))[inIndex];
72 //What should we do if input views overlap on the output tensor?
73 //We could error, take the average, or shm else...
74 //For now just stop after finding first view (input) that matches.