Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 8 | #include "SharedFunctions.hpp" |
| 9 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 10 | #include <tensorflow/lite/builtin_ops.h> |
| 11 | #include <tensorflow/lite/c/builtin_op_data.h> |
| 12 | #include <tensorflow/lite/c/common.h> |
| 13 | #include <tensorflow/lite/minimal_logging.h> |
| 14 | |
| 15 | namespace armnnDelegate |
| 16 | { |
| 17 | |
| 18 | TfLiteStatus VisitFloorOperator(DelegateData& delegateData, |
| 19 | TfLiteContext* tfLiteContext, |
| 20 | TfLiteNode* tfLiteNode, |
| 21 | int nodeIndex, |
| 22 | int32_t operatorCode) |
| 23 | { |
Sadik Armagan | 788e2c6 | 2021-02-10 16:26:44 +0000 | [diff] [blame] | 24 | TF_LITE_ENSURE_STATUS(ValidateNumInputs(tfLiteContext, tfLiteNode, 1, nodeIndex)); |
| 25 | TF_LITE_ENSURE_STATUS(ValidateNumOutputs(tfLiteContext, tfLiteNode, 1, nodeIndex)); |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 26 | |
Sadik Armagan | 788e2c6 | 2021-02-10 16:26:44 +0000 | [diff] [blame] | 27 | const TfLiteTensor* tfLiteTensors = tfLiteContext->tensors; |
| 28 | const TfLiteTensor& tfLiteInputTensor = tfLiteTensors[tfLiteNode->inputs->data[0]]; |
| 29 | if (!IsValid(tfLiteContext, tfLiteInputTensor, operatorCode, nodeIndex)) |
| 30 | { |
| 31 | return kTfLiteError; |
| 32 | } |
| 33 | |
| 34 | const TfLiteTensor& tfLiteOutputTensor = tfLiteTensors[tfLiteNode->outputs->data[0]]; |
| 35 | if (!IsValid(tfLiteContext, tfLiteOutputTensor, operatorCode, nodeIndex)) |
| 36 | { |
| 37 | return kTfLiteError; |
| 38 | } |
| 39 | |
| 40 | const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor); |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 41 | // NOTE: looks like the outputTensorInfo is the only thing that is required for the case |
| 42 | // where we are adding the floor layer so maybe move the other stuff inside the |
| 43 | // if !delegateData block for efficiency. |
Sadik Armagan | 788e2c6 | 2021-02-10 16:26:44 +0000 | [diff] [blame] | 44 | const armnn::TensorInfo& outputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteOutputTensor); |
| 45 | |
Sadik Armagan | 788e2c6 | 2021-02-10 16:26:44 +0000 | [diff] [blame] | 46 | // If the m_Network is a nullptr, this signals that a prerequisite TfLite callback is required to clarify the |
| 47 | // support for the operator |
| 48 | // If supported, VisitFloorOperator will be called again to add the layer to the network as seen further below |
| 49 | if (!delegateData.m_Network) |
| 50 | { |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 51 | return ValidateFloorOperator(delegateData, tfLiteContext, inputTensorInfo, outputTensorInfo); |
Sadik Armagan | 788e2c6 | 2021-02-10 16:26:44 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // Add a Floor layer |
| 55 | armnn::IConnectableLayer* layer = delegateData.m_Network->AddFloorLayer(); |
| 56 | ARMNN_ASSERT(layer != nullptr); |
| 57 | |
| 58 | armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0); |
| 59 | outputSlot.SetTensorInfo(outputTensorInfo); |
| 60 | |
| 61 | // Connect |
| 62 | return Connect(layer, tfLiteNode, delegateData); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace armnnDelegate |