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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #ifdef FUNCTION_PROFILE
  41. #include "functable.h"
  42. #endif
  43. #ifdef XDOUBLE
  44. #define ERROR_NAME "QGEMV "
  45. #elif defined(DOUBLE)
  46. #define ERROR_NAME "DGEMV "
  47. #else
  48. #define ERROR_NAME "SGEMV "
  49. #endif
  50. #ifdef SMP
  51. static int (*gemv_thread[])(BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
  52. #ifdef XDOUBLE
  53. qgemv_thread_n, qgemv_thread_t,
  54. #elif defined DOUBLE
  55. dgemv_thread_n, dgemv_thread_t,
  56. #else
  57. sgemv_thread_n, sgemv_thread_t,
  58. #endif
  59. };
  60. #endif
  61. #ifndef CBLAS
  62. void NAME(char *TRANS, blasint *M, blasint *N,
  63. FLOAT *ALPHA, FLOAT *a, blasint *LDA,
  64. FLOAT *x, blasint *INCX,
  65. FLOAT *BETA, FLOAT *y, blasint *INCY){
  66. char trans = *TRANS;
  67. blasint m = *M;
  68. blasint n = *N;
  69. blasint lda = *LDA;
  70. blasint incx = *INCX;
  71. blasint incy = *INCY;
  72. FLOAT alpha = *ALPHA;
  73. FLOAT beta = *BETA;
  74. FLOAT *buffer;
  75. #ifdef SMP
  76. int nthreads;
  77. #endif
  78. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  79. GEMV_N, GEMV_T,
  80. };
  81. blasint info;
  82. blasint lenx, leny;
  83. blasint i;
  84. PRINT_DEBUG_NAME;
  85. TOUPPER(trans);
  86. info = 0;
  87. i = -1;
  88. if (trans == 'N') i = 0;
  89. if (trans == 'T') i = 1;
  90. if (trans == 'R') i = 0;
  91. if (trans == 'C') i = 1;
  92. if (incy == 0) info = 11;
  93. if (incx == 0) info = 8;
  94. if (lda < MAX(1, m)) info = 6;
  95. if (n < 0) info = 3;
  96. if (m < 0) info = 2;
  97. if (i < 0) info = 1;
  98. trans = i;
  99. if (info != 0){
  100. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  101. return;
  102. }
  103. #else
  104. void CNAME(enum CBLAS_ORDER order,
  105. enum CBLAS_TRANSPOSE TransA,
  106. blasint m, blasint n,
  107. FLOAT alpha,
  108. FLOAT *a, blasint lda,
  109. FLOAT *x, blasint incx,
  110. FLOAT beta,
  111. FLOAT *y, blasint incy){
  112. FLOAT *buffer;
  113. blasint lenx, leny;
  114. int trans;
  115. blasint info, t;
  116. #ifdef SMP
  117. int nthreads;
  118. #endif
  119. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  120. GEMV_N, GEMV_T,
  121. };
  122. PRINT_DEBUG_CNAME;
  123. trans = -1;
  124. info = 0;
  125. if (order == CblasColMajor) {
  126. if (TransA == CblasNoTrans) trans = 0;
  127. if (TransA == CblasTrans) trans = 1;
  128. if (TransA == CblasConjNoTrans) trans = 0;
  129. if (TransA == CblasConjTrans) trans = 1;
  130. info = -1;
  131. if (incy == 0) info = 11;
  132. if (incx == 0) info = 8;
  133. if (lda < MAX(1, m)) info = 6;
  134. if (n < 0) info = 3;
  135. if (m < 0) info = 2;
  136. if (trans < 0) info = 1;
  137. }
  138. if (order == CblasRowMajor) {
  139. if (TransA == CblasNoTrans) trans = 1;
  140. if (TransA == CblasTrans) trans = 0;
  141. if (TransA == CblasConjNoTrans) trans = 1;
  142. if (TransA == CblasConjTrans) trans = 0;
  143. info = -1;
  144. t = n;
  145. n = m;
  146. m = t;
  147. if (incy == 0) info = 11;
  148. if (incx == 0) info = 8;
  149. if (lda < MAX(1, m)) info = 6;
  150. if (n < 0) info = 3;
  151. if (m < 0) info = 2;
  152. if (trans < 0) info = 1;
  153. }
  154. if (info >= 0) {
  155. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  156. return;
  157. }
  158. #endif
  159. if ((m==0) || (n==0)) return;
  160. lenx = n;
  161. leny = m;
  162. if (trans) lenx = m;
  163. if (trans) leny = n;
  164. if (beta != ONE) SCAL_K(leny, 0, 0, beta, y, abs(incy), NULL, 0, NULL, 0);
  165. if (alpha == ZERO) return;
  166. IDEBUG_START;
  167. FUNCTION_PROFILE_START();
  168. if (incx < 0) x -= (lenx - 1) * incx;
  169. if (incy < 0) y -= (leny - 1) * incy;
  170. buffer = (FLOAT *)blas_memory_alloc(1);
  171. #ifdef SMP
  172. nthreads = num_cpu_avail(2);
  173. if (nthreads == 1) {
  174. #endif
  175. (gemv[(int)trans])(m, n, 0, alpha, a, lda, x, incx, y, incy, buffer);
  176. #ifdef SMP
  177. } else {
  178. (gemv_thread[(int)trans])(m, n, alpha, a, lda, x, incx, y, incy, buffer, nthreads);
  179. }
  180. #endif
  181. blas_memory_free(buffer);
  182. FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);
  183. IDEBUG_END;
  184. return;
  185. }