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.

trsm.c 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. #ifndef TRMM
  45. #ifndef COMPLEX
  46. #ifdef XDOUBLE
  47. #define ERROR_NAME "QTRSM "
  48. #elif defined(DOUBLE)
  49. #define ERROR_NAME "DTRSM "
  50. #else
  51. #define ERROR_NAME "STRSM "
  52. #endif
  53. #else
  54. #ifdef XDOUBLE
  55. #define ERROR_NAME "XTRSM "
  56. #elif defined(DOUBLE)
  57. #define ERROR_NAME "ZTRSM "
  58. #else
  59. #define ERROR_NAME "CTRSM "
  60. #endif
  61. #endif
  62. #else
  63. #ifndef COMPLEX
  64. #ifdef XDOUBLE
  65. #define ERROR_NAME "QTRMM "
  66. #elif defined(DOUBLE)
  67. #define ERROR_NAME "DTRMM "
  68. #else
  69. #define ERROR_NAME "STRMM "
  70. #endif
  71. #else
  72. #ifdef XDOUBLE
  73. #define ERROR_NAME "XTRMM "
  74. #elif defined(DOUBLE)
  75. #define ERROR_NAME "ZTRMM "
  76. #else
  77. #define ERROR_NAME "CTRMM "
  78. #endif
  79. #endif
  80. #endif
  81. static int (*trsm[])(blas_arg_t *, BLASLONG *, BLASLONG *, FLOAT *, FLOAT *, BLASLONG) = {
  82. #ifndef TRMM
  83. TRSM_LNUU, TRSM_LNUN, TRSM_LNLU, TRSM_LNLN,
  84. TRSM_LTUU, TRSM_LTUN, TRSM_LTLU, TRSM_LTLN,
  85. TRSM_LRUU, TRSM_LRUN, TRSM_LRLU, TRSM_LRLN,
  86. TRSM_LCUU, TRSM_LCUN, TRSM_LCLU, TRSM_LCLN,
  87. TRSM_RNUU, TRSM_RNUN, TRSM_RNLU, TRSM_RNLN,
  88. TRSM_RTUU, TRSM_RTUN, TRSM_RTLU, TRSM_RTLN,
  89. TRSM_RRUU, TRSM_RRUN, TRSM_RRLU, TRSM_RRLN,
  90. TRSM_RCUU, TRSM_RCUN, TRSM_RCLU, TRSM_RCLN,
  91. #else
  92. TRMM_LNUU, TRMM_LNUN, TRMM_LNLU, TRMM_LNLN,
  93. TRMM_LTUU, TRMM_LTUN, TRMM_LTLU, TRMM_LTLN,
  94. TRMM_LRUU, TRMM_LRUN, TRMM_LRLU, TRMM_LRLN,
  95. TRMM_LCUU, TRMM_LCUN, TRMM_LCLU, TRMM_LCLN,
  96. TRMM_RNUU, TRMM_RNUN, TRMM_RNLU, TRMM_RNLN,
  97. TRMM_RTUU, TRMM_RTUN, TRMM_RTLU, TRMM_RTLN,
  98. TRMM_RRUU, TRMM_RRUN, TRMM_RRLU, TRMM_RRLN,
  99. TRMM_RCUU, TRMM_RCUN, TRMM_RCLU, TRMM_RCLN,
  100. #endif
  101. };
  102. #ifndef CBLAS
  103. void NAME(char *SIDE, char *UPLO, char *TRANS, char *DIAG,
  104. blasint *M, blasint *N, FLOAT *alpha,
  105. FLOAT *a, blasint *ldA, FLOAT *b, blasint *ldB){
  106. char side_arg = *SIDE;
  107. char uplo_arg = *UPLO;
  108. char trans_arg = *TRANS;
  109. char diag_arg = *DIAG;
  110. blas_arg_t args;
  111. FLOAT *buffer;
  112. FLOAT *sa, *sb;
  113. #ifdef SMP
  114. #ifndef COMPLEX
  115. #ifdef XDOUBLE
  116. int mode = BLAS_XDOUBLE | BLAS_REAL;
  117. #elif defined(DOUBLE)
  118. int mode = BLAS_DOUBLE | BLAS_REAL;
  119. #else
  120. int mode = BLAS_SINGLE | BLAS_REAL;
  121. #endif
  122. #else
  123. #ifdef XDOUBLE
  124. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  125. #elif defined(DOUBLE)
  126. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  127. #else
  128. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  129. #endif
  130. #endif
  131. #endif
  132. blasint info;
  133. int side;
  134. int uplo;
  135. int unit;
  136. int trans;
  137. int nrowa;
  138. PRINT_DEBUG_NAME;
  139. args.m = *M;
  140. args.n = *N;
  141. args.a = (void *)a;
  142. args.b = (void *)b;
  143. args.lda = *ldA;
  144. args.ldb = *ldB;
  145. args.beta = (void *)alpha;
  146. TOUPPER(side_arg);
  147. TOUPPER(uplo_arg);
  148. TOUPPER(trans_arg);
  149. TOUPPER(diag_arg);
  150. side = -1;
  151. trans = -1;
  152. unit = -1;
  153. uplo = -1;
  154. if (side_arg == 'L') side = 0;
  155. if (side_arg == 'R') side = 1;
  156. if (trans_arg == 'N') trans = 0;
  157. if (trans_arg == 'T') trans = 1;
  158. if (trans_arg == 'R') trans = 2;
  159. if (trans_arg == 'C') trans = 3;
  160. if (diag_arg == 'U') unit = 0;
  161. if (diag_arg == 'N') unit = 1;
  162. if (uplo_arg == 'U') uplo = 0;
  163. if (uplo_arg == 'L') uplo = 1;
  164. nrowa = args.m;
  165. if (side & 1) nrowa = args.n;
  166. info = 0;
  167. if (args.ldb < MAX(1,args.m)) info = 11;
  168. if (args.lda < MAX(1,nrowa)) info = 9;
  169. if (args.n < 0) info = 6;
  170. if (args.m < 0) info = 5;
  171. if (unit < 0) info = 4;
  172. if (trans < 0) info = 3;
  173. if (uplo < 0) info = 2;
  174. if (side < 0) info = 1;
  175. if (info != 0) {
  176. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  177. return;
  178. }
  179. #else
  180. void CNAME(enum CBLAS_ORDER order,
  181. enum CBLAS_SIDE Side, enum CBLAS_UPLO Uplo,
  182. enum CBLAS_TRANSPOSE Trans, enum CBLAS_DIAG Diag,
  183. blasint m, blasint n,
  184. #ifndef COMPLEX
  185. FLOAT alpha,
  186. #else
  187. FLOAT *alpha,
  188. #endif
  189. FLOAT *a, blasint lda,
  190. FLOAT *b, blasint ldb) {
  191. blas_arg_t args;
  192. int side, uplo, trans, unit;
  193. blasint info, nrowa;
  194. XFLOAT *buffer;
  195. XFLOAT *sa, *sb;
  196. #ifdef SMP
  197. #ifndef COMPLEX
  198. #ifdef XDOUBLE
  199. int mode = BLAS_XDOUBLE | BLAS_REAL;
  200. #elif defined(DOUBLE)
  201. int mode = BLAS_DOUBLE | BLAS_REAL;
  202. #else
  203. int mode = BLAS_SINGLE | BLAS_REAL;
  204. #endif
  205. #else
  206. #ifdef XDOUBLE
  207. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  208. #elif defined(DOUBLE)
  209. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  210. #else
  211. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  212. #endif
  213. #endif
  214. #endif
  215. PRINT_DEBUG_CNAME;
  216. args.a = (void *)a;
  217. args.b = (void *)b;
  218. args.lda = lda;
  219. args.ldb = ldb;
  220. #ifndef COMPLEX
  221. args.beta = (void *)&alpha;
  222. #else
  223. args.beta = (void *)alpha;
  224. #endif
  225. side = -1;
  226. uplo = -1;
  227. trans = -1;
  228. unit = -1;
  229. info = 0;
  230. if (order == CblasColMajor) {
  231. args.m = m;
  232. args.n = n;
  233. if (Side == CblasLeft) side = 0;
  234. if (Side == CblasRight) side = 1;
  235. if (Uplo == CblasUpper) uplo = 0;
  236. if (Uplo == CblasLower) uplo = 1;
  237. if (Trans == CblasNoTrans) trans = 0;
  238. if (Trans == CblasTrans) trans = 1;
  239. #ifndef COMPLEX
  240. if (Trans == CblasConjNoTrans) trans = 0;
  241. if (Trans == CblasConjTrans) trans = 1;
  242. #else
  243. if (Trans == CblasConjNoTrans) trans = 2;
  244. if (Trans == CblasConjTrans) trans = 3;
  245. #endif
  246. if (Diag == CblasUnit) unit = 0;
  247. if (Diag == CblasNonUnit) unit = 1;
  248. info = -1;
  249. nrowa = args.m;
  250. if (side & 1) nrowa = args.n;
  251. if (args.ldb < MAX(1,args.m)) info = 11;
  252. if (args.lda < MAX(1,nrowa)) info = 9;
  253. if (args.n < 0) info = 6;
  254. if (args.m < 0) info = 5;
  255. if (unit < 0) info = 4;
  256. if (trans < 0) info = 3;
  257. if (uplo < 0) info = 2;
  258. if (side < 0) info = 1;
  259. }
  260. if (order == CblasRowMajor) {
  261. args.m = n;
  262. args.n = m;
  263. if (Side == CblasLeft) side = 1;
  264. if (Side == CblasRight) side = 0;
  265. if (Uplo == CblasUpper) uplo = 1;
  266. if (Uplo == CblasLower) uplo = 0;
  267. if (Trans == CblasNoTrans) trans = 0;
  268. if (Trans == CblasTrans) trans = 1;
  269. #ifndef COMPLEX
  270. if (Trans == CblasConjNoTrans) trans = 0;
  271. if (Trans == CblasConjTrans) trans = 1;
  272. #else
  273. if (Trans == CblasConjNoTrans) trans = 2;
  274. if (Trans == CblasConjTrans) trans = 3;
  275. #endif
  276. if (Diag == CblasUnit) unit = 0;
  277. if (Diag == CblasNonUnit) unit = 1;
  278. info = -1;
  279. nrowa = args.m;
  280. if (side & 1) nrowa = args.n;
  281. if (args.ldb < MAX(1,args.m)) info = 11;
  282. if (args.lda < MAX(1,nrowa)) info = 9;
  283. if (args.n < 0) info = 6;
  284. if (args.m < 0) info = 5;
  285. if (unit < 0) info = 4;
  286. if (trans < 0) info = 3;
  287. if (uplo < 0) info = 2;
  288. if (side < 0) info = 1;
  289. }
  290. if (info >= 0) {
  291. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  292. return;
  293. }
  294. #endif
  295. if ((args.m == 0) || (args.n == 0)) return;
  296. IDEBUG_START;
  297. FUNCTION_PROFILE_START();
  298. buffer = (FLOAT *)blas_memory_alloc(0);
  299. sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
  300. sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  301. #ifdef SMP
  302. mode |= (trans << BLAS_TRANSA_SHIFT);
  303. mode |= (side << BLAS_RSIDE_SHIFT);
  304. args.nthreads = num_cpu_avail(3);
  305. if (args.nthreads == 1) {
  306. #endif
  307. (trsm[(side<<4) | (trans<<2) | (uplo<<1) | unit])(&args, NULL, NULL, sa, sb, 0);
  308. #ifdef SMP
  309. } else {
  310. if (!side) {
  311. gemm_thread_n(mode, &args, NULL, NULL, trsm[(side<<4) | (trans<<2) | (uplo<<1) | unit], sa, sb, args.nthreads);
  312. } else {
  313. gemm_thread_m(mode, &args, NULL, NULL, trsm[(side<<4) | (trans<<2) | (uplo<<1) | unit], sa, sb, args.nthreads);
  314. }
  315. }
  316. #endif
  317. blas_memory_free(buffer);
  318. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE,
  319. (!side) ? args.m * (args.m + args.n) : args.n * (args.m + args.n),
  320. (!side) ? args.m * args.m * args.n : args.m * args.n * args.n);
  321. IDEBUG_END;
  322. return;
  323. }