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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. if (trans_arg == 'N') trans = 0;
  130. if (trans_arg == 'T') trans = 1;
  131. if (trans_arg == 'R') trans = 0;
  132. if (trans_arg == 'C') trans = 1;
  133. nrowa = args.n;
  134. if (trans & 1) nrowa = args.k;
  135. info = 0;
  136. if (args.ldc < MAX(1,args.n)) info = 12;
  137. if (args.ldb < MAX(1,nrowa)) info = 9;
  138. if (args.lda < MAX(1,nrowa)) info = 7;
  139. if (args.k < 0) info = 4;
  140. if (args.n < 0) info = 3;
  141. if (trans < 0) info = 2;
  142. if (uplo < 0) info = 1;
  143. if (info != 0) {
  144. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  145. return;
  146. }
  147. #else
  148. void CNAME(enum CBLAS_ORDER order, enum CBLAS_UPLO Uplo, enum CBLAS_TRANSPOSE Trans,
  149. blasint n, blasint k,
  150. #ifndef COMPLEX
  151. FLOAT alpha,
  152. #else
  153. FLOAT *alpha,
  154. #endif
  155. FLOAT *a, blasint lda,
  156. FLOAT *b, blasint ldb,
  157. #if !defined(COMPLEX) || defined(HEMM)
  158. FLOAT beta,
  159. #else
  160. FLOAT *beta,
  161. #endif
  162. FLOAT *c, blasint ldc) {
  163. blas_arg_t args;
  164. int uplo, trans;
  165. blasint info, nrowa;
  166. FLOAT *buffer;
  167. FLOAT *sa, *sb;
  168. #ifdef HEMM
  169. FLOAT CAlpha[2];
  170. #endif
  171. #ifdef SMP
  172. #ifndef COMPLEX
  173. #ifdef XDOUBLE
  174. int mode = BLAS_XDOUBLE | BLAS_REAL;
  175. #elif defined(DOUBLE)
  176. int mode = BLAS_DOUBLE | BLAS_REAL;
  177. #else
  178. int mode = BLAS_SINGLE | BLAS_REAL;
  179. #endif
  180. #else
  181. #ifdef XDOUBLE
  182. int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  183. #elif defined(DOUBLE)
  184. int mode = BLAS_DOUBLE | BLAS_COMPLEX;
  185. #else
  186. int mode = BLAS_SINGLE | BLAS_COMPLEX;
  187. #endif
  188. #endif
  189. #endif
  190. PRINT_DEBUG_CNAME;
  191. args.n = n;
  192. args.k = k;
  193. args.a = (void *)a;
  194. args.b = (void *)b;
  195. args.c = (void *)c;
  196. args.lda = lda;
  197. args.ldb = ldb;
  198. args.ldc = ldc;
  199. #ifndef COMPLEX
  200. args.alpha = (void *)&alpha;
  201. #else
  202. args.alpha = (void *)alpha;
  203. #endif
  204. #if !defined(COMPLEX) || defined(HEMM)
  205. args.beta = (void *)&beta;
  206. #else
  207. args.beta = (void *)beta;
  208. #endif
  209. trans = -1;
  210. uplo = -1;
  211. info = 0;
  212. if (order == CblasColMajor) {
  213. if (Uplo == CblasUpper) uplo = 0;
  214. if (Uplo == CblasLower) uplo = 1;
  215. if (Trans == CblasNoTrans) trans = 0;
  216. #ifndef COMPLEX
  217. if (Trans == CblasTrans) trans = 1;
  218. if (Trans == CblasConjNoTrans) trans = 0;
  219. if (Trans == CblasConjTrans) trans = 1;
  220. #elif !defined(HEMM)
  221. if (Trans == CblasTrans) trans = 1;
  222. #else
  223. if (Trans == CblasConjTrans) trans = 1;
  224. #endif
  225. info = -1;
  226. nrowa = args.n;
  227. if (trans & 1) nrowa = args.k;
  228. if (args.ldc < MAX(1,args.n)) info = 12;
  229. if (args.ldb < MAX(1,nrowa)) info = 9;
  230. if (args.lda < MAX(1,nrowa)) info = 7;
  231. if (args.k < 0) info = 4;
  232. if (args.n < 0) info = 3;
  233. if (trans < 0) info = 2;
  234. if (uplo < 0) info = 1;
  235. }
  236. if (order == CblasRowMajor) {
  237. #ifdef HEMM
  238. CAlpha[0] = alpha[0];
  239. CAlpha[1] = -alpha[1];
  240. args.alpha = (void *)CAlpha;
  241. #endif
  242. if (Uplo == CblasUpper) uplo = 1;
  243. if (Uplo == CblasLower) uplo = 0;
  244. if (Trans == CblasNoTrans) trans = 1;
  245. #ifndef COMPLEX
  246. if (Trans == CblasTrans) trans = 0;
  247. if (Trans == CblasConjNoTrans) trans = 1;
  248. if (Trans == CblasConjTrans) trans = 0;
  249. #elif !defined(HEMM)
  250. if (Trans == CblasTrans) trans = 0;
  251. #else
  252. if (Trans == CblasConjTrans) trans = 0;
  253. #endif
  254. info = -1;
  255. nrowa = args.n;
  256. if (trans & 1) nrowa = args.k;
  257. if (args.ldc < MAX(1,args.n)) info = 12;
  258. if (args.ldb < MAX(1,nrowa)) info = 9;
  259. if (args.lda < MAX(1,nrowa)) info = 7;
  260. if (args.k < 0) info = 4;
  261. if (args.n < 0) info = 3;
  262. if (trans < 0) info = 2;
  263. if (uplo < 0) info = 1;
  264. }
  265. if (info >= 0) {
  266. BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
  267. return;
  268. }
  269. #endif
  270. if (args.n == 0) return;
  271. IDEBUG_START;
  272. FUNCTION_PROFILE_START();
  273. buffer = (FLOAT *)blas_memory_alloc(0);
  274. sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
  275. sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
  276. #ifdef SMP
  277. if (!trans){
  278. mode |= (BLAS_TRANSA_N | BLAS_TRANSB_T);
  279. } else {
  280. mode |= (BLAS_TRANSA_T | BLAS_TRANSB_N);
  281. }
  282. mode |= (uplo << BLAS_UPLO_SHIFT);
  283. args.common = NULL;
  284. args.nthreads = num_cpu_avail(3);
  285. if (args.nthreads == 1) {
  286. #endif
  287. (syr2k[(uplo << 1) | trans ])(&args, NULL, NULL, sa, sb, 0);
  288. #ifdef SMP
  289. } else {
  290. syrk_thread(mode, &args, NULL, NULL, syr2k[(uplo << 1) | trans ], sa, sb, args.nthreads);
  291. }
  292. #endif
  293. blas_memory_free(buffer);
  294. FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE, 2 * args.n * args.k + args.n * args.n, 2 * args.n * args.n * args.k);
  295. IDEBUG_END;
  296. return;
  297. }

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.