arm_fully_connected_s16.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2010-2021 Arm Limited or its affiliates. All rights reserved.
  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_s16
  21. * Description: Fully connected function compatible with TF Lite.
  22. *
  23. * $Date: 3. August 2021
  24. * $Revision: V.1.0.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. * S16 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_s16(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 q15_t *input,
  49. const cmsis_nn_dims *filter_dims,
  50. const q7_t *kernel,
  51. const cmsis_nn_dims *bias_dims,
  52. const int64_t *bias,
  53. const cmsis_nn_dims *output_dims,
  54. q15_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. const q31_t reduced_multiplier = REDUCE_MULTIPLIER(quant_params->multiplier);
  61. while (batch_cnt)
  62. {
  63. arm_nn_vec_mat_mult_t_s16(input,
  64. kernel,
  65. bias,
  66. output,
  67. reduced_multiplier,
  68. quant_params->shift,
  69. filter_dims->n, /* col_dim or accum_depth */
  70. output_dims->c, /* row_dim or output_depth */
  71. fc_params->activation.min,
  72. fc_params->activation.max);
  73. input += filter_dims->n;
  74. output += output_dims->c;
  75. batch_cnt--;
  76. }
  77. return (ARM_MATH_SUCCESS);
  78. }
  79. int32_t arm_fully_connected_s16_get_buffer_size(const cmsis_nn_dims *filter_dims)
  80. {
  81. (void)filter_dims;
  82. return 0;
  83. }
  84. /**
  85. * @} end of FC group
  86. */