Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 1 | // |
Ryan OShea | 3ad2e14 | 2023-01-13 10:19:20 +0000 | [diff] [blame] | 2 | // Copyright © 2021-2023 Arm Ltd and Contributors. All rights reserved. |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | |
| 7 | #include "SharedFunctions.hpp" |
| 8 | |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 9 | #include <DelegateUtils.hpp> |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 10 | |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 11 | #include "tensorflow/lite/builtin_ops.h" |
| 12 | #include "tensorflow/lite/c/builtin_op_data.h" |
| 13 | #include "tensorflow/lite/c/common.h" |
| 14 | #include "tensorflow/lite/minimal_logging.h" |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 15 | |
| 16 | namespace armnnDelegate |
| 17 | { |
| 18 | |
| 19 | TfLiteStatus ValidateFloorOperator(DelegateData& delegateData, |
| 20 | TfLiteContext* tfLiteContext, |
| 21 | const armnn::TensorInfo& inputTensorInfo, |
| 22 | const armnn::TensorInfo& outputTensorInfo) |
| 23 | { |
| 24 | bool isSupported = false; |
| 25 | auto validateFunc = [&](const armnn::TensorInfo& outInfo, bool& isSupported) |
| 26 | { |
Sadik Armagan | bfa767c | 2022-02-09 14:58:03 +0000 | [diff] [blame] | 27 | FORWARD_LAYER_SUPPORT_FUNC("FLOOR", |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 28 | tfLiteContext, |
| 29 | IsFloorSupported, |
| 30 | delegateData.m_Backends, |
| 31 | isSupported, |
Cathal Corbett | 5383767 | 2022-09-01 11:34:37 +0100 | [diff] [blame] | 32 | armnn::BackendId(), |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 33 | inputTensorInfo, |
| 34 | outInfo); |
| 35 | }; |
| 36 | validateFunc(outputTensorInfo, isSupported); |
| 37 | return isSupported ? kTfLiteOk : kTfLiteError; |
| 38 | } |
| 39 | |
Ryan OShea | 3ad2e14 | 2023-01-13 10:19:20 +0000 | [diff] [blame] | 40 | TfLiteStatus ValidateFusedActivationOperator(DelegateData& delegateData, |
| 41 | TfLiteContext* tfLiteContext, |
| 42 | const armnn::TensorInfo& inputInfo, |
| 43 | const armnn::TensorInfo& outputInfo, |
| 44 | TfLiteFusedActivation activationType) |
| 45 | { |
| 46 | armnn::ActivationDescriptor activationDesc; |
| 47 | |
| 48 | switch (activationType) |
| 49 | { |
| 50 | case kTfLiteActNone: |
| 51 | { |
| 52 | // No Activation |
| 53 | return kTfLiteOk; |
| 54 | } |
| 55 | case kTfLiteActRelu: |
| 56 | { |
| 57 | activationDesc.m_Function = armnn::ActivationFunction::ReLu; |
| 58 | break; |
| 59 | } |
| 60 | // The name of kTfLiteActRelu1 changed after TF Lite v2.3 |
| 61 | #if defined(ARMNN_POST_TFLITE_2_3) |
| 62 | case kTfLiteActReluN1To1: |
| 63 | #else |
| 64 | case kTfLiteActRelu1: |
| 65 | #endif |
| 66 | { |
| 67 | activationDesc.m_Function = armnn::ActivationFunction::BoundedReLu; |
| 68 | activationDesc.m_A = 1.0f; |
| 69 | activationDesc.m_B = -1.0f; |
| 70 | break; |
| 71 | } |
| 72 | case kTfLiteActRelu6: |
| 73 | { |
| 74 | activationDesc.m_Function = armnn::ActivationFunction::BoundedReLu; |
| 75 | activationDesc.m_A = 6.0f; |
| 76 | activationDesc.m_B = 0.0f; |
| 77 | break; |
| 78 | } |
| 79 | case kTfLiteActSigmoid: |
| 80 | { |
| 81 | activationDesc.m_Function = armnn::ActivationFunction::Sigmoid; |
| 82 | break; |
| 83 | } |
| 84 | case kTfLiteActTanh: |
| 85 | { |
| 86 | activationDesc.m_Function = armnn::ActivationFunction::TanH; |
| 87 | activationDesc.m_A = 1.0f; |
| 88 | activationDesc.m_B = 1.0f; |
| 89 | break; |
| 90 | } |
| 91 | default: |
| 92 | return kTfLiteError; |
| 93 | } |
| 94 | |
| 95 | bool isSupported = false; |
| 96 | armnn::BackendId setBackend; |
| 97 | |
| 98 | auto validateFunc = [&](const armnn::TensorInfo& outputInfo, bool& isSupported) |
| 99 | { |
| 100 | FORWARD_LAYER_SUPPORT_FUNC("ACTIVATION", |
| 101 | tfLiteContext, |
| 102 | IsActivationSupported, |
| 103 | delegateData.m_Backends, |
| 104 | isSupported, |
| 105 | armnn::BackendId(), |
| 106 | inputInfo, |
| 107 | outputInfo, |
| 108 | activationDesc); |
| 109 | }; |
| 110 | validateFunc(outputInfo, isSupported); |
| 111 | return isSupported ? kTfLiteOk : kTfLiteError; |
| 112 | } |
| 113 | |
| 114 | |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 115 | } // namespace armnnDelegate |
| 116 | |