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.

potrf_parallel.c 17 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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 "common.h"
  40. #ifndef USE_SIMPLE_THREADED_LEVEL3
  41. //The array of job_t may overflow the stack.
  42. //Instead, use malloc to alloc job_t.
  43. #if MAX_CPU_NUMBER > BLAS3_MEM_ALLOC_THRESHOLD
  44. #define USE_ALLOC_HEAP
  45. #endif
  46. static FLOAT dm1 = -1.;
  47. #ifndef KERNEL_FUNC
  48. #ifndef LOWER
  49. #define KERNEL_FUNC SYRK_KERNEL_U
  50. #else
  51. #define KERNEL_FUNC SYRK_KERNEL_L
  52. #endif
  53. #endif
  54. #ifndef LOWER
  55. #ifndef COMPLEX
  56. #define TRSM_KERNEL TRSM_KERNEL_LT
  57. #else
  58. #define TRSM_KERNEL TRSM_KERNEL_LC
  59. #endif
  60. #else
  61. #ifndef COMPLEX
  62. #define TRSM_KERNEL TRSM_KERNEL_RN
  63. #else
  64. #define TRSM_KERNEL TRSM_KERNEL_RR
  65. #endif
  66. #endif
  67. #ifndef CACHE_LINE_SIZE
  68. #define CACHE_LINE_SIZE 8
  69. #endif
  70. #ifndef DIVIDE_RATE
  71. #define DIVIDE_RATE 2
  72. #endif
  73. #ifndef SWITCH_RATIO
  74. #define SWITCH_RATIO 2
  75. #endif
  76. #ifndef LOWER
  77. #define TRANS
  78. #endif
  79. #ifndef SYRK_LOCAL
  80. #if !defined(LOWER) && !defined(TRANS)
  81. #define SYRK_LOCAL SYRK_UN
  82. #elif !defined(LOWER) && defined(TRANS)
  83. #define SYRK_LOCAL SYRK_UT
  84. #elif defined(LOWER) && !defined(TRANS)
  85. #define SYRK_LOCAL SYRK_LN
  86. #else
  87. #define SYRK_LOCAL SYRK_LT
  88. #endif
  89. #endif
  90. typedef struct {
  91. volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
  92. } job_t;
  93. #ifndef KERNEL_OPERATION
  94. #ifndef COMPLEX
  95. #define KERNEL_OPERATION(M, N, K, ALPHA, SA, SB, C, LDC, X, Y) \
  96. KERNEL_FUNC(M, N, K, ALPHA[0], SA, SB, (FLOAT *)(C) + ((X) + (Y) * LDC) * COMPSIZE, LDC, (X) - (Y))
  97. #else
  98. #define KERNEL_OPERATION(M, N, K, ALPHA, SA, SB, C, LDC, X, Y) \
  99. KERNEL_FUNC(M, N, K, ALPHA[0], ALPHA[1], SA, SB, (FLOAT *)(C) + ((X) + (Y) * LDC) * COMPSIZE, LDC, (X) - (Y))
  100. #endif
  101. #endif
  102. #ifndef ICOPY_OPERATION
  103. #ifndef TRANS
  104. #define ICOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_ITCOPY(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER);
  105. #else
  106. #define ICOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_INCOPY(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, BUFFER);
  107. #endif
  108. #endif
  109. #ifndef OCOPY_OPERATION
  110. #ifdef TRANS
  111. #define OCOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_ONCOPY(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, BUFFER);
  112. #else
  113. #define OCOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_OTCOPY(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER);
  114. #endif
  115. #endif
  116. #ifndef S
  117. #define S args -> a
  118. #endif
  119. #ifndef A
  120. #define A args -> b
  121. #endif
  122. #ifndef C
  123. #define C args -> c
  124. #endif
  125. #ifndef LDA
  126. #define LDA args -> lda
  127. #endif
  128. #ifndef N
  129. #define N args -> m
  130. #endif
  131. #ifndef K
  132. #define K args -> k
  133. #endif
  134. static int inner_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG mypos){
  135. FLOAT *buffer[DIVIDE_RATE];
  136. BLASLONG k, lda;
  137. BLASLONG m_from, m_to;
  138. FLOAT *alpha;
  139. FLOAT *a, *c;
  140. job_t *job = (job_t *)args -> common;
  141. BLASLONG xxx, bufferside;
  142. BLASLONG jjs, min_jj;
  143. BLASLONG is, min_i, div_n;
  144. BLASLONG i, current;
  145. k = K;
  146. a = (FLOAT *)A;
  147. c = (FLOAT *)C;
  148. lda = LDA;
  149. alpha = (FLOAT *)args -> alpha;
  150. m_from = range_n[mypos + 0];
  151. m_to = range_n[mypos + 1];
  152. #if 0
  153. fprintf(stderr, "Thread[%ld] m_from : %ld m_to : %ld\n", mypos, m_from, m_to);
  154. #endif
  155. div_n = ((m_to - m_from + DIVIDE_RATE - 1) / DIVIDE_RATE + GEMM_UNROLL_MN - 1) & ~(GEMM_UNROLL_MN - 1);
  156. buffer[0] = (FLOAT *)((((BLASULONG)(sb + k * k * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
  157. for (i = 1; i < DIVIDE_RATE; i++) {
  158. buffer[i] = buffer[i - 1] + GEMM_Q * div_n * COMPSIZE;
  159. }
  160. #ifndef LOWER
  161. TRSM_IUNCOPY(k, k, (FLOAT *)S, lda, 0, sb);
  162. #else
  163. TRSM_OLTCOPY(k, k, (FLOAT *)S, lda, 0, sb);
  164. #endif
  165. for (xxx = m_from, bufferside = 0; xxx < m_to; xxx += div_n, bufferside ++) {
  166. for(jjs = xxx; jjs < MIN(m_to, xxx + div_n); jjs += min_jj){
  167. min_jj = MIN(m_to, xxx + div_n) - jjs;
  168. #ifndef LOWER
  169. if (min_jj > GEMM_UNROLL_MN) min_jj = GEMM_UNROLL_MN;
  170. #else
  171. if (min_jj > GEMM_P) min_jj = GEMM_P;
  172. #endif
  173. #ifndef LOWER
  174. OCOPY_OPERATION (k, min_jj, a, lda, 0, jjs, buffer[bufferside] + k * (jjs - xxx) * COMPSIZE);
  175. TRSM_KERNEL (k, min_jj, k, dm1,
  176. #ifdef COMPLEX
  177. ZERO,
  178. #endif
  179. sb,
  180. buffer[bufferside] + k * (jjs - xxx) * COMPSIZE,
  181. a + jjs * lda * COMPSIZE, lda, 0);
  182. #else
  183. ICOPY_OPERATION (k, min_jj, a, lda, 0, jjs, buffer[bufferside] + k * (jjs - xxx) * COMPSIZE);
  184. TRSM_KERNEL (min_jj, k, k, dm1,
  185. #ifdef COMPLEX
  186. ZERO,
  187. #endif
  188. buffer[bufferside] + k * (jjs - xxx) * COMPSIZE,
  189. sb,
  190. a + jjs * COMPSIZE, lda, 0);
  191. #endif
  192. }
  193. #ifndef LOWER
  194. for (i = 0; i <= mypos; i++)
  195. job[mypos].working[i][CACHE_LINE_SIZE * bufferside] = (BLASLONG)buffer[bufferside];
  196. #else
  197. for (i = mypos; i < args -> nthreads; i++)
  198. job[mypos].working[i][CACHE_LINE_SIZE * bufferside] = (BLASLONG)buffer[bufferside];
  199. #endif
  200. WMB;
  201. }
  202. min_i = m_to - m_from;
  203. if (min_i >= GEMM_P * 2) {
  204. min_i = GEMM_P;
  205. } else
  206. if (min_i > GEMM_P) {
  207. min_i = ((min_i + 1) / 2 + GEMM_UNROLL_MN - 1) & ~(GEMM_UNROLL_MN - 1);
  208. }
  209. #ifndef LOWER
  210. ICOPY_OPERATION(k, min_i, a, lda, 0, m_from, sa);
  211. #else
  212. OCOPY_OPERATION(k, min_i, a, lda, 0, m_from, sa);
  213. #endif
  214. current = mypos;
  215. #ifndef LOWER
  216. while (current < args -> nthreads)
  217. #else
  218. while (current >= 0)
  219. #endif
  220. {
  221. div_n = ((range_n[current + 1] - range_n[current] + DIVIDE_RATE - 1) / DIVIDE_RATE + GEMM_UNROLL_MN - 1) & ~(GEMM_UNROLL_MN - 1);
  222. for (xxx = range_n[current], bufferside = 0; xxx < range_n[current + 1]; xxx += div_n, bufferside ++) {
  223. /* thread has to wait */
  224. if (current != mypos) while(job[current].working[mypos][CACHE_LINE_SIZE * bufferside] == 0) {YIELDING;};
  225. KERNEL_OPERATION(min_i, MIN(range_n[current + 1] - xxx, div_n), k, alpha,
  226. sa, (FLOAT *)job[current].working[mypos][CACHE_LINE_SIZE * bufferside],
  227. c, lda, m_from, xxx);
  228. if (m_from + min_i >= m_to) {
  229. job[current].working[mypos][CACHE_LINE_SIZE * bufferside] &= 0;
  230. WMB;
  231. }
  232. }
  233. #ifndef LOWER
  234. current ++;
  235. #else
  236. current --;
  237. #endif
  238. }
  239. for(is = m_from + min_i; is < m_to; is += min_i){
  240. min_i = m_to - is;
  241. if (min_i >= GEMM_P * 2) {
  242. min_i = GEMM_P;
  243. } else
  244. if (min_i > GEMM_P) {
  245. min_i = ((min_i + 1) / 2 + GEMM_UNROLL_MN - 1) & ~(GEMM_UNROLL_MN - 1);
  246. }
  247. #ifndef LOWER
  248. ICOPY_OPERATION(k, min_i, a, lda, 0, is, sa);
  249. #else
  250. OCOPY_OPERATION(k, min_i, a, lda, 0, is, sa);
  251. #endif
  252. current = mypos;
  253. #ifndef LOWER
  254. while (current < args -> nthreads)
  255. #else
  256. while (current >= 0)
  257. #endif
  258. {
  259. div_n = ((range_n[current + 1] - range_n[current] + DIVIDE_RATE - 1) / DIVIDE_RATE + GEMM_UNROLL_MN - 1) & ~(GEMM_UNROLL_MN - 1);
  260. for (xxx = range_n[current], bufferside = 0; xxx < range_n[current + 1]; xxx += div_n, bufferside ++) {
  261. KERNEL_OPERATION(min_i, MIN(range_n[current + 1] - xxx, div_n), k, alpha,
  262. sa, (FLOAT *)job[current].working[mypos][CACHE_LINE_SIZE * bufferside],
  263. c, lda, is, xxx);
  264. if (is + min_i >= m_to) {
  265. job[current].working[mypos][CACHE_LINE_SIZE * bufferside] &= 0;
  266. WMB;
  267. }
  268. }
  269. #ifndef LOWER
  270. current ++;
  271. #else
  272. current --;
  273. #endif
  274. }
  275. }
  276. for (i = 0; i < args -> nthreads; i++) {
  277. if (i != mypos) {
  278. for (xxx = 0; xxx < DIVIDE_RATE; xxx++) {
  279. while (job[mypos].working[i][CACHE_LINE_SIZE * xxx] ) {YIELDING;};
  280. }
  281. }
  282. }
  283. return 0;
  284. }
  285. static int thread_driver(blas_arg_t *args, FLOAT *sa, FLOAT *sb){
  286. blas_arg_t newarg;
  287. #ifndef USE_ALLOC_HEAP
  288. job_t job[MAX_CPU_NUMBER];
  289. #else
  290. job_t * job = NULL;
  291. #endif
  292. blas_queue_t queue[MAX_CPU_NUMBER];
  293. BLASLONG range[MAX_CPU_NUMBER + 100];
  294. BLASLONG num_cpu;
  295. BLASLONG nthreads = args -> nthreads;
  296. BLASLONG width, i, j, k;
  297. BLASLONG n, n_from, n_to;
  298. int mode, mask;
  299. double dnum;
  300. #ifndef COMPLEX
  301. #ifdef XDOUBLE
  302. mode = BLAS_XDOUBLE | BLAS_REAL;
  303. mask = MAX(QGEMM_UNROLL_M, QGEMM_UNROLL_N) - 1;
  304. #elif defined(DOUBLE)
  305. mode = BLAS_DOUBLE | BLAS_REAL;
  306. mask = MAX(DGEMM_UNROLL_M, DGEMM_UNROLL_N) - 1;
  307. #else
  308. mode = BLAS_SINGLE | BLAS_REAL;
  309. mask = MAX(SGEMM_UNROLL_M, SGEMM_UNROLL_N) - 1;
  310. #endif
  311. #else
  312. #ifdef XDOUBLE
  313. mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  314. mask = MAX(XGEMM_UNROLL_M, XGEMM_UNROLL_N) - 1;
  315. #elif defined(DOUBLE)
  316. mode = BLAS_DOUBLE | BLAS_COMPLEX;
  317. mask = MAX(ZGEMM_UNROLL_M, ZGEMM_UNROLL_N) - 1;
  318. #else
  319. mode = BLAS_SINGLE | BLAS_COMPLEX;
  320. mask = MAX(CGEMM_UNROLL_M, CGEMM_UNROLL_N) - 1;
  321. #endif
  322. #endif
  323. newarg.m = args -> m;
  324. newarg.k = args -> k;
  325. newarg.a = args -> a;
  326. newarg.b = args -> b;
  327. newarg.c = args -> c;
  328. newarg.lda = args -> lda;
  329. newarg.alpha = args -> alpha;
  330. #ifdef USE_ALLOC_HEAP
  331. job = (job_t*)malloc(MAX_CPU_NUMBER * sizeof(job_t));
  332. if(job==NULL){
  333. fprintf(stderr, "OpenBLAS: malloc failed in %s\n", __func__);
  334. exit(1);
  335. }
  336. #endif
  337. newarg.common = (void *)job;
  338. n_from = 0;
  339. n_to = args -> m;
  340. #ifndef LOWER
  341. range[MAX_CPU_NUMBER] = n_to - n_from;
  342. range[0] = 0;
  343. num_cpu = 0;
  344. i = 0;
  345. n = n_to - n_from;
  346. dnum = (double)n * (double)n /(double)nthreads;
  347. while (i < n){
  348. if (nthreads - num_cpu > 1) {
  349. double di = (double)i;
  350. width = (((BLASLONG)(sqrt(di * di + dnum) - di) + mask) & ~mask);
  351. if (num_cpu == 0) width = n - ((n - width) & ~mask);
  352. if ((width > n - i) || (width < mask)) width = n - i;
  353. } else {
  354. width = n - i;
  355. }
  356. range[MAX_CPU_NUMBER - num_cpu - 1] = range[MAX_CPU_NUMBER - num_cpu] - width;
  357. queue[num_cpu].mode = mode;
  358. queue[num_cpu].routine = inner_thread;
  359. queue[num_cpu].args = &newarg;
  360. queue[num_cpu].range_m = NULL;
  361. queue[num_cpu].sa = NULL;
  362. queue[num_cpu].sb = NULL;
  363. queue[num_cpu].next = &queue[num_cpu + 1];
  364. num_cpu ++;
  365. i += width;
  366. }
  367. for (i = 0; i < num_cpu; i ++) queue[i].range_n = &range[MAX_CPU_NUMBER - num_cpu];
  368. #else
  369. range[0] = 0;
  370. num_cpu = 0;
  371. i = 0;
  372. n = n_to - n_from;
  373. dnum = (double)n * (double)n /(double)nthreads;
  374. while (i < n){
  375. if (nthreads - num_cpu > 1) {
  376. double di = (double)i;
  377. width = (((BLASLONG)(sqrt(di * di + dnum) - di) + mask) & ~mask);
  378. if ((width > n - i) || (width < mask)) width = n - i;
  379. } else {
  380. width = n - i;
  381. }
  382. range[num_cpu + 1] = range[num_cpu] + width;
  383. queue[num_cpu].mode = mode;
  384. queue[num_cpu].routine = inner_thread;
  385. queue[num_cpu].args = &newarg;
  386. queue[num_cpu].range_m = NULL;
  387. queue[num_cpu].range_n = range;
  388. queue[num_cpu].sa = NULL;
  389. queue[num_cpu].sb = NULL;
  390. queue[num_cpu].next = &queue[num_cpu + 1];
  391. num_cpu ++;
  392. i += width;
  393. }
  394. #endif
  395. newarg.nthreads = num_cpu;
  396. if (num_cpu) {
  397. for (j = 0; j < num_cpu; j++) {
  398. for (i = 0; i < num_cpu; i++) {
  399. for (k = 0; k < DIVIDE_RATE; k++) {
  400. job[j].working[i][CACHE_LINE_SIZE * k] = 0;
  401. }
  402. }
  403. }
  404. queue[0].sa = sa;
  405. queue[0].sb = sb;
  406. queue[num_cpu - 1].next = NULL;
  407. exec_blas(num_cpu, queue);
  408. }
  409. #ifdef USE_ALLOC_HEAP
  410. free(job);
  411. #endif
  412. return 0;
  413. }
  414. #endif
  415. blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG myid) {
  416. BLASLONG n, bk, i, blocking, lda;
  417. BLASLONG info;
  418. int mode;
  419. blas_arg_t newarg;
  420. FLOAT *a;
  421. FLOAT alpha[2] = { -ONE, ZERO};
  422. #ifndef COMPLEX
  423. #ifdef XDOUBLE
  424. mode = BLAS_XDOUBLE | BLAS_REAL;
  425. #elif defined(DOUBLE)
  426. mode = BLAS_DOUBLE | BLAS_REAL;
  427. #else
  428. mode = BLAS_SINGLE | BLAS_REAL;
  429. #endif
  430. #else
  431. #ifdef XDOUBLE
  432. mode = BLAS_XDOUBLE | BLAS_COMPLEX;
  433. #elif defined(DOUBLE)
  434. mode = BLAS_DOUBLE | BLAS_COMPLEX;
  435. #else
  436. mode = BLAS_SINGLE | BLAS_COMPLEX;
  437. #endif
  438. #endif
  439. if (args -> nthreads == 1) {
  440. #ifndef LOWER
  441. info = POTRF_U_SINGLE(args, NULL, NULL, sa, sb, 0);
  442. #else
  443. info = POTRF_L_SINGLE(args, NULL, NULL, sa, sb, 0);
  444. #endif
  445. return info;
  446. }
  447. n = args -> n;
  448. a = (FLOAT *)args -> a;
  449. lda = args -> lda;
  450. if (range_n) n = range_n[1] - range_n[0];
  451. if (n <= GEMM_UNROLL_N * 2) {
  452. #ifndef LOWER
  453. info = POTRF_U_SINGLE(args, NULL, range_n, sa, sb, 0);
  454. #else
  455. info = POTRF_L_SINGLE(args, NULL, range_n, sa, sb, 0);
  456. #endif
  457. return info;
  458. }
  459. newarg.lda = lda;
  460. newarg.ldb = lda;
  461. newarg.ldc = lda;
  462. newarg.alpha = alpha;
  463. newarg.beta = NULL;
  464. newarg.nthreads = args -> nthreads;
  465. blocking = (n / 2 + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
  466. if (blocking > GEMM_Q) blocking = GEMM_Q;
  467. for (i = 0; i < n; i += blocking) {
  468. bk = n - i;
  469. if (bk > blocking) bk = blocking;
  470. newarg.m = bk;
  471. newarg.n = bk;
  472. newarg.a = a + (i + i * lda) * COMPSIZE;
  473. info = CNAME(&newarg, NULL, NULL, sa, sb, 0);
  474. if (info) return info + i;
  475. if (n - i - bk > 0) {
  476. #ifndef USE_SIMPLE_THREADED_LEVEL3
  477. newarg.m = n - i - bk;
  478. newarg.k = bk;
  479. #ifndef LOWER
  480. newarg.b = a + ( i + (i + bk) * lda) * COMPSIZE;
  481. #else
  482. newarg.b = a + ((i + bk) + i * lda) * COMPSIZE;
  483. #endif
  484. newarg.c = a + ((i + bk) + (i + bk) * lda) * COMPSIZE;
  485. thread_driver(&newarg, sa, sb);
  486. #else
  487. #ifndef LOWER
  488. newarg.m = bk;
  489. newarg.n = n - i - bk;
  490. newarg.a = a + (i + i * lda) * COMPSIZE;
  491. newarg.b = a + (i + (i + bk) * lda) * COMPSIZE;
  492. gemm_thread_n(mode | BLAS_TRANSA_T,
  493. &newarg, NULL, NULL, (void *)TRSM_LCUN, sa, sb, args -> nthreads);
  494. newarg.n = n - i - bk;
  495. newarg.k = bk;
  496. newarg.a = a + ( i + (i + bk) * lda) * COMPSIZE;
  497. newarg.c = a + ((i + bk) + (i + bk) * lda) * COMPSIZE;
  498. #if 0
  499. HERK_THREAD_UC(&newarg, NULL, NULL, sa, sb, 0);
  500. #else
  501. syrk_thread(mode | BLAS_TRANSA_N | BLAS_TRANSB_T,
  502. &newarg, NULL, NULL, (void *)HERK_UC, sa, sb, args -> nthreads);
  503. #endif
  504. #else
  505. newarg.m = n - i - bk;
  506. newarg.n = bk;
  507. newarg.a = a + (i + i * lda) * COMPSIZE;
  508. newarg.b = a + (i + bk + i * lda) * COMPSIZE;
  509. gemm_thread_m(mode | BLAS_RSIDE | BLAS_TRANSA_T | BLAS_UPLO,
  510. &newarg, NULL, NULL, (void *)TRSM_RCLN, sa, sb, args -> nthreads);
  511. newarg.n = n - i - bk;
  512. newarg.k = bk;
  513. newarg.a = a + (i + bk + i * lda) * COMPSIZE;
  514. newarg.c = a + (i + bk + (i + bk) * lda) * COMPSIZE;
  515. #if 0
  516. HERK_THREAD_LN(&newarg, NULL, NULL, sa, sb, 0);
  517. #else
  518. syrk_thread(mode | BLAS_TRANSA_N | BLAS_TRANSB_T | BLAS_UPLO,
  519. &newarg, NULL, NULL, (void *)HERK_LN, sa, sb, args -> nthreads);
  520. #endif
  521. #endif
  522. #endif
  523. }
  524. }
  525. return 0;
  526. }