Teresa Charlin | d5c0ed2 | 2022-04-25 18:23:41 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "DelegateUtils.hpp" |
| 9 | #include <algorithm> |
| 10 | #include <iterator> |
| 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
| 14 | namespace armnnDelegate |
| 15 | { |
| 16 | TfLiteStatus VisitGatherNdOperator(DelegateData& delegateData, |
| 17 | TfLiteContext* tfLiteContext, |
| 18 | TfLiteNode* tfLiteNode, |
| 19 | int nodeIndex, |
| 20 | int32_t operatorCode) |
| 21 | { |
| 22 | TF_LITE_ENSURE_STATUS(ValidateNumInputs(tfLiteContext, tfLiteNode, 2, nodeIndex)); |
| 23 | TF_LITE_ENSURE_STATUS(ValidateNumOutputs(tfLiteContext, tfLiteNode, 1, nodeIndex)); |
| 24 | |
| 25 | const TfLiteTensor* tfLiteTensors = tfLiteContext->tensors; |
| 26 | |
| 27 | const TfLiteTensor& tfLiteInputTensor = tfLiteTensors[tfLiteNode->inputs->data[0]]; |
| 28 | if (!IsValid(tfLiteContext, tfLiteInputTensor, operatorCode, nodeIndex)) |
| 29 | { |
| 30 | return kTfLiteError; |
| 31 | } |
| 32 | |
| 33 | const TfLiteTensor& tfLiteIndicesTensor = tfLiteTensors[tfLiteNode->inputs->data[1]]; |
| 34 | if (!IsValid(tfLiteContext, tfLiteIndicesTensor, operatorCode, nodeIndex)) |
| 35 | { |
| 36 | return kTfLiteError; |
| 37 | } |
| 38 | |
| 39 | const TfLiteTensor& tfLiteOutputTensor = tfLiteTensors[tfLiteNode->outputs->data[0]]; |
| 40 | if (!IsValid(tfLiteContext, tfLiteOutputTensor, operatorCode, nodeIndex)) |
| 41 | { |
| 42 | return kTfLiteError; |
| 43 | } |
| 44 | |
| 45 | const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor); |
| 46 | const armnn::TensorInfo& indicesTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteIndicesTensor); |
Sadik Armagan | 90a119b | 2022-08-05 16:12:49 +0100 | [diff] [blame] | 47 | const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor, true); |
Teresa Charlin | d5c0ed2 | 2022-04-25 18:23:41 +0100 | [diff] [blame] | 48 | |
| 49 | if (!delegateData.m_Network) |
| 50 | { |
| 51 | // Check if supported |
| 52 | bool isSupported = false; |
| 53 | FORWARD_LAYER_SUPPORT_FUNC("GATHER_ND", |
| 54 | tfLiteContext, |
| 55 | IsGatherNdSupported, |
| 56 | delegateData.m_Backends, |
| 57 | isSupported, |
| 58 | inputTensorInfo, |
| 59 | indicesTensorInfo, |
| 60 | outputTensorInfo); |
| 61 | return isSupported ? kTfLiteOk : kTfLiteError; |
| 62 | } |
| 63 | |
| 64 | armnn::IConnectableLayer* layer = delegateData.m_Network->AddGatherNdLayer(); |
| 65 | ARMNN_ASSERT(layer != nullptr); |
| 66 | layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 67 | |
| 68 | auto inputsTensorsProcess = ProcessInputs(layer, |
| 69 | delegateData, |
| 70 | tfLiteContext, |
| 71 | tfLiteNode); |
| 72 | if (inputsTensorsProcess == kTfLiteError) |
| 73 | { |
| 74 | return inputsTensorsProcess; |
| 75 | } |
| 76 | |
| 77 | Connect(layer, tfLiteNode, delegateData); |
| 78 | |
| 79 | return kTfLiteOk; |
| 80 | } |
| 81 | } // namespace armnnDelegate |