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.

sbgemv.c 6.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*********************************************************************/
  2. /* Copyright 2025 The OpenBLAS Project. */
  3. /* Copyright 2009, 2010 The University of Texas at Austin. */
  4. /* All rights reserved. */
  5. /* */
  6. /* Redistribution and use in source and binary forms, with or */
  7. /* without modification, are permitted provided that the following */
  8. /* conditions are met: */
  9. /* */
  10. /* 1. Redistributions of source code must retain the above */
  11. /* copyright notice, this list of conditions and the following */
  12. /* disclaimer. */
  13. /* */
  14. /* 2. Redistributions in binary form must reproduce the above */
  15. /* copyright notice, this list of conditions and the following */
  16. /* disclaimer in the documentation and/or other materials */
  17. /* provided with the distribution. */
  18. /* */
  19. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  20. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  21. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  22. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  23. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  24. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  25. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  26. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  27. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  28. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  29. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  30. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  31. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  32. /* POSSIBILITY OF SUCH DAMAGE. */
  33. /* */
  34. /* The views and conclusions contained in the software and */
  35. /* documentation are those of the authors and should not be */
  36. /* interpreted as representing official policies, either expressed */
  37. /* or implied, of The University of Texas at Austin. */
  38. /*********************************************************************/
  39. #include <stdio.h>
  40. #include "common.h"
  41. #include "l1param.h"
  42. #ifdef FUNCTION_PROFILE
  43. #include "functable.h"
  44. #endif
  45. #ifdef BGEMM
  46. #define GEMV_THREAD_N bgemv_thread_n
  47. #define GEMV_THREAD_T bgemv_thread_t
  48. #define ERROR_NAME "BGEMV "
  49. #else
  50. #define GEMV_THREAD_N sbgemv_thread_n
  51. #define GEMV_THREAD_T sbgemv_thread_t
  52. #define ERROR_NAME "SBGEMV "
  53. #endif
  54. #ifdef SMP
  55. static int (*gemv_thread[])(BLASLONG, BLASLONG, FLOAT, IFLOAT *, BLASLONG, IFLOAT * , BLASLONG, FLOAT, FLOAT *, BLASLONG, int) = {
  56. GEMV_THREAD_N, GEMV_THREAD_T,
  57. };
  58. #endif
  59. #ifndef CBLAS
  60. void NAME(char *TRANS, blasint *M, blasint *N, FLOAT *ALPHA, IFLOAT *a, blasint *LDA, IFLOAT *x, blasint *INCX, FLOAT *BETA, FLOAT *y, blasint *INCY)
  61. {
  62. char trans = *TRANS;
  63. blasint m = *M;
  64. blasint n = *N;
  65. blasint lda = *LDA;
  66. blasint incx = *INCX;
  67. blasint incy = *INCY;
  68. FLOAT alpha = *ALPHA;
  69. FLOAT beta = *BETA;
  70. #ifdef SMP
  71. int nthreads;
  72. #endif
  73. int (*gemv[])(BLASLONG, BLASLONG, FLOAT, IFLOAT *, BLASLONG, IFLOAT * , BLASLONG, FLOAT, FLOAT *, BLASLONG) = {
  74. GEMV_N, GEMV_T,
  75. };
  76. blasint info;
  77. blasint lenx, leny;
  78. blasint i;
  79. PRINT_DEBUG_NAME;
  80. TOUPPER(trans);
  81. info = 0;
  82. i = -1;
  83. if (trans == 'N') {i = 0;}
  84. if (trans == 'T') {i = 1;}
  85. if (trans == 'R') {i = 0;}
  86. if (trans == 'C') {i = 1;}
  87. if (incy == 0) {info = 11;}
  88. if (incx == 0) {info = 8;}
  89. if (lda < MAX(1, m)) {info = 6;}
  90. if (n < 0) {info = 3;}
  91. if (m < 0) {info = 2;}
  92. if (i < 0) {info = 1;}
  93. trans = i;
  94. if (info != 0) {
  95. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  96. return;
  97. }
  98. #else
  99. void CNAME(enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE TransA, blasint m, blasint n, FLOAT alpha, IFLOAT *a, blasint lda, IFLOAT *x, blasint incx, FLOAT beta, FLOAT *y, blasint incy)
  100. {
  101. blasint lenx, leny;
  102. int trans;
  103. blasint info, t;
  104. #ifdef SMP
  105. int nthreads;
  106. #endif
  107. int (*gemv[])(BLASLONG, BLASLONG, FLOAT, IFLOAT *, BLASLONG, IFLOAT * , BLASLONG, FLOAT, FLOAT *, BLASLONG) = {
  108. GEMV_N, GEMV_T,
  109. };
  110. PRINT_DEBUG_CNAME;
  111. trans = -1;
  112. info = 0;
  113. if (order == CblasColMajor) { // Column Major
  114. if (TransA == CblasNoTrans || TransA == CblasConjNoTrans) {
  115. trans = 0;
  116. } else if (TransA == CblasTrans || TransA == CblasConjTrans) {
  117. trans = 1;
  118. }
  119. } else { // Row Major
  120. if (TransA == CblasNoTrans || TransA == CblasConjNoTrans) {
  121. trans = 1;
  122. } else if (TransA == CblasTrans || TransA == CblasConjTrans) {
  123. trans = 0;
  124. }
  125. t = n;
  126. n = m;
  127. m = t;
  128. }
  129. info = -1;
  130. if (incy == 0) {info = 11;}
  131. if (incx == 0) {info = 8;}
  132. if (lda < MAX(1, m)) {info = 6;}
  133. if (n < 0) {info = 3;}
  134. if (m < 0) {info = 2;}
  135. if (trans < 0) {info = 1;}
  136. if (info >= 0) {
  137. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  138. return;
  139. }
  140. #endif
  141. if ((m==0) || (n==0)) return;
  142. if (trans) {
  143. lenx = m;
  144. leny = n;
  145. } else {
  146. lenx = n;
  147. leny = m;
  148. }
  149. #ifdef BGEMM
  150. float alpha_float, beta_float;
  151. SBF16TOS_K(1, &alpha, 1, &alpha_float, 1);
  152. SBF16TOS_K(1, &beta, 1, &beta_float, 1);
  153. #else
  154. float alpha_float = alpha;
  155. float beta_float = beta;
  156. #endif
  157. if (alpha_float == ZERO) {
  158. if (beta_float != ONE) SCAL_K(leny, 0, 0, beta, y, blasabs(incy), NULL, 0, NULL, 0);
  159. return;
  160. }
  161. IDEBUG_START;
  162. FUNCTION_PROFILE_START();
  163. if (incx < 0) {x -= (lenx - 1) * incx;}
  164. if (incy < 0) {y -= (leny - 1) * incy;}
  165. #ifdef SMP
  166. if ( 1L * m * n < 115200L * GEMM_MULTITHREAD_THRESHOLD )
  167. nthreads = 1;
  168. else
  169. nthreads = num_cpu_avail(2);
  170. if (nthreads == 1) {
  171. #endif
  172. (gemv[(int)trans])(m, n, alpha, a, lda, x, incx, beta, y, incy);
  173. #ifdef SMP
  174. } else {
  175. (gemv_thread[(int)trans])(m, n, alpha, a, lda, x, incx, beta, y, incy, nthreads);
  176. }
  177. #endif
  178. FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);
  179. IDEBUG_END;
  180. return;
  181. }