arm_fully_connected_s8.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2010-2022 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_fully_connected_s8
  21. * Description: Fully connected function compatible with TF Lite.
  22. *
  23. * $Date: 8 April 2022
  24. * $Revision: V.3.1.0
  25. *
  26. * Target Processor: Cortex-M and Cortex-A cores
  27. *
  28. * -------------------------------------------------------------------- */
  29. #include "arm_nnfunctions.h"
  30. #include "arm_nnsupportfunctions.h"
  31. /**
  32. * @ingroup groupNN
  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_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 q7_t *input,
  49. const cmsis_nn_dims *filter_dims,
  50. const q7_t *kernel,
  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. (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_s8(input,
  63. kernel,
  64. bias,
  65. output,
  66. fc_params->input_offset,
  67. 0,
  68. fc_params->output_offset,
  69. quant_params->multiplier,
  70. quant_params->shift,
  71. filter_dims->n, /* col_dim or accum_depth */
  72. output_dims->c, /* row_dim or output_depth */
  73. fc_params->activation.min,
  74. fc_params->activation.max,
  75. 1L);
  76. input += filter_dims->n;
  77. output += output_dims->c;
  78. batch_cnt--;
  79. }
  80. return (ARM_MATH_SUCCESS);
  81. }
  82. int32_t arm_fully_connected_s8_get_buffer_size(const cmsis_nn_dims *filter_dims)
  83. {
  84. (void)filter_dims;
  85. return 0;
  86. }
  87. /**
  88. * @} end of FC group
  89. */