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