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.

gemv.c 7.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. int nthreads_max;
  78. int nthreads_avail;
  79. double MNK;
  80. #endif
  81. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  82. GEMV_N, GEMV_T,
  83. };
  84. blasint info;
  85. blasint lenx, leny;
  86. blasint i;
  87. PRINT_DEBUG_NAME;
  88. TOUPPER(trans);
  89. info = 0;
  90. i = -1;
  91. if (trans == 'N') i = 0;
  92. if (trans == 'T') i = 1;
  93. if (trans == 'R') i = 0;
  94. if (trans == 'C') i = 1;
  95. if (incy == 0) info = 11;
  96. if (incx == 0) info = 8;
  97. if (lda < MAX(1, m)) info = 6;
  98. if (n < 0) info = 3;
  99. if (m < 0) info = 2;
  100. if (i < 0) info = 1;
  101. trans = i;
  102. if (info != 0){
  103. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  104. return;
  105. }
  106. #else
  107. void CNAME(enum CBLAS_ORDER order,
  108. enum CBLAS_TRANSPOSE TransA,
  109. blasint m, blasint n,
  110. FLOAT alpha,
  111. FLOAT *a, blasint lda,
  112. FLOAT *x, blasint incx,
  113. FLOAT beta,
  114. FLOAT *y, blasint incy){
  115. FLOAT *buffer;
  116. blasint lenx, leny;
  117. int trans;
  118. blasint info, t;
  119. #ifdef SMP
  120. int nthreads;
  121. int nthreads_max;
  122. int nthreads_avail;
  123. double MNK;
  124. #endif
  125. int (*gemv[])(BLASLONG, BLASLONG, BLASLONG, FLOAT, FLOAT *, BLASLONG, FLOAT * , BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  126. GEMV_N, GEMV_T,
  127. };
  128. PRINT_DEBUG_CNAME;
  129. trans = -1;
  130. info = 0;
  131. if (order == CblasColMajor) {
  132. if (TransA == CblasNoTrans) trans = 0;
  133. if (TransA == CblasTrans) trans = 1;
  134. if (TransA == CblasConjNoTrans) trans = 0;
  135. if (TransA == CblasConjTrans) trans = 1;
  136. info = -1;
  137. if (incy == 0) info = 11;
  138. if (incx == 0) info = 8;
  139. if (lda < MAX(1, m)) info = 6;
  140. if (n < 0) info = 3;
  141. if (m < 0) info = 2;
  142. if (trans < 0) info = 1;
  143. }
  144. if (order == CblasRowMajor) {
  145. if (TransA == CblasNoTrans) trans = 1;
  146. if (TransA == CblasTrans) trans = 0;
  147. if (TransA == CblasConjNoTrans) trans = 1;
  148. if (TransA == CblasConjTrans) trans = 0;
  149. info = -1;
  150. t = n;
  151. n = m;
  152. m = t;
  153. if (incy == 0) info = 11;
  154. if (incx == 0) info = 8;
  155. if (lda < MAX(1, m)) info = 6;
  156. if (n < 0) info = 3;
  157. if (m < 0) info = 2;
  158. if (trans < 0) info = 1;
  159. }
  160. if (info >= 0) {
  161. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  162. return;
  163. }
  164. #endif
  165. if ((m==0) || (n==0)) return;
  166. lenx = n;
  167. leny = m;
  168. if (trans) lenx = m;
  169. if (trans) leny = n;
  170. if (beta != ONE) SCAL_K(leny, 0, 0, beta, y, abs(incy), NULL, 0, NULL, 0);
  171. if (alpha == ZERO) return;
  172. IDEBUG_START;
  173. FUNCTION_PROFILE_START();
  174. if (incx < 0) x -= (lenx - 1) * incx;
  175. if (incy < 0) y -= (leny - 1) * incy;
  176. buffer = (FLOAT *)blas_memory_alloc(1);
  177. #ifdef SMP
  178. nthreads_max = num_cpu_avail(2);
  179. nthreads_avail = nthreads_max;
  180. MNK = (double) m * (double) n;
  181. if ( MNK <= (24.0 * 24.0 * (double) (GEMM_MULTITHREAD_THRESHOLD*GEMM_MULTITHREAD_THRESHOLD) ) )
  182. nthreads_max = 1;
  183. if ( nthreads_max > nthreads_avail )
  184. nthreads = nthreads_avail;
  185. else
  186. nthreads = nthreads_max;
  187. if (nthreads == 1) {
  188. #endif
  189. (gemv[(int)trans])(m, n, 0, alpha, a, lda, x, incx, y, incy, buffer);
  190. #ifdef SMP
  191. } else {
  192. (gemv_thread[(int)trans])(m, n, alpha, a, lda, x, incx, y, incy, buffer, nthreads);
  193. }
  194. #endif
  195. blas_memory_free(buffer);
  196. FUNCTION_PROFILE_END(1, m * n + m + n, 2 * m * n);
  197. IDEBUG_END;
  198. return;
  199. }