depthwise_conv.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef TENSORFLOW_LITE_MICRO_KERNELS_DEPTHWISE_CONV_H_
  13. #define TENSORFLOW_LITE_MICRO_KERNELS_DEPTHWISE_CONV_H_
  14. #include <cstdint>
  15. #include "tensorflow/lite/c/builtin_op_data.h"
  16. #include "tensorflow/lite/c/common.h"
  17. #include "tensorflow/lite/kernels/internal/types.h"
  18. #include "tensorflow/lite/micro/kernels/conv.h"
  19. namespace tflite {
  20. extern const int kDepthwiseConvInputTensor;
  21. extern const int kDepthwiseConvWeightsTensor;
  22. extern const int kDepthwiseConvBiasTensor;
  23. extern const int kDepthwiseConvOutputTensor;
  24. extern const int kDepthwiseConvQuantizedDimension;
  25. // Returns a DepthwiseParams struct with all the parameters needed for a
  26. // float computation.
  27. DepthwiseParams DepthwiseConvParamsFloat(
  28. const TfLiteDepthwiseConvParams& params, const OpDataConv& data);
  29. // Returns a DepthwiseParams struct with all the parameters needed for a
  30. // quantized computation.
  31. DepthwiseParams DepthwiseConvParamsQuantized(
  32. const TfLiteDepthwiseConvParams& params, const OpDataConv& data);
  33. TfLiteStatus CalculateOpDataDepthwiseConv(
  34. TfLiteContext* context, TfLiteNode* node,
  35. const TfLiteDepthwiseConvParams& params, int width, int height,
  36. int filter_width, int filter_height, int out_width, int out_height,
  37. const TfLiteType data_type, OpDataConv* data);
  38. TfLiteStatus DepthwiseConvPrepare(TfLiteContext* context, TfLiteNode* node);
  39. // This is the most generic TfLiteRegistration. The actual supported types may
  40. // still be target dependent. The only requirement is that every implementation
  41. // (reference or optimized) must define this function.
  42. TfLiteRegistration Register_DEPTHWISE_CONV_2D();
  43. #if defined(CMSIS_NN)
  44. // Returns a TfLiteRegistration struct for kernel variant that only supports
  45. // int8 activations and int8 weights and uses the latency optimized
  46. // implementations.
  47. TfLiteRegistration Register_DEPTHWISE_CONV_2D_INT8();
  48. // Returns a TfLiteRegistration struct for kernel variant that only supports
  49. // int16 activations and int8 weights and uses the latency optimized
  50. // implementations.
  51. TfLiteRegistration Register_DEPTHWISE_CONV_2D_INT16();
  52. #else
  53. inline TfLiteRegistration Register_DEPTHWISE_CONV_2D_INT8() {
  54. return Register_DEPTHWISE_CONV_2D();
  55. }
  56. inline TfLiteRegistration Register_DEPTHWISE_CONV_2D_INT16() {
  57. return Register_DEPTHWISE_CONV_2D();
  58. }
  59. #endif
  60. } // namespace tflite
  61. #endif // TENSORFLOW_LITE_MICRO_KERNELS_DEPTHWISE_CONV_H_