Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 6 | #include "Concatenate.hpp" |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 7 | #include "RefWorkloadUtils.hpp" |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 8 | #include "Decoders.hpp" |
| 9 | #include "Encoders.hpp" |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 14 | void Concatenate(const ConcatQueueDescriptor &data) |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 15 | { |
| 16 | const TensorInfo& outputInfo0 = GetTensorInfo(data.m_Outputs[0]); |
| 17 | |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 18 | std::unique_ptr<Encoder<float>> encoderPtr = MakeEncoder<float>(outputInfo0, data.m_Outputs[0]->Map()); |
| 19 | Encoder<float>& encoder = *encoderPtr; |
| 20 | |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 21 | for (unsigned int index = 0 ; index < outputInfo0.GetNumElements(); ++index) |
| 22 | { |
| 23 | unsigned int indices[MaxNumOfTensorDimensions] = { 0 }; |
| 24 | |
| 25 | unsigned int indexRemainder = index; |
| 26 | unsigned int dimensionStride = outputInfo0.GetNumElements(); |
| 27 | |
| 28 | for (unsigned int i = 0; i < outputInfo0.GetNumDimensions(); i++) |
| 29 | { |
| 30 | dimensionStride /= outputInfo0.GetShape()[i]; |
| 31 | indices[i] = indexRemainder / dimensionStride; // Use integer division to round down. |
| 32 | indexRemainder -= indices[i] * dimensionStride; |
| 33 | } |
| 34 | |
| 35 | for (unsigned int viewIdx = 0; viewIdx < data.m_ViewOrigins.size(); ++viewIdx) |
| 36 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 37 | ConcatQueueDescriptor::ViewOrigin const& view = data.m_ViewOrigins[viewIdx]; |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 38 | |
| 39 | //Split view extents are defined by the size of (the corresponding) input tensor. |
| 40 | const TensorInfo& inputInfo = GetTensorInfo(data.m_Inputs[viewIdx]); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 41 | ARMNN_ASSERT(inputInfo.GetNumDimensions() == outputInfo0.GetNumDimensions()); |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 42 | |
| 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++) |
| 46 | { |
| 47 | if (indices[i] < view.m_Origin[i]) |
| 48 | { |
| 49 | insideView = false; |
| 50 | } |
| 51 | if (indices[i] >= view.m_Origin[i] + inputInfo.GetShape()[i]) |
| 52 | { |
| 53 | insideView = false; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (insideView) |
| 58 | { |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 59 | std::unique_ptr<Decoder<float>> decoderPtr = |
| 60 | MakeDecoder<float>(inputInfo, data.m_Inputs[viewIdx]->Map()); |
| 61 | Decoder<float>& decoder = *decoderPtr; |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 62 | unsigned int inIndex = 0; |
| 63 | unsigned int dimensionStride = 1; |
| 64 | |
| 65 | for (unsigned int i = inputInfo.GetNumDimensions(); i-- > 0;) |
| 66 | { |
| 67 | inIndex += dimensionStride * (indices[i] - view.m_Origin[i]); |
| 68 | dimensionStride *= inputInfo.GetShape()[i]; |
| 69 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 70 | decoder += inIndex; |
| 71 | encoder.Set(decoder.Get()); |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 72 | |
| 73 | //What should we do if input views overlap on the output tensor? |
| 74 | //We could error, take the average, or shm else... |
| 75 | //For now just stop after finding first view (input) that matches. |
| 76 | break; |
| 77 | } |
| 78 | } |
Jim Flynn | cbb66aa | 2019-05-15 13:03:54 +0100 | [diff] [blame] | 79 | ++encoder; |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Ferran Balaguer | b284565 | 2019-02-27 09:42:06 +0000 | [diff] [blame] | 83 | } //namespace armnn |