arm_fully_connected_s8.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_s8
  21. * Description: Fully connected function compatible with TF Lite.
  22. *
  23. * $Date: 19. March 2021
  24. * $Revision: V.3.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. * 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. input += filter_dims->n;
  76. output += output_dims->c;
  77. batch_cnt--;
  78. }
  79. return (ARM_MATH_SUCCESS);
  80. }
  81. int32_t arm_fully_connected_s8_get_buffer_size(const cmsis_nn_dims *filter_dims)
  82. {
  83. (void)filter_dims;
  84. return 0;
  85. }
  86. /**
  87. * @} end of FC group
  88. */