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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. FLOAT *a, blasint lda,
  162. FLOAT *b, blasint ldb,
  163. #else
  164. void *valpha,
  165. void *va, blasint lda,
  166. void *vb, blasint ldb,
  167. #endif
  168. #if !defined(COMPLEX) || defined(HEMM)
  169. FLOAT beta,
  170. #else
  171. void *vbeta,
  172. #endif
  173. #ifndef COMPLEX
  174. FLOAT *c,
  175. #else
  176. void *vc,
  177. #endif
  178. blasint ldc) {
  179. #ifdef COMPLEX
  180. FLOAT* alpha = (FLOAT*) valpha;
  181. #if !defined(HEMM)
  182. FLOAT* beta = (FLOAT*) vbeta;
  183. #endif
  184. FLOAT* a = (FLOAT*) va;
  185. FLOAT* b = (FLOAT*) vb;
  186. FLOAT* c = (FLOAT*) vc;
  187. #endif
  188. blas_arg_t args;
  189. int uplo, trans;
  190. blasint info, nrowa;
  191. FLOAT *buffer;
  192. FLOAT *sa, *sb;
  193. #ifdef HEMM
  194. FLOAT CAlpha[2];
  195. #endif
  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.n = n;
  217. args.k = k;
  218. args.a = (void *)a;
  219. args.b = (void *)b;
  220. args.c = (void *)c;
  221. args.lda = lda;
  222. args.ldb = ldb;
  223. args.ldc = ldc;
  224. #ifndef COMPLEX
  225. args.alpha = (void *)&alpha;
  226. #else
  227. args.alpha = (void *)alpha;
  228. #endif
  229. #if !defined(COMPLEX) || defined(HEMM)
  230. args.beta = (void *)&beta;
  231. #else
  232. args.beta = (void *)beta;
  233. #endif
  234. trans = -1;
  235. uplo = -1;
  236. info = 0;
  237. if (order == CblasColMajor) {
  238. if (Uplo == CblasUpper) uplo = 0;
  239. if (Uplo == CblasLower) uplo = 1;
  240. if (Trans == CblasNoTrans) trans = 0;
  241. #ifndef COMPLEX
  242. if (Trans == CblasTrans) trans = 1;
  243. if (Trans == CblasConjNoTrans) trans = 0;
  244. if (Trans == CblasConjTrans) trans = 1;
  245. #elif !defined(HEMM)
  246. if (Trans == CblasTrans) trans = 1;
  247. #else
  248. if (Trans == CblasConjTrans) trans = 1;
  249. #endif
  250. info = -1;
  251. nrowa = args.n;
  252. if (trans & 1) nrowa = args.k;
  253. if (args.ldc < MAX(1,args.n)) info = 12;
  254. if (args.ldb < MAX(1,nrowa)) info = 9;
  255. if (args.lda < MAX(1,nrowa)) info = 7;
  256. if (args.k < 0) info = 4;
  257. if (args.n < 0) info = 3;
  258. if (trans < 0) info = 2;
  259. if (uplo < 0) info = 1;
  260. }
  261. if (order == CblasRowMajor) {
  262. #ifdef HEMM
  263. CAlpha[0] = alpha[0];
  264. CAlpha[1] = -alpha[1];
  265. args.alpha = (void *)CAlpha;
  266. #endif
  267. if (Uplo == CblasUpper) uplo = 1;
  268. if (Uplo == CblasLower) uplo = 0;
  269. if (Trans == CblasNoTrans) trans = 1;
  270. #ifndef COMPLEX
  271. if (Trans == CblasTrans) trans = 0;
  272. if (Trans == CblasConjNoTrans) trans = 1;
  273. if (Trans == CblasConjTrans) trans = 0;
  274. #elif !defined(HEMM)
  275. if (Trans == CblasTrans) trans = 0;
  276. #else
  277. if (Trans == CblasConjTrans) trans = 0;
  278. #endif
  279. info = -1;
  280. nrowa = args.n;
  281. if (trans & 1) nrowa = args.k;
  282. if (args.ldc < MAX(1,args.n)) info = 12;
  283. if (args.ldb < MAX(1,nrowa)) info = 9;
  284. if (args.lda < MAX(1,nrowa)) info = 7;
  285. if (args.k < 0) info = 4;
  286. if (args.n < 0) info = 3;
  287. if (trans < 0) info = 2;
  288. if (uplo < 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.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. if (!trans){
  303. mode |= (BLAS_TRANSA_N | BLAS_TRANSB_T);
  304. } else {
  305. mode |= (BLAS_TRANSA_T | BLAS_TRANSB_N);
  306. }
  307. mode |= (uplo << BLAS_UPLO_SHIFT);
  308. args.common = NULL;
  309. if (args.n*args.k <1000)
  310. args.nthreads =1 ;
  311. else
  312. args.nthreads = num_cpu_avail(3);
  313. if (args.nthreads == 1) {
  314. #endif
  315. (syr2k[(uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  316. #ifdef SMP
  317. } else {
  318. syrk_thread(mode, &args, NULL, NULL, syr2k[(uplo << 1) | trans ], sa, sb, args.nthreads);
  319. }
  320. #endif
  321. blas_memory_free(buffer);
  322. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE, 2 * args.n * args.k + args.n * args.n, 2 * args.n * args.n * args.k);
  323. IDEBUG_END;
  324. return;
  325. }