arm_convolve_1x1_s8_fast.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * SPDX-FileCopyrightText: Copyright 2010-2024 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_convolve_1x1_s8_fast.c
  21. * Description: Fast s8 version of 1x1 convolution (non-square shape)
  22. *
  23. * $Date: 04 January 2024
  24. * $Revision: V.3.5.0
  25. *
  26. * Target : Arm(R) M-Profile Architecture
  27. *
  28. * -------------------------------------------------------------------- */
  29. #include "arm_nnfunctions.h"
  30. #include "arm_nnsupportfunctions.h"
  31. /**
  32. * @ingroup Public
  33. */
  34. /**
  35. * @addtogroup NNConv
  36. * @{
  37. */
  38. /*
  39. * Fast s8 version for 1x1 convolution (non-square shape)
  40. *
  41. * Refer header file for details.
  42. *
  43. */
  44. arm_cmsis_nn_status arm_convolve_1x1_s8_fast(const cmsis_nn_context *ctx,
  45. const cmsis_nn_conv_params *conv_params,
  46. const cmsis_nn_per_channel_quant_params *quant_params,
  47. const cmsis_nn_dims *input_dims,
  48. const int8_t *input_data,
  49. const cmsis_nn_dims *filter_dims,
  50. const int8_t *filter_data,
  51. const cmsis_nn_dims *bias_dims,
  52. const int32_t *bias_data,
  53. const cmsis_nn_dims *output_dims,
  54. int8_t *output_data)
  55. {
  56. if (conv_params->padding.w != 0 || conv_params->padding.h != 0 || conv_params->stride.w != 1 ||
  57. conv_params->stride.h != 1)
  58. {
  59. return ARM_CMSIS_NN_ARG_ERROR;
  60. }
  61. (void)ctx;
  62. (void)filter_dims;
  63. (void)bias_dims;
  64. const int32_t lhs_rows = input_dims->w * input_dims->h * input_dims->n;
  65. const int32_t rhs_rows = output_dims->c;
  66. const int32_t rhs_cols = input_dims->c;
  67. arm_nn_mat_mult_nt_t_s8(input_data,
  68. filter_data,
  69. bias_data,
  70. output_data,
  71. quant_params->multiplier,
  72. quant_params->shift,
  73. lhs_rows,
  74. rhs_rows,
  75. rhs_cols,
  76. conv_params->input_offset,
  77. conv_params->output_offset,
  78. conv_params->activation.min,
  79. conv_params->activation.max,
  80. rhs_rows,
  81. rhs_cols);
  82. /* Return to application */
  83. return ARM_CMSIS_NN_SUCCESS;
  84. }
  85. /**
  86. * @} end of NNConv group
  87. */