narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1 | // |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 2 | // Copyright © 2019-2023 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 "RefGatherWorkload.hpp" |
| 7 | |
| 8 | #include "Gather.hpp" |
| 9 | #include "Profiling.hpp" |
| 10 | #include "RefWorkloadUtils.hpp" |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 11 | #include <ResolveType.hpp> |
Ciara Sookarry | abd3c21 | 2023-10-11 17:04:04 +0100 | [diff] [blame] | 12 | #include <fmt/format.h> |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 17 | void RefGatherWorkload::Execute() const |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 18 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 19 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
| 20 | } |
| 21 | |
Matthew Sloyan | 2d213a7 | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 22 | void RefGatherWorkload::ExecuteAsync(ExecutionData& executionData) |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 23 | { |
Matthew Sloyan | 2d213a7 | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 24 | WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data); |
| 25 | Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs); |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void RefGatherWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const |
| 29 | { |
Mike Kelly | 7cbe781 | 2023-07-25 17:37:33 +0100 | [diff] [blame] | 30 | ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefGatherWorkload_Execute"); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 31 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 32 | const TensorInfo& inputInfo0 = GetTensorInfo(inputs[0]); |
| 33 | const TensorInfo& inputInfo1 = GetTensorInfo(inputs[1]); |
| 34 | const TensorInfo& outputInfo = GetTensorInfo(outputs[0]); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 35 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 36 | std::unique_ptr<Decoder<float>> decoderPtr = MakeDecoder<float>(inputInfo0, inputs[0]->Map()); |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 37 | Decoder<float>& decoder = *decoderPtr; |
| 38 | |
Finn Williams | 0109794 | 2021-04-26 12:06:34 +0100 | [diff] [blame] | 39 | const int32_t* indicesData = reinterpret_cast<int32_t*>(inputs[1]->Map()); |
Ciara Sookarry | abd3c21 | 2023-10-11 17:04:04 +0100 | [diff] [blame] | 40 | // Check for negative indices, it could not be checked in validate as we do not have access to the values there |
| 41 | for (unsigned int i = 0; i < inputInfo1.GetNumElements(); ++i) |
| 42 | { |
| 43 | if (indicesData[i] < 0) |
| 44 | { |
| 45 | throw InvalidArgumentException((fmt::format("Gather: indices[{}] < 0", i))); |
| 46 | } |
| 47 | } |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 48 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 49 | std::unique_ptr<Encoder<float>> encoderPtr = MakeEncoder<float>(outputInfo, outputs[0]->Map()); |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 50 | Encoder<float>& encoder = *encoderPtr; |
| 51 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 52 | Gather(inputInfo0, inputInfo1, outputInfo, decoder, indicesData, encoder, m_Data.m_Parameters.m_Axis); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 53 | } |
| 54 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 55 | } //namespace armnn |