blob: 1677607571816c613490ccf570cc37a3a755a4fa [file] [log] [blame]
Sadik Armagan62483be2020-10-23 17:14:43 +01001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include <tensorflow/lite/builtin_ops.h>
9#include <tensorflow/lite/c/builtin_op_data.h>
10#include <tensorflow/lite/c/common.h>
11#include <tensorflow/lite/minimal_logging.h>
12
13namespace armnnDelegate
14{
15
16TfLiteStatus VisitFloorOperator(DelegateData& delegateData,
17 TfLiteContext* tfLiteContext,
18 TfLiteNode* tfLiteNode,
19 int nodeIndex,
20 int32_t operatorCode)
21{
Sadik Armagan788e2c62021-02-10 16:26:44 +000022 TF_LITE_ENSURE_STATUS(ValidateNumInputs(tfLiteContext, tfLiteNode, 1, nodeIndex));
23 TF_LITE_ENSURE_STATUS(ValidateNumOutputs(tfLiteContext, tfLiteNode, 1, nodeIndex));
Finn Williams6f9f9902020-11-13 13:23:15 +000024
Sadik Armagan788e2c62021-02-10 16:26:44 +000025 const TfLiteTensor* tfLiteTensors = tfLiteContext->tensors;
26 const TfLiteTensor& tfLiteInputTensor = tfLiteTensors[tfLiteNode->inputs->data[0]];
27 if (!IsValid(tfLiteContext, tfLiteInputTensor, operatorCode, nodeIndex))
28 {
29 return kTfLiteError;
30 }
31
32 const TfLiteTensor& tfLiteOutputTensor = tfLiteTensors[tfLiteNode->outputs->data[0]];
33 if (!IsValid(tfLiteContext, tfLiteOutputTensor, operatorCode, nodeIndex))
34 {
35 return kTfLiteError;
36 }
37
38 const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
39 const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor);
40
41 bool isSupported = false;
42 auto validateFunc = [&](const armnn::TensorInfo& outInfo, bool& isSupported)
43 {
44 FORWARD_LAYER_SUPPORT_FUNC(__func__,
45 tfLiteContext,
46 IsFloorSupported,
47 delegateData.m_Backends,
48 isSupported,
49 inputTensorInfo,
50 outInfo);
51 };
52
53 // If the m_Network is a nullptr, this signals that a prerequisite TfLite callback is required to clarify the
54 // support for the operator
55 // If supported, VisitFloorOperator will be called again to add the layer to the network as seen further below
56 if (!delegateData.m_Network)
57 {
58 validateFunc(outputTensorInfo, isSupported);
59 return isSupported ? kTfLiteOk : kTfLiteError;
60 }
61
62 // Add a Floor layer
63 armnn::IConnectableLayer* layer = delegateData.m_Network->AddFloorLayer();
64 ARMNN_ASSERT(layer != nullptr);
65
66 armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
67 outputSlot.SetTensorInfo(outputTensorInfo);
68
69 // Connect
70 return Connect(layer, tfLiteNode, delegateData);
Sadik Armagan62483be2020-10-23 17:14:43 +010071}
72
73} // namespace armnnDelegate