1 /*********************************************************************/
2 /* Copyright 2009, 2010 The University of Texas at Austin. */
3 /* All rights reserved. */
5 /* Redistribution and use in source and binary forms, with or */
6 /* without modification, are permitted provided that the following */
7 /* conditions are met: */
9 /* 1. Redistributions of source code must retain the above */
10 /* copyright notice, this list of conditions and the following */
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. */
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. */
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 /*********************************************************************/
42 #ifdef FUNCTION_PROFILE
43 #include "functable.h"
49 #define ERROR_NAME "QTRSM "
51 #define ERROR_NAME "DTRSM "
53 #define ERROR_NAME "STRSM "
57 #define ERROR_NAME "XTRSM "
59 #define ERROR_NAME "ZTRSM "
61 #define ERROR_NAME "CTRSM "
67 #define ERROR_NAME "QTRMM "
69 #define ERROR_NAME "DTRMM "
71 #define ERROR_NAME "STRMM "
75 #define ERROR_NAME "XTRMM "
77 #define ERROR_NAME "ZTRMM "
79 #define ERROR_NAME "CTRMM "
85 #define SMP_FACTOR 256
87 #define SMP_FACTOR 128
90 static int (*trsm[])(blas_arg_t *, BLASLONG *, BLASLONG *, FLOAT *, FLOAT *, BLASLONG) = {
92 TRSM_LNUU, TRSM_LNUN, TRSM_LNLU, TRSM_LNLN,
93 TRSM_LTUU, TRSM_LTUN, TRSM_LTLU, TRSM_LTLN,
94 TRSM_LRUU, TRSM_LRUN, TRSM_LRLU, TRSM_LRLN,
95 TRSM_LCUU, TRSM_LCUN, TRSM_LCLU, TRSM_LCLN,
96 TRSM_RNUU, TRSM_RNUN, TRSM_RNLU, TRSM_RNLN,
97 TRSM_RTUU, TRSM_RTUN, TRSM_RTLU, TRSM_RTLN,
98 TRSM_RRUU, TRSM_RRUN, TRSM_RRLU, TRSM_RRLN,
99 TRSM_RCUU, TRSM_RCUN, TRSM_RCLU, TRSM_RCLN,
101 TRMM_LNUU, TRMM_LNUN, TRMM_LNLU, TRMM_LNLN,
102 TRMM_LTUU, TRMM_LTUN, TRMM_LTLU, TRMM_LTLN,
103 TRMM_LRUU, TRMM_LRUN, TRMM_LRLU, TRMM_LRLN,
104 TRMM_LCUU, TRMM_LCUN, TRMM_LCLU, TRMM_LCLN,
105 TRMM_RNUU, TRMM_RNUN, TRMM_RNLU, TRMM_RNLN,
106 TRMM_RTUU, TRMM_RTUN, TRMM_RTLU, TRMM_RTLN,
107 TRMM_RRUU, TRMM_RRUN, TRMM_RRLU, TRMM_RRLN,
108 TRMM_RCUU, TRMM_RCUN, TRMM_RCLU, TRMM_RCLN,
114 void NAME(char *SIDE, char *UPLO, char *TRANS, char *DIAG,
115 blasint *M, blasint *N, FLOAT *alpha,
116 FLOAT *a, blasint *ldA, FLOAT *b, blasint *ldB){
118 char side_arg = *SIDE;
119 char uplo_arg = *UPLO;
120 char trans_arg = *TRANS;
121 char diag_arg = *DIAG;
131 int mode = BLAS_XDOUBLE | BLAS_REAL;
132 #elif defined(DOUBLE)
133 int mode = BLAS_DOUBLE | BLAS_REAL;
135 int mode = BLAS_SINGLE | BLAS_REAL;
139 int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
140 #elif defined(DOUBLE)
141 int mode = BLAS_DOUBLE | BLAS_COMPLEX;
143 int mode = BLAS_SINGLE | BLAS_COMPLEX;
166 args.beta = (void *)alpha;
178 if (side_arg == 'L') side = 0;
179 if (side_arg == 'R') side = 1;
181 if (trans_arg == 'N') trans = 0;
182 if (trans_arg == 'T') trans = 1;
183 if (trans_arg == 'R') trans = 2;
184 if (trans_arg == 'C') trans = 3;
186 if (diag_arg == 'U') unit = 0;
187 if (diag_arg == 'N') unit = 1;
189 if (uplo_arg == 'U') uplo = 0;
190 if (uplo_arg == 'L') uplo = 1;
193 if (side & 1) nrowa = args.n;
197 if (args.ldb < MAX(1,args.m)) info = 11;
198 if (args.lda < MAX(1,nrowa)) info = 9;
199 if (args.n < 0) info = 6;
200 if (args.m < 0) info = 5;
201 if (unit < 0) info = 4;
202 if (trans < 0) info = 3;
203 if (uplo < 0) info = 2;
204 if (side < 0) info = 1;
207 BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME)-1);
213 void CNAME(enum CBLAS_ORDER order,
214 enum CBLAS_SIDE Side, enum CBLAS_UPLO Uplo,
215 enum CBLAS_TRANSPOSE Trans, enum CBLAS_DIAG Diag,
216 blasint m, blasint n,
219 FLOAT *a, blasint lda,
220 FLOAT *b, blasint ldb) {
223 void *va, blasint lda,
224 void *vb, blasint ldb) {
225 FLOAT *alpha = (FLOAT*) valpha;
226 FLOAT *a = (FLOAT*) va;
227 FLOAT *b = (FLOAT*) vb;
231 int side, uplo, trans, unit;
240 int mode = BLAS_XDOUBLE | BLAS_REAL;
241 #elif defined(DOUBLE)
242 int mode = BLAS_DOUBLE | BLAS_REAL;
244 int mode = BLAS_SINGLE | BLAS_REAL;
248 int mode = BLAS_XDOUBLE | BLAS_COMPLEX;
249 #elif defined(DOUBLE)
250 int mode = BLAS_DOUBLE | BLAS_COMPLEX;
252 int mode = BLAS_SINGLE | BLAS_COMPLEX;
266 args.beta = (void *)α
268 args.beta = (void *)alpha;
277 if (order == CblasColMajor) {
281 if (Side == CblasLeft) side = 0;
282 if (Side == CblasRight) side = 1;
284 if (Uplo == CblasUpper) uplo = 0;
285 if (Uplo == CblasLower) uplo = 1;
287 if (Trans == CblasNoTrans) trans = 0;
288 if (Trans == CblasTrans) trans = 1;
290 if (Trans == CblasConjNoTrans) trans = 0;
291 if (Trans == CblasConjTrans) trans = 1;
293 if (Trans == CblasConjNoTrans) trans = 2;
294 if (Trans == CblasConjTrans) trans = 3;
297 if (Diag == CblasUnit) unit = 0;
298 if (Diag == CblasNonUnit) unit = 1;
303 if (side & 1) nrowa = args.n;
305 if (args.ldb < MAX(1,args.m)) info = 11;
306 if (args.lda < MAX(1,nrowa)) info = 9;
307 if (args.n < 0) info = 6;
308 if (args.m < 0) info = 5;
309 if (unit < 0) info = 4;
310 if (trans < 0) info = 3;
311 if (uplo < 0) info = 2;
312 if (side < 0) info = 1;
315 if (order == CblasRowMajor) {
319 if (Side == CblasLeft) side = 1;
320 if (Side == CblasRight) side = 0;
322 if (Uplo == CblasUpper) uplo = 1;
323 if (Uplo == CblasLower) uplo = 0;
325 if (Trans == CblasNoTrans) trans = 0;
326 if (Trans == CblasTrans) trans = 1;
328 if (Trans == CblasConjNoTrans) trans = 0;
329 if (Trans == CblasConjTrans) trans = 1;
331 if (Trans == CblasConjNoTrans) trans = 2;
332 if (Trans == CblasConjTrans) trans = 3;
335 if (Diag == CblasUnit) unit = 0;
336 if (Diag == CblasNonUnit) unit = 1;
341 if (side & 1) nrowa = args.n;
343 if (args.ldb < MAX(1,args.m)) info = 11;
344 if (args.lda < MAX(1,nrowa)) info = 9;
345 if (args.n < 0) info = 6;
346 if (args.m < 0) info = 5;
347 if (unit < 0) info = 4;
348 if (trans < 0) info = 3;
349 if (uplo < 0) info = 2;
350 if (side < 0) info = 1;
354 BLASFUNC(xerbla)(ERROR_NAME, &info, sizeof(ERROR_NAME));
360 if ((args.m == 0) || (args.n == 0)) return;
364 FUNCTION_PROFILE_START();
366 buffer = (FLOAT *)blas_memory_alloc(0);
368 sa = (FLOAT *)((BLASLONG)buffer + GEMM_OFFSET_A);
369 sb = (FLOAT *)(((BLASLONG)sa + ((GEMM_P * GEMM_Q * COMPSIZE * SIZE + GEMM_ALIGN) & ~GEMM_ALIGN)) + GEMM_OFFSET_B);
372 mode |= (trans << BLAS_TRANSA_SHIFT);
373 mode |= (side << BLAS_RSIDE_SHIFT);
376 if ( args.m < 2 * GEMM_MULTITHREAD_THRESHOLD )
379 if ( args.n < 2 * GEMM_MULTITHREAD_THRESHOLD )
382 if ( args.m * args.n < SMP_FACTOR * GEMM_MULTITHREAD_THRESHOLD)
385 args.nthreads = num_cpu_avail(3);
388 if (args.nthreads == 1) {
391 (trsm[(side<<4) | (trans<<2) | (uplo<<1) | unit])(&args, NULL, NULL, sa, sb, 0);
396 gemm_thread_n(mode, &args, NULL, NULL, trsm[(side<<4) | (trans<<2) | (uplo<<1) | unit], sa, sb, args.nthreads);
398 gemm_thread_m(mode, &args, NULL, NULL, trsm[(side<<4) | (trans<<2) | (uplo<<1) | unit], sa, sb, args.nthreads);
403 blas_memory_free(buffer);
405 FUNCTION_PROFILE_END(COMPSIZE * COMPSIZE,
406 (!side) ? args.m * (args.m + args.n) : args.n * (args.m + args.n),
407 (!side) ? args.m * args.m * args.n : args.m * args.n * args.n);