arm_fully_connected_s4.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * SPDX-FileCopyrightText: Copyright 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_fully_connected_s4
  21. * Description: Fully connected function compatible with TF Lite.
  22. *
  23. * $Date: 10 October 2023
  24. * $Revision: V.1.0.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. * S4 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_s4(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. (void)ctx;
  58. (void)fc_params->filter_offset;
  59. int32_t batch_cnt = input_dims->n;
  60. while (batch_cnt)
  61. {
  62. arm_nn_vec_mat_mult_t_s4(input,
  63. kernel,
  64. bias,
  65. output,
  66. fc_params->input_offset,
  67. fc_params->output_offset,
  68. quant_params->multiplier,
  69. quant_params->shift,
  70. filter_dims->n, /* col_dim or accum_depth */
  71. output_dims->c, /* row_dim or output_depth */
  72. fc_params->activation.min,
  73. fc_params->activation.max,
  74. 1L);
  75. input += filter_dims->n;
  76. output += output_dims->c;
  77. batch_cnt--;
  78. }
  79. return (ARM_CMSIS_NN_SUCCESS);
  80. }
  81. /**
  82. * @} end of FC group
  83. */