1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATIONS_H_
17 #define TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATIONS_H_
18 
19 #include <cstdint>
20 
21 #include "tensorflow/lite/c/builtin_op_data.h"
22 #include "tensorflow/lite/c/common.h"
23 #include "tensorflow/lite/kernels/internal/types.h"
24 
25 namespace tflite {
26 
27 extern const int kActivationsInputTensor;
28 extern const int kActivationsOutputTensor;
29 
30 struct ReluOpData {
31   ReluParams params;
32 };
33 
34 struct Relu6OpData {
35   int8_t six_int8;
36   int8_t zero_int8;
37 };
38 
39 void ReluQuantized(const ReluOpData& data, const RuntimeShape& input_shape,
40                    const RuntimeShape& output_shape, const int8_t* input_data,
41                    int8_t* output_data);
42 
43 template <typename T>
44 void CalculateReluOpData(const TfLiteTensor* input, TfLiteTensor* output,
45                          ReluOpData* data);
46 
47 void ReluFloat(const RuntimeShape& input_shape, const float* input_data,
48                const RuntimeShape& output_shape, float* output_data);
49 
50 void Relu6Float(const RuntimeShape& input_shape, const float* input_data,
51                 const RuntimeShape& output_shape, float* output_data);
52 
53 void Relu6Quantized(int8_t lower, int8_t upper, const RuntimeShape& input_shape,
54                     const int8_t* input_data, const RuntimeShape& output_shape,
55                     int8_t* output_data);
56 
57 TfLiteStatus ReluPrepare(TfLiteContext* context, TfLiteNode* node);
58 
59 TfLiteStatus Relu6Prepare(TfLiteContext* context, TfLiteNode* node);
60 
61 }  // namespace tflite
62 
63 #endif  // TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATIONS_H_
64