• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONV_H_
17 #define TENSORFLOW_LITE_MICRO_KERNELS_CONV_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 struct OpDataConv {
28   TfLitePaddingValues padding;
29 
30   // Cached tensor zero point values for quantized operations.
31   int32_t input_zero_point;
32   int32_t filter_zero_point;
33   int32_t output_zero_point;
34 
35   // The scaling factor from input to output (aka the 'real multiplier') can
36   // be represented as a fixed point multiplier plus a left shift.
37   int32_t output_multiplier;
38   int output_shift;
39 
40   // Per channel output multiplier and shift.
41   int32_t* per_channel_output_multiplier;
42   int32_t* per_channel_output_shift;
43 
44   // The range of the fused activation layer. For example for kNone and
45   // uint8_t these would be 0 and 255.
46   int32_t output_activation_min;
47   int32_t output_activation_max;
48 };
49 
50 extern const int kConvInputTensor;
51 extern const int kConvWeightsTensor;
52 extern const int kConvBiasTensor;
53 extern const int kConvOutputTensor;
54 extern const int kConvQuantizedDimension;
55 
56 // Returns a ConvParams struct with all the parameters needed for a
57 // float computation.
58 ConvParams ConvParamsFloat(const TfLiteConvParams& params,
59                            const OpDataConv& data);
60 
61 // Returns a ConvParams struct with all the parameters needed for a
62 // quantized computation.
63 ConvParams ConvParamsQuantized(const TfLiteConvParams& params,
64                                const OpDataConv& data);
65 
66 TfLiteStatus CalculateOpDataConv(TfLiteContext* context, TfLiteNode* node,
67                                  const TfLiteConvParams& params, int width,
68                                  int height, int filter_width,
69                                  int filter_height, int out_width,
70                                  int out_height, const TfLiteType data_type,
71                                  OpDataConv* data);
72 
73 TfLiteStatus ConvPrepare(TfLiteContext* context, TfLiteNode* node);
74 
75 }  // namespace tflite
76 
77 #endif  // TENSORFLOW_LITE_MICRO_KERNELS_CONV_H_
78