arm_depthwise_conv_wrapper_s8.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * SPDX-FileCopyrightText: Copyright 2010-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
  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: 13 January 2023
  25. * $Revision: V.2.1.0
  26. *
  27. * Target : Arm(R) M-Profile Architecture
  28. *
  29. * -------------------------------------------------------------------- */
  30. #include "arm_nnfunctions.h"
  31. /**
  32. * @ingroup Public
  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_cmsis_nn_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 int8_t *input,
  49. const cmsis_nn_dims *filter_dims,
  50. const int8_t *filter,
  51. const cmsis_nn_dims *bias_dims,
  52. const int32_t *bias,
  53. const cmsis_nn_dims *output_dims,
  54. int8_t *output)
  55. {
  56. arm_cmsis_nn_status status = ARM_CMSIS_NN_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. /**
  110. * @} end of NNConv group
  111. */