ArmNN
 25.11
Loading...
Searching...
No Matches
Splitter.hpp
Go to the documentation of this file.
1//
2// Copyright © 2017, 2024 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
10#include <armnn/Tensor.hpp>
12
13namespace armnn
14{
15
16template <typename DataType>
18 std::vector<ITensorHandle*> inputs,
19 std::vector<ITensorHandle*> outputs)
20{
21 const TensorInfo& inputInfo0 = GetTensorInfo(inputs[0]);
22
23 for (unsigned int index = 0; index < inputInfo0.GetNumElements(); ++index)
24 {
25 unsigned int indices[MaxNumOfTensorDimensions] = { 0 };
26
27 unsigned int indexRemainder = index;
28 unsigned int dimensionStride = inputInfo0.GetNumElements();
29
30 for (unsigned int i = 0; i<inputInfo0.GetNumDimensions(); i++)
31 {
32 dimensionStride /= inputInfo0.GetShape()[i];
33 indices[i] = indexRemainder / dimensionStride; // Use integer division to round down.
34 indexRemainder -= indices[i] * dimensionStride;
35 }
36
37 for (unsigned int viewIdx = 0; viewIdx < data.m_ViewOrigins.size(); ++viewIdx)
38 {
39 SplitterQueueDescriptor::ViewOrigin const& view = data.m_ViewOrigins[viewIdx];
40
41 //Split view extents are defined by the size of (the corresponding) input tensor.
42 const TensorInfo& outputInfo = GetTensorInfo(outputs[viewIdx]);
44 outputInfo.GetNumDimensions() == inputInfo0.GetNumDimensions(),
45 "The number of output dimensions does not match the number of input dimensions.");
46
47 // Check all dimensions to see if this element is inside the given input view.
48 bool insideView = true;
49 for (unsigned int i = 0; i<outputInfo.GetNumDimensions(); i++)
50 {
51 if (indices[i] < view.m_Origin[i])
52 {
53 insideView = false;
54 }
55 if (indices[i] >= view.m_Origin[i] + outputInfo.GetShape()[i])
56 {
57 insideView = false;
58 }
59 }
60
61 if (insideView)
62 {
63 unsigned int outIndex = 0;
64 unsigned int dimensionStride = 1;
65
66 for (unsigned int i = outputInfo.GetNumDimensions(); i-- > 0;)
67 {
68 outIndex += dimensionStride * (indices[i] - view.m_Origin[i]);
69 dimensionStride *= outputInfo.GetShape()[i];
70 }
71
72 //We are within the view, to copy input data to the output corresponding to this view.
73 DataType* outputData = GetOutputTensorData<DataType>(viewIdx, data);
74 const DataType* inputData = GetInputTensorData<DataType>(0, data);
75 outputData[outIndex] = inputData[index];
76 }
77 }
78 }
79}
80
81void Split(const SplitterQueueDescriptor& data,
82 std::vector<ITensorHandle*> inputs,
83 std::vector<ITensorHandle*> outputs);
84} //namespace armnn
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
const TensorShape & GetShape() const
Definition Tensor.hpp:193
unsigned int GetNumDimensions() const
Definition Tensor.hpp:197
unsigned int GetNumElements() const
Definition Tensor.hpp:198
Copyright (c) 2021 ARM Limited and Contributors.
void Split(const SplitterQueueDescriptor &data, std::vector< ITensorHandle * > inputs, std::vector< ITensorHandle * > outputs)
Definition Splitter.cpp:20
const DataType * GetInputTensorData(unsigned int idx, const PayloadType &data)
constexpr unsigned int MaxNumOfTensorDimensions
Definition Types.hpp:31
DataType
Definition Types.hpp:49
DataType * GetOutputTensorData(unsigned int idx, const PayloadType &data)
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
std::vector< ViewOrigin > m_ViewOrigins