arm_depthwise_conv_wrapper_s8.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2010-2021 Arm Limited or its affiliates.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /* ----------------------------------------------------------------------
  19. * Project: CMSIS NN Library
  20. * Title: arm_depthwise_conv_wrapper_s8.c
  21. * Description: Wrapper API to select appropriate depthwise conv API based
  22. * on dimensions.
  23. *
  24. * $Date: 20. Dec 2021
  25. * $Revision: V.1.4.0
  26. *
  27. * Target Processor: Cortex-M CPUs
  28. *
  29. * -------------------------------------------------------------------- */
  30. #include "arm_nnfunctions.h"
  31. /**
  32. * @ingroup groupNN
  33. */
  34. /**
  35. * @addtogroup NNConv
  36. * @{
  37. */
  38. /*
  39. * s8 Depthwise conv wrapper function
  40. *
  41. * Refer header file for details.
  42. *
  43. */
  44. arm_status arm_depthwise_conv_wrapper_s8(const cmsis_nn_context *ctx,
  45. const cmsis_nn_dw_conv_params *dw_conv_params,
  46. const cmsis_nn_per_channel_quant_params *quant_params,
  47. const cmsis_nn_dims *input_dims,
  48. const q7_t *input,
  49. const cmsis_nn_dims *filter_dims,
  50. const q7_t *filter,
  51. const cmsis_nn_dims *bias_dims,
  52. const int32_t *bias,
  53. const cmsis_nn_dims *output_dims,
  54. q7_t *output)
  55. {
  56. arm_status status = ARM_MATH_SUCCESS;
  57. if (1 == dw_conv_params->ch_mult && input_dims->n == 1 && dw_conv_params->dilation.w == 1 &&
  58. dw_conv_params->dilation.h == 1)
  59. {
  60. #if !defined(ARM_MATH_MVEI)
  61. if ((filter_dims->w == 3) && (filter_dims->h == 3) && (dw_conv_params->padding.h <= 1) &&
  62. (dw_conv_params->padding.w <= 1))
  63. {
  64. status = arm_depthwise_conv_3x3_s8(ctx,
  65. dw_conv_params,
  66. quant_params,
  67. input_dims,
  68. input,
  69. filter_dims,
  70. filter,
  71. bias_dims,
  72. bias,
  73. output_dims,
  74. output);
  75. }
  76. else
  77. #endif
  78. {
  79. status = arm_depthwise_conv_s8_opt(ctx,
  80. dw_conv_params,
  81. quant_params,
  82. input_dims,
  83. input,
  84. filter_dims,
  85. filter,
  86. bias_dims,
  87. bias,
  88. output_dims,
  89. output);
  90. }
  91. }
  92. else
  93. {
  94. status = arm_depthwise_conv_s8(ctx,
  95. dw_conv_params,
  96. quant_params,
  97. input_dims,
  98. input,
  99. filter_dims,
  100. filter,
  101. bias_dims,
  102. bias,
  103. output_dims,
  104. output);
  105. }
  106. /* Return to application */
  107. return status;
  108. }
  109. int32_t arm_depthwise_conv_wrapper_s8_get_buffer_size(const cmsis_nn_dw_conv_params *dw_conv_params,
  110. const cmsis_nn_dims *input_dims,
  111. const cmsis_nn_dims *filter_dims,
  112. const cmsis_nn_dims *output_dims)
  113. {
  114. (void)dw_conv_params;
  115. int32_t size = 0;
  116. if (input_dims->c == output_dims->c && input_dims->n == 1 && dw_conv_params->dilation.w == 1 &&
  117. dw_conv_params->dilation.h == 1)
  118. {
  119. size = arm_depthwise_conv_s8_opt_get_buffer_size(input_dims, filter_dims);
  120. }
  121. return size;
  122. }
  123. /**
  124. * @} end of NNConv group
  125. */