1 /* Copyright 2020 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 #ifndef TENSORFLOW_LITE_MICRO_KERNELS_SVDF_H_
16 #define TENSORFLOW_LITE_MICRO_KERNELS_SVDF_H_
17 
18 #include "tensorflow/lite/c/builtin_op_data.h"
19 #include "tensorflow/lite/c/common.h"
20 
21 namespace tflite {
22 
23 struct OpData {
24   int32_t effective_scale_1_a;
25   int32_t effective_scale_2_a;
26   // b versions of each scale are kept at int since the numbers are just the
27   // shift value - typically between [-32, 32].
28   int effective_scale_1_b;
29   int effective_scale_2_b;
30   int scratch_tensor_index;
31   int scratch_output_tensor_index;
32 
33   // Cached tensor zero point values for quantized operations.
34   int input_zero_point;
35   int output_zero_point;
36 };
37 
38 // Input tensors.
39 extern const int kSvdfInputTensor;
40 extern const int kSvdfWeightsFeatureTensor;
41 extern const int kSvdfWeightsTimeTensor;
42 extern const int kSvdfBiasTensor;
43 // This is a variable tensor, and will be modified by this op.
44 extern const int kSvdfInputActivationStateTensor;
45 
46 // Output tensor.
47 extern const int kSvdfOutputTensor;
48 
49 // TensorflowLite Micro-specific reference implementation for Integer SVDF.
50 void EvalIntegerSvdfReference(TfLiteContext* context, TfLiteNode* node,
51                               const TfLiteEvalTensor* input_tensor,
52                               const TfLiteEvalTensor* weights_feature_tensor,
53                               const TfLiteEvalTensor* weights_time_tensor,
54                               const TfLiteEvalTensor* bias_tensor,
55                               const TfLiteSVDFParams* params,
56                               TfLiteEvalTensor* activation_state_tensor,
57                               TfLiteEvalTensor* output_tensor,
58                               const OpData& data);
59 
60 void EvalFloatSvdfReference(
61     TfLiteContext* context, TfLiteNode* node, const TfLiteEvalTensor* input,
62     const TfLiteEvalTensor* weights_feature,
63     const TfLiteEvalTensor* weights_time, const TfLiteEvalTensor* bias,
64     const TfLiteSVDFParams* params, int scratch_tensor_index,
65     TfLiteEvalTensor* activation_state, TfLiteEvalTensor* output);
66 
67 TfLiteStatus PrepareSvdf(TfLiteContext* context, TfLiteNode* node);
68 
69 }  // namespace tflite
70 
71 #endif  // TENSORFLOW_LITE_MICRO_KERNELS_SVDF_H_
72