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.

syr2k.c 9.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 COMPLEX
  45. #ifdef XDOUBLE
  46. #define ERROR_NAME "QSYR2K"
  47. #elif defined(DOUBLE)
  48. #define ERROR_NAME "DSYR2K"
  49. #else
  50. #define ERROR_NAME "SSYR2K"
  51. #endif
  52. #else
  53. #ifndef HEMM
  54. #ifdef XDOUBLE
  55. #define ERROR_NAME "XSYR2K"
  56. #elif defined(DOUBLE)
  57. #define ERROR_NAME "ZSYR2K"
  58. #else
  59. #define ERROR_NAME "CSYR2K"
  60. #endif
  61. #else
  62. #ifdef XDOUBLE
  63. #define ERROR_NAME "XHER2K"
  64. #elif defined(DOUBLE)
  65. #define ERROR_NAME "ZHER2K"
  66. #else
  67. #define ERROR_NAME "CHER2K"
  68. #endif
  69. #endif
  70. #endif
  71. static int (*syr2k[])(blas_arg_t *, BLASLONG *, BLASLONG *, FLOAT *, FLOAT *, BLASLONG) = {
  72. #ifndef HEMM
  73. SYR2K_UN, SYR2K_UC, SYR2K_LN, SYR2K_LC,
  74. #else
  75. HER2K_UN, HER2K_UC, HER2K_LN, HER2K_LC,
  76. #endif
  77. };
  78. #ifndef CBLAS
  79. void NAME(char *UPLO, char *TRANS,
  80. blasint *N, blasint *K,
  81. FLOAT *alpha, FLOAT *a, blasint *ldA,
  82. FLOAT *b, blasint *ldB,
  83. FLOAT *beta, FLOAT *c, blasint *ldC){
  84. char uplo_arg = *UPLO;
  85. char trans_arg = *TRANS;
  86. blas_arg_t args;
  87. FLOAT *buffer;
  88. FLOAT *sa, *sb;
  89. #ifdef SMP
  90. #ifndef COMPLEX
  91. #ifdef XDOUBLE
  92. int mode = BLAS_XDOUBLE | BLAS_REAL;
  93. #elif defined(DOUBLE)
  94. int mode = BLAS_DOUBLE | BLAS_REAL;
  95. #else
  96. int mode = BLAS_SINGLE | BLAS_REAL;
  97. #endif
  98. #else
  99. #ifdef XDOUBLE
  100. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  101. #elif defined(DOUBLE)
  102. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  103. #else
  104. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  105. #endif
  106. #endif
  107. #endif
  108. blasint info;
  109. int uplo;
  110. int trans;
  111. int nrowa;
  112. PRINT_DEBUG_NAME;
  113. args.n = *N;
  114. args.k = *K;
  115. args.a = (void *)a;
  116. args.b = (void *)b;
  117. args.c = (void *)c;
  118. args.lda = *ldA;
  119. args.ldb = *ldB;
  120. args.ldc = *ldC;
  121. args.alpha = (void *)alpha;
  122. args.beta = (void *)beta;
  123. TOUPPER(uplo_arg);
  124. TOUPPER(trans_arg);
  125. uplo = -1;
  126. trans = -1;
  127. if (uplo_arg == 'U') uplo = 0;
  128. if (uplo_arg == 'L') uplo = 1;
  129. #ifndef COMPLEX
  130. if (trans_arg == 'N') trans = 0;
  131. if (trans_arg == 'T') trans = 1;
  132. if (trans_arg == 'C') trans = 1;
  133. #else
  134. #ifdef HEMM
  135. if (trans_arg == 'N') trans = 0;
  136. if (trans_arg == 'C') trans = 1;
  137. #else
  138. if (trans_arg == 'N') trans = 0;
  139. if (trans_arg == 'T') trans = 1;
  140. #endif
  141. #endif
  142. nrowa = args.n;
  143. if (trans & 1) nrowa = args.k;
  144. info = 0;
  145. if (args.ldc < MAX(1,args.n)) info = 12;
  146. if (args.ldb < MAX(1,nrowa)) info = 9;
  147. if (args.lda < MAX(1,nrowa)) info = 7;
  148. if (args.k < 0) info = 4;
  149. if (args.n < 0) info = 3;
  150. if (trans < 0) info = 2;
  151. if (uplo < 0) info = 1;
  152. if (info != 0) {
  153. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  154. return;
  155. }
  156. #else
  157. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE Trans,
  158. blasint n, blasint k,
  159. #ifndef COMPLEX
  160. FLOAT alpha,
  161. #else
  162. FLOAT *alpha,
  163. #endif
  164. FLOAT *a, blasint lda,
  165. FLOAT *b, blasint ldb,
  166. #if !defined(COMPLEX) || defined(HEMM)
  167. FLOAT beta,
  168. #else
  169. FLOAT *beta,
  170. #endif
  171. FLOAT *c, blasint ldc) {
  172. blas_arg_t args;
  173. int uplo, trans;
  174. blasint info, nrowa;
  175. FLOAT *buffer;
  176. FLOAT *sa, *sb;
  177. #ifdef HEMM
  178. FLOAT CAlpha[2];
  179. #endif
  180. #ifdef SMP
  181. #ifndef COMPLEX
  182. #ifdef XDOUBLE
  183. int mode = BLAS_XDOUBLE | BLAS_REAL;
  184. #elif defined(DOUBLE)
  185. int mode = BLAS_DOUBLE | BLAS_REAL;
  186. #else
  187. int mode = BLAS_SINGLE | BLAS_REAL;
  188. #endif
  189. #else
  190. #ifdef XDOUBLE
  191. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  192. #elif defined(DOUBLE)
  193. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  194. #else
  195. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  196. #endif
  197. #endif
  198. #endif
  199. PRINT_DEBUG_CNAME;
  200. args.n = n;
  201. args.k = k;
  202. args.a = (void *)a;
  203. args.b = (void *)b;
  204. args.c = (void *)c;
  205. args.lda = lda;
  206. args.ldb = ldb;
  207. args.ldc = ldc;
  208. #ifndef COMPLEX
  209. args.alpha = (void *)&alpha;
  210. #else
  211. args.alpha = (void *)alpha;
  212. #endif
  213. #if !defined(COMPLEX) || defined(HEMM)
  214. args.beta = (void *)&beta;
  215. #else
  216. args.beta = (void *)beta;
  217. #endif
  218. trans = -1;
  219. uplo = -1;
  220. info = 0;
  221. if (order == CblasColMajor) {
  222. if (Uplo == CblasUpper) uplo = 0;
  223. if (Uplo == CblasLower) uplo = 1;
  224. if (Trans == CblasNoTrans) trans = 0;
  225. #ifndef COMPLEX
  226. if (Trans == CblasTrans) trans = 1;
  227. if (Trans == CblasConjNoTrans) trans = 0;
  228. if (Trans == CblasConjTrans) trans = 1;
  229. #elif !defined(HEMM)
  230. if (Trans == CblasTrans) trans = 1;
  231. #else
  232. if (Trans == CblasConjTrans) trans = 1;
  233. #endif
  234. info = -1;
  235. nrowa = args.n;
  236. if (trans & 1) nrowa = args.k;
  237. if (args.ldc < MAX(1,args.n)) info = 12;
  238. if (args.ldb < MAX(1,nrowa)) info = 9;
  239. if (args.lda < MAX(1,nrowa)) info = 7;
  240. if (args.k < 0) info = 4;
  241. if (args.n < 0) info = 3;
  242. if (trans < 0) info = 2;
  243. if (uplo < 0) info = 1;
  244. }
  245. if (order == CblasRowMajor) {
  246. #ifdef HEMM
  247. CAlpha[0] = alpha[0];
  248. CAlpha[1] = -alpha[1];
  249. args.alpha = (void *)CAlpha;
  250. #endif
  251. if (Uplo == CblasUpper) uplo = 1;
  252. if (Uplo == CblasLower) uplo = 0;
  253. if (Trans == CblasNoTrans) trans = 1;
  254. #ifndef COMPLEX
  255. if (Trans == CblasTrans) trans = 0;
  256. if (Trans == CblasConjNoTrans) trans = 1;
  257. if (Trans == CblasConjTrans) trans = 0;
  258. #elif !defined(HEMM)
  259. if (Trans == CblasTrans) trans = 0;
  260. #else
  261. if (Trans == CblasConjTrans) trans = 0;
  262. #endif
  263. info = -1;
  264. nrowa = args.n;
  265. if (trans & 1) nrowa = args.k;
  266. if (args.ldc < MAX(1,args.n)) info = 12;
  267. if (args.ldb < MAX(1,nrowa)) info = 9;
  268. if (args.lda < MAX(1,nrowa)) info = 7;
  269. if (args.k < 0) info = 4;
  270. if (args.n < 0) info = 3;
  271. if (trans < 0) info = 2;
  272. if (uplo < 0) info = 1;
  273. }
  274. if (info >= 0) {
  275. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  276. return;
  277. }
  278. #endif
  279. if (args.n == 0) return;
  280. IDEBUG_START;
  281. FUNCTION_PROFILE_START();
  282. buffer = (FLOAT *)blas_memory_alloc(0);
  283. sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
  284. sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  285. #ifdef SMP
  286. if (!trans){
  287. mode |= (BLAS_TRANSA_N | BLAS_TRANSB_T);
  288. } else {
  289. mode |= (BLAS_TRANSA_T | BLAS_TRANSB_N);
  290. }
  291. mode |= (uplo << BLAS_UPLO_SHIFT);
  292. args.common = NULL;
  293. args.nthreads = num_cpu_avail(3);
  294. if (args.nthreads == 1) {
  295. #endif
  296. (syr2k[(uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  297. #ifdef SMP
  298. } else {
  299. syrk_thread(mode, &args, NULL, NULL, syr2k[(uplo << 1) | trans ], sa, sb, args.nthreads);
  300. }
  301. #endif
  302. blas_memory_free(buffer);
  303. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE, 2 * args.n * args.k + args.n * args.n, 2 * args.n * args.n * args.k);
  304. IDEBUG_END;
  305. return;
  306. }