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.5 kB

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