narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "Gather.hpp" |
| 7 | |
| 8 | #include "RefWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <backendsCommon/WorkloadData.hpp> |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 11 | #include <armnn/utility/IgnoreUnused.hpp> |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 12 | #include <armnn/utility/NumericCast.hpp> |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 13 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 17 | void Gather(const TensorInfo& paramsInfo, |
| 18 | const TensorInfo& indicesInfo, |
| 19 | const TensorInfo& outputInfo, |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 20 | Decoder<float>& params, |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 21 | const int32_t* indices, |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 22 | Encoder<float>& output, |
| 23 | const int32_t axis) |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 24 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 25 | IgnoreUnused(outputInfo); |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 26 | IgnoreUnused(axis); |
| 27 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 28 | const TensorShape& paramsShape = paramsInfo.GetShape(); |
| 29 | |
| 30 | unsigned int paramsProduct = 1; |
| 31 | for (unsigned int i = 1; i < paramsInfo.GetNumDimensions(); ++i) |
| 32 | { |
| 33 | paramsProduct = paramsProduct * paramsShape[i]; |
| 34 | } |
| 35 | |
| 36 | unsigned int outIndex = 0; |
| 37 | for (unsigned int i = 0; i < indicesInfo.GetNumElements(); ++i) |
| 38 | { |
Matthew Sloyan | 171214c | 2020-09-09 09:07:37 +0100 | [diff] [blame] | 39 | unsigned int indx = armnn::numeric_cast<unsigned int>(indices[i]); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 40 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 41 | ARMNN_ASSERT(indices[i] >= 0 && indx < paramsShape[0]); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 42 | |
| 43 | unsigned int startOffset = indx * paramsProduct; |
| 44 | unsigned int endOffset = startOffset + paramsProduct; |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 45 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 46 | for (unsigned int j = startOffset; j < endOffset; ++j) |
| 47 | { |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 48 | params[j]; |
| 49 | float outputValue = params.Get(); |
| 50 | output[outIndex]; |
| 51 | output.Set(outputValue); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 52 | ++outIndex; |
| 53 | } |
| 54 | } |
| 55 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 56 | ARMNN_ASSERT(outIndex == outputInfo.GetNumElements()); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 57 | } |
| 58 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 59 | } //namespace armnn |