blob: f2192f77c37ca84005229669deb04c1b02ad51f4 [file] [log] [blame]
Teresa Charlind5c0ed22022-04-25 18:23:41 +01001//
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
14namespace armnnDelegate
15{
16TfLiteStatus 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 Armagan90a119b2022-08-05 16:12:49 +010047 const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor, true);
Teresa Charlind5c0ed22022-04-25 18:23:41 +010048
Cathal Corbett53837672022-09-01 11:34:37 +010049 armnn::BackendId setBackend;
Teresa Charlind5c0ed22022-04-25 18:23:41 +010050 if (!delegateData.m_Network)
51 {
52 // Check if supported
53 bool isSupported = false;
54 FORWARD_LAYER_SUPPORT_FUNC("GATHER_ND",
55 tfLiteContext,
56 IsGatherNdSupported,
57 delegateData.m_Backends,
58 isSupported,
Cathal Corbett53837672022-09-01 11:34:37 +010059 setBackend,
Teresa Charlind5c0ed22022-04-25 18:23:41 +010060 inputTensorInfo,
61 indicesTensorInfo,
62 outputTensorInfo);
63 return isSupported ? kTfLiteOk : kTfLiteError;
64 }
65
66 armnn::IConnectableLayer* layer = delegateData.m_Network->AddGatherNdLayer();
Cathal Corbett53837672022-09-01 11:34:37 +010067 layer->SetBackendId(setBackend);
Teresa Charlind5c0ed22022-04-25 18:23:41 +010068 ARMNN_ASSERT(layer != nullptr);
69 layer->GetOutputSlot(0).SetTensorInfo(outputTensorInfo);
70
71 auto inputsTensorsProcess = ProcessInputs(layer,
72 delegateData,
73 tfLiteContext,
74 tfLiteNode);
75 if (inputsTensorsProcess == kTfLiteError)
76 {
77 return inputsTensorsProcess;
78 }
79
80 Connect(layer, tfLiteNode, delegateData);
81
82 return kTfLiteOk;
83}
84} // namespace armnnDelegate