arm_fully_connected_s8.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_fully_connected_s8
  21. * Description: Fully connected function compatible with TF Lite.
  22. *
  23. * $Date: 6 February 2024
  24. * $Revision: V.5.3.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 FC
  36. * @{
  37. */
  38. /*
  39. * S8 basic fully-connected and matrix multiplication layer function for TensorFlow Lite
  40. *
  41. * Refer header file for details.
  42. *
  43. */
  44. arm_cmsis_nn_status arm_fully_connected_s8(const cmsis_nn_context *ctx,
  45. const cmsis_nn_fc_params *fc_params,
  46. const cmsis_nn_per_tensor_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 *kernel,
  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. (void)bias_dims;
  57. int32_t batch_cnt = input_dims->n;
  58. #if defined(ARM_MATH_MVEI)
  59. if (ctx->buf == NULL)
  60. {
  61. return (ARM_CMSIS_NN_ARG_ERROR);
  62. }
  63. #endif
  64. const int32_t *kernel_sum = (const int32_t *)ctx->buf;
  65. while (batch_cnt)
  66. {
  67. arm_nn_vec_mat_mult_t_s8(input,
  68. kernel,
  69. kernel_sum,
  70. bias,
  71. output,
  72. fc_params->input_offset,
  73. fc_params->output_offset,
  74. quant_params->multiplier,
  75. quant_params->shift,
  76. filter_dims->n, /* col_dim or accum_depth */
  77. output_dims->c, /* row_dim or output_depth */
  78. fc_params->activation.min,
  79. fc_params->activation.max,
  80. 1L,
  81. fc_params->filter_offset);
  82. input += filter_dims->n;
  83. output += output_dims->c;
  84. batch_cnt--;
  85. }
  86. return (ARM_CMSIS_NN_SUCCESS);
  87. }
  88. /**
  89. * @} end of FC group
  90. */