blob: 26309b080f5d165d29f6c2ce8b54ffbbecb82b15 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
6#pragma once
7
8#include "RefWorkloadUtils.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00009#include <backendsCommon/WorkloadData.hpp>
telsoa014fcda012018-03-09 14:13:49 +000010#include <armnn/Tensor.hpp>
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010011#include <armnn/utility/Assert.hpp>
telsoa014fcda012018-03-09 14:13:49 +000012
13namespace armnn
14{
15
16template <typename DataType>
17void Splitter(const SplitterQueueDescriptor& data)
18{
19 const TensorInfo& inputInfo0 = GetTensorInfo(data.m_Inputs[0]);
20
21 for (unsigned int index = 0; index < inputInfo0.GetNumElements(); ++index)
22 {
surmeh013537c2c2018-05-18 16:31:43 +010023 unsigned int indices[MaxNumOfTensorDimensions] = { 0 };
telsoa014fcda012018-03-09 14:13:49 +000024
25 unsigned int indexRemainder = index;
26 unsigned int dimensionStride = inputInfo0.GetNumElements();
27
28 for (unsigned int i = 0; i<inputInfo0.GetNumDimensions(); i++)
29 {
30 dimensionStride /= inputInfo0.GetShape()[i];
telsoa01c577f2c2018-08-31 09:22:23 +010031 indices[i] = indexRemainder / dimensionStride; // Use integer division to round down.
telsoa014fcda012018-03-09 14:13:49 +000032 indexRemainder -= indices[i] * dimensionStride;
33 }
34
35 for (unsigned int viewIdx = 0; viewIdx < data.m_ViewOrigins.size(); ++viewIdx)
36 {
37 SplitterQueueDescriptor::ViewOrigin const& view = data.m_ViewOrigins[viewIdx];
38
telsoa01c577f2c2018-08-31 09:22:23 +010039 //Split view extents are defined by the size of (the corresponding) input tensor.
telsoa014fcda012018-03-09 14:13:49 +000040 const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[viewIdx]);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010041 ARMNN_ASSERT(outputInfo.GetNumDimensions() == inputInfo0.GetNumDimensions());
telsoa014fcda012018-03-09 14:13:49 +000042
telsoa01c577f2c2018-08-31 09:22:23 +010043 // Check all dimensions to see if this element is inside the given input view.
telsoa014fcda012018-03-09 14:13:49 +000044 bool insideView = true;
45 for (unsigned int i = 0; i<outputInfo.GetNumDimensions(); i++)
46 {
47 if (indices[i] < view.m_Origin[i])
48 {
49 insideView = false;
50 }
51 if (indices[i] >= view.m_Origin[i] + outputInfo.GetShape()[i])
52 {
53 insideView = false;
54 }
55 }
56
57 if (insideView)
58 {
59 unsigned int outIndex = 0;
60 unsigned int dimensionStride = 1;
61
62 for (unsigned int i = outputInfo.GetNumDimensions(); i-- > 0;)
63 {
64 outIndex += dimensionStride * (indices[i] - view.m_Origin[i]);
65 dimensionStride *= outputInfo.GetShape()[i];
66 }
67
telsoa01c577f2c2018-08-31 09:22:23 +010068 //We are within the view, to copy input data to the output corresponding to this view.
telsoa014fcda012018-03-09 14:13:49 +000069 DataType* outputData = GetOutputTensorData<DataType>(viewIdx, data);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010070 ARMNN_ASSERT(outputData);
telsoa014fcda012018-03-09 14:13:49 +000071
72 const DataType* inputData = GetInputTensorData<DataType>(0, data);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010073 ARMNN_ASSERT(inputData);
telsoa014fcda012018-03-09 14:13:49 +000074
75 outputData[outIndex] = inputData[index];
76 }
77 }
78 }
79}
80
Ruomei Yan25339c32019-05-28 16:48:20 +010081void Split(const SplitterQueueDescriptor& data);
telsoa014fcda012018-03-09 14:13:49 +000082} //namespace armnn