telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "RefWorkloadUtils.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | #include <backendsCommon/WorkloadData.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include <armnn/Tensor.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | #include <boost/assert.hpp> |
| 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | template <typename DataType> |
| 17 | void 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 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 23 | unsigned int indices[MaxNumOfTensorDimensions] = { 0 }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | |
| 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]; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 31 | indices[i] = indexRemainder / dimensionStride; // Use integer division to round down. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | 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 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 39 | //Split view extents are defined by the size of (the corresponding) input tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 40 | const TensorInfo& outputInfo = GetTensorInfo(data.m_Outputs[viewIdx]); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 41 | BOOST_ASSERT(outputInfo.GetNumDimensions() == inputInfo0.GetNumDimensions()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 42 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 43 | // Check all dimensions to see if this element is inside the given input view. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 44 | 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 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 68 | //We are within the view, to copy input data to the output corresponding to this view. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | DataType* outputData = GetOutputTensorData<DataType>(viewIdx, data); |
| 70 | BOOST_ASSERT(outputData); |
| 71 | |
| 72 | const DataType* inputData = GetInputTensorData<DataType>(0, data); |
| 73 | BOOST_ASSERT(inputData); |
| 74 | |
| 75 | outputData[outIndex] = inputData[index]; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
Ruomei Yan | 25339c3 | 2019-05-28 16:48:20 +0100 | [diff] [blame] | 81 | void Split(const SplitterQueueDescriptor& data); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | } //namespace armnn |