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.

ztrmv.c 8.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 <ctype.h>
  40. #include "common.h"
  41. #ifdef FUNCTION_PROFILE
  42. #include "functable.h"
  43. #endif
  44. #ifdef XDOUBLE
  45. #define ERROR_NAME "XTRMV "
  46. #elif defined(DOUBLE)
  47. #define ERROR_NAME "ZTRMV "
  48. #else
  49. #define ERROR_NAME "CTRMV "
  50. #endif
  51. static int (*trmv[])(BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *) = {
  52. #ifdef XDOUBLE
  53. xtrmv_NUU, xtrmv_NUN, xtrmv_NLU, xtrmv_NLN,
  54. xtrmv_TUU, xtrmv_TUN, xtrmv_TLU, xtrmv_TLN,
  55. xtrmv_RUU, xtrmv_RUN, xtrmv_RLU, xtrmv_RLN,
  56. xtrmv_CUU, xtrmv_CUN, xtrmv_CLU, xtrmv_CLN,
  57. #elif defined(DOUBLE)
  58. ztrmv_NUU, ztrmv_NUN, ztrmv_NLU, ztrmv_NLN,
  59. ztrmv_TUU, ztrmv_TUN, ztrmv_TLU, ztrmv_TLN,
  60. ztrmv_RUU, ztrmv_RUN, ztrmv_RLU, ztrmv_RLN,
  61. ztrmv_CUU, ztrmv_CUN, ztrmv_CLU, ztrmv_CLN,
  62. #else
  63. ctrmv_NUU, ctrmv_NUN, ctrmv_NLU, ctrmv_NLN,
  64. ctrmv_TUU, ctrmv_TUN, ctrmv_TLU, ctrmv_TLN,
  65. ctrmv_RUU, ctrmv_RUN, ctrmv_RLU, ctrmv_RLN,
  66. ctrmv_CUU, ctrmv_CUN, ctrmv_CLU, ctrmv_CLN,
  67. #endif
  68. };
  69. #ifdef SMP
  70. static int (*trmv_thread[])(BLASLONG, FLOAT *, BLASLONG, FLOAT *, BLASLONG, FLOAT *, int) = {
  71. #ifdef XDOUBLE
  72. xtrmv_thread_NUU, xtrmv_thread_NUN, xtrmv_thread_NLU, xtrmv_thread_NLN,
  73. xtrmv_thread_TUU, xtrmv_thread_TUN, xtrmv_thread_TLU, xtrmv_thread_TLN,
  74. xtrmv_thread_RUU, xtrmv_thread_RUN, xtrmv_thread_RLU, xtrmv_thread_RLN,
  75. xtrmv_thread_CUU, xtrmv_thread_CUN, xtrmv_thread_CLU, xtrmv_thread_CLN,
  76. #elif defined(DOUBLE)
  77. ztrmv_thread_NUU, ztrmv_thread_NUN, ztrmv_thread_NLU, ztrmv_thread_NLN,
  78. ztrmv_thread_TUU, ztrmv_thread_TUN, ztrmv_thread_TLU, ztrmv_thread_TLN,
  79. ztrmv_thread_RUU, ztrmv_thread_RUN, ztrmv_thread_RLU, ztrmv_thread_RLN,
  80. ztrmv_thread_CUU, ztrmv_thread_CUN, ztrmv_thread_CLU, ztrmv_thread_CLN,
  81. #else
  82. ctrmv_thread_NUU, ctrmv_thread_NUN, ctrmv_thread_NLU, ctrmv_thread_NLN,
  83. ctrmv_thread_TUU, ctrmv_thread_TUN, ctrmv_thread_TLU, ctrmv_thread_TLN,
  84. ctrmv_thread_RUU, ctrmv_thread_RUN, ctrmv_thread_RLU, ctrmv_thread_RLN,
  85. ctrmv_thread_CUU, ctrmv_thread_CUN, ctrmv_thread_CLU, ctrmv_thread_CLN,
  86. #endif
  87. };
  88. #endif
  89. #ifndef CBLAS
  90. void NAME(char *UPLO, char *TRANS, char *DIAG,
  91. blasint *N, FLOAT *a, blasint *LDA, FLOAT *x, blasint *INCX){
  92. char uplo_arg = *UPLO;
  93. char trans_arg = *TRANS;
  94. char diag_arg = *DIAG;
  95. blasint n = *N;
  96. blasint lda = *LDA;
  97. blasint incx = *INCX;
  98. blasint info;
  99. int uplo;
  100. int unit;
  101. int trans, buffer_size;
  102. FLOAT *buffer;
  103. #ifdef SMP
  104. int nthreads;
  105. #endif
  106. PRINT_DEBUG_NAME;
  107. TOUPPER(uplo_arg);
  108. TOUPPER(trans_arg);
  109. TOUPPER(diag_arg);
  110. trans = -1;
  111. unit = -1;
  112. uplo = -1;
  113. if (trans_arg == 'N') trans = 0;
  114. if (trans_arg == 'T') trans = 1;
  115. if (trans_arg == 'R') trans = 2;
  116. if (trans_arg == 'C') trans = 3;
  117. if (diag_arg == 'U') unit = 0;
  118. if (diag_arg == 'N') unit = 1;
  119. if (uplo_arg == 'U') uplo = 0;
  120. if (uplo_arg == 'L') uplo = 1;
  121. info = 0;
  122. if (incx == 0) info = 8;
  123. if (lda < MAX(1, n)) info = 6;
  124. if (n < 0) info = 4;
  125. if (unit < 0) info = 3;
  126. if (trans < 0) info = 2;
  127. if (uplo < 0) info = 1;
  128. if (info != 0) {
  129. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  130. return;
  131. }
  132. #else
  133. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo,
  134. enum CBLAS_TRANSPOSE TransA, enum CBLAS_DIAG Diag,
  135. blasint n, FLOAT *a, blasint lda, FLOAT *x, blasint incx) {
  136. int trans, uplo, unit, buffer_size;
  137. blasint info;
  138. FLOAT *buffer;
  139. #ifdef SMP
  140. int nthreads;
  141. #endif
  142. PRINT_DEBUG_CNAME;
  143. unit = -1;
  144. uplo = -1;
  145. trans = -1;
  146. info = 0;
  147. if (order == CblasColMajor) {
  148. if (Uplo == CblasUpper) uplo = 0;
  149. if (Uplo == CblasLower) uplo = 1;
  150. if (TransA == CblasNoTrans) trans = 0;
  151. if (TransA == CblasTrans) trans = 1;
  152. if (TransA == CblasConjNoTrans) trans = 2;
  153. if (TransA == CblasConjTrans) trans = 3;
  154. if (Diag == CblasUnit) unit = 0;
  155. if (Diag == CblasNonUnit) unit = 1;
  156. info = -1;
  157. if (incx == 0) info = 8;
  158. if (lda < MAX(1, n)) info = 6;
  159. if (n < 0) info = 4;
  160. if (unit < 0) info = 3;
  161. if (trans < 0) info = 2;
  162. if (uplo < 0) info = 1;
  163. }
  164. if (order == CblasRowMajor) {
  165. if (Uplo == CblasUpper) uplo = 1;
  166. if (Uplo == CblasLower) uplo = 0;
  167. if (TransA == CblasNoTrans) trans = 1;
  168. if (TransA == CblasTrans) trans = 0;
  169. if (TransA == CblasConjNoTrans) trans = 3;
  170. if (TransA == CblasConjTrans) trans = 2;
  171. if (Diag == CblasUnit) unit = 0;
  172. if (Diag == CblasNonUnit) unit = 1;
  173. info = -1;
  174. if (incx == 0) info = 8;
  175. if (lda < MAX(1, n)) info = 6;
  176. if (n < 0) info = 4;
  177. if (unit < 0) info = 3;
  178. if (trans < 0) info = 2;
  179. if (uplo < 0) info = 1;
  180. }
  181. if (info >= 0) {
  182. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  183. return;
  184. }
  185. #endif
  186. if (n == 0) return;
  187. IDEBUG_START;
  188. FUNCTION_PROFILE_START();
  189. if (incx < 0 ) x -= (n - 1) * incx * 2;
  190. #ifdef SMP
  191. // Calibrated on a Xeon E5-2630
  192. if(1L * n * n > 36L * sizeof(FLOAT) * sizeof(FLOAT) * GEMM_MULTITHREAD_THRESHOLD) {
  193. nthreads = num_cpu_avail(2);
  194. if(nthreads > 2 && 1L * n * n < 64L * sizeof(FLOAT) * sizeof(FLOAT) * GEMM_MULTITHREAD_THRESHOLD)
  195. nthreads = 2;
  196. } else
  197. nthreads = 1;
  198. if(nthreads > 1) {
  199. buffer_size = n > 16 ? 0 : n * 4 + 40;
  200. }
  201. else
  202. #endif
  203. {
  204. buffer_size = ((n - 1) / DTB_ENTRIES) * 2 * DTB_ENTRIES + 32 / sizeof(FLOAT);
  205. if(incx != 1)
  206. buffer_size += n * 2;
  207. }
  208. STACK_ALLOC(buffer_size, FLOAT, buffer);
  209. #ifdef SMP
  210. if (nthreads == 1) {
  211. #endif
  212. (trmv[(trans<<2) | (uplo<<1) | unit])(n, a, lda, x, incx, buffer);
  213. #ifdef SMP
  214. } else {
  215. (trmv_thread[(trans<<2) | (uplo<<1) | unit])(n, a, lda, x, incx, buffer, nthreads);
  216. }
  217. #endif
  218. STACK_FREE(buffer);
  219. FUNCTION_PROFILE_END(4, n * n / 2 + n, n * n);
  220. IDEBUG_END;
  221. return;
  222. }