You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gemm_ncopy_sve_v1x8.c 5.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /***************************************************************************
  2. Copyright (c) 2023, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A00 PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #include <stdint.h>
  28. #include <stdio.h>
  29. #include <arm_sve.h>
  30. #include "common.h"
  31. #ifdef DOUBLE
  32. #define COUNT "cntd"
  33. #define SV_TYPE svfloat64_t
  34. #define SV_INDEX svuint64_t
  35. #define SV_INDEXER svindex_u64
  36. #define SV_TRUE svptrue_b64
  37. #define SV_WHILE svwhilelt_b64
  38. #define SV_PREFETCH svprfd_gather_index
  39. #else
  40. #define COUNT "cntw"
  41. #define SV_TYPE svfloat32_t
  42. #define SV_INDEX svuint32_t
  43. #define SV_INDEXER svindex_u32
  44. #define SV_TRUE svptrue_b32
  45. #define SV_WHILE svwhilelt_b32
  46. #define SV_PREFETCH svprfw_gather_index
  47. #endif
  48. #define INNER_COPY(pg, a_offset_inner, b_offset, lda, active) \
  49. a_vec = svld1_gather_index(pg, a_offset_inner, lda_vec); \
  50. svst1(pg, b_offset, a_vec); \
  51. a_offset_inner++; \
  52. b_offset += active;
  53. int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b) {
  54. uint64_t sve_size;
  55. asm(COUNT" %[SIZE_]" : [SIZE_] "=r" (sve_size) : : );
  56. IFLOAT *a_offset, *a_offset_inner, *b_offset;
  57. a_offset = a;
  58. b_offset = b;
  59. SV_INDEX lda_vec = SV_INDEXER(0LL, lda);
  60. SV_TYPE a_vec;
  61. svbool_t pg_true = SV_TRUE();
  62. BLASLONG single_vectors_n = n & -sve_size;
  63. for (BLASLONG j = 0; j < single_vectors_n; j += sve_size) {
  64. a_offset_inner = a_offset;
  65. svbool_t pg = pg_true;
  66. uint64_t active = sve_size;
  67. uint64_t i_cnt = m >> 3;
  68. while (i_cnt--) {
  69. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  70. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  71. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  72. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  73. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  74. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  75. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  76. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  77. }
  78. if (m & 4) {
  79. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  80. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  81. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  82. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  83. }
  84. if (m & 2) {
  85. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  86. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  87. }
  88. if (m & 1) {
  89. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  90. }
  91. a_offset += sve_size * lda;
  92. }
  93. BLASLONG remaining_n = n - single_vectors_n;
  94. if (remaining_n) {
  95. a_offset_inner = a_offset;
  96. svbool_t pg = SV_WHILE((uint64_t)0L, (uint64_t)remaining_n);
  97. uint64_t active = remaining_n;
  98. uint64_t i_cnt = m >> 2;
  99. while (i_cnt--) {
  100. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  101. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  102. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  103. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  104. }
  105. if (m & 2) {
  106. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  107. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  108. }
  109. if (m & 1) {
  110. INNER_COPY(pg, a_offset_inner, b_offset, lda, active);
  111. }
  112. }
  113. return 0;
  114. }