2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
8 #include "RefWorkloadUtils.hpp"
10 #include <backends/WorkloadData.hpp>
11 #include <armnn/Tensor.hpp>
13 #include <boost/assert.hpp>
18 template <typename DataType>
19 void Splitter(const SplitterQueueDescriptor& data)
21 const TensorInfo& inputInfo0 = GetTensorInfo(data.m_Inputs[0]);
23 for (unsigned int index = 0; index < inputInfo0.GetNumElements(); ++index)
25 unsigned int indices[MaxNumOfTensorDimensions] = { 0 };
27 unsigned int indexRemainder = index;
28 unsigned int dimensionStride = inputInfo0.GetNumElements();
30 for (unsigned int i = 0; i<inputInfo0.GetNumDimensions(); i++)
32 dimensionStride /= inputInfo0.GetShape()[i];
33 indices[i] = indexRemainder / dimensionStride; // Use integer division to round down.
34 indexRemainder -= indices[i] * dimensionStride;
37 for (unsigned int viewIdx = 0; viewIdx < data.m_ViewOrigins.size(); ++viewIdx)
39 SplitterQueueDescriptor::ViewOrigin const& view = data.m_ViewOrigins[viewIdx];
41 //Split view extents are defined by the size of (the corresponding) input tensor.
42 const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[viewIdx]);
43 BOOST_ASSERT(outputInfo.GetNumDimensions() == inputInfo0.GetNumDimensions());
45 // Check all dimensions to see if this element is inside the given input view.
46 bool insideView = true;
47 for (unsigned int i = 0; i<outputInfo.GetNumDimensions(); i++)
49 if (indices[i] < view.m_Origin[i])
53 if (indices[i] >= view.m_Origin[i] + outputInfo.GetShape()[i])
61 unsigned int outIndex = 0;
62 unsigned int dimensionStride = 1;
64 for (unsigned int i = outputInfo.GetNumDimensions(); i-- > 0;)
66 outIndex += dimensionStride * (indices[i] - view.m_Origin[i]);
67 dimensionStride *= outputInfo.GetShape()[i];
70 //We are within the view, to copy input data to the output corresponding to this view.
71 DataType* outputData = GetOutputTensorData<DataType>(viewIdx, data);
72 BOOST_ASSERT(outputData);
74 const DataType* inputData = GetInputTensorData<DataType>(0, data);
75 BOOST_ASSERT(inputData);
77 outputData[outIndex] = inputData[index];