## Solvers for triangular matrix

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)

### Re: Solvers for triangular matrix

This is implemented in CUBLAS. In MAGMA we use TRSM to solve triangular systems. As an example, you can see the code in src/sgetrs_gpu.cpp:
Code: Select all
`...if (notran) {        inc = 1;        /* Solve A * X = B. */        cublasGetMatrix( n, nrhs, sizeof(float), dB, lddb, work, n);        lapackf77_slaswp(&nrhs, work, &n, &i1, &i2, ipiv, &inc);        cublasSetMatrix( n, nrhs, sizeof(float), work, n, dB, lddb);        if ( nrhs == 1) {            cublasStrsv(MagmaLower, MagmaNoTrans, MagmaUnit,    n, dA, ldda, dB, 1 );            cublasStrsv(MagmaUpper, MagmaNoTrans, MagmaNonUnit, n, dA, ldda, dB, 1 );        } else {            cublasStrsm(MagmaLeft, MagmaLower, MagmaNoTrans, MagmaUnit,    n, nrhs, c_one, dA, ldda, dB, lddb );            cublasStrsm(MagmaLeft, MagmaUpper, MagmaNoTrans, MagmaNonUnit, n, nrhs, c_one, dA, ldda, dB, lddb );        }    } else {        inc = -1;        /* Solve A' * X = B. */        if ( nrhs == 1) {            cublasStrsv(MagmaUpper, trans, MagmaNonUnit, n, dA, ldda, dB, 1 );            cublasStrsv(MagmaLower, trans, MagmaUnit,    n, dA, ldda, dB, 1 );        } else {            cublasStrsm(MagmaLeft, MagmaUpper, trans, MagmaNonUnit, n, nrhs, c_one, dA, ldda, dB, lddb );            cublasStrsm(MagmaLeft, MagmaLower, trans, MagmaUnit,    n, nrhs, c_one, dA, ldda, dB, lddb );        }        cublasGetMatrix( n, nrhs, sizeof(float), dB, lddb, work, n );        lapackf77_slaswp(&nrhs, work, &n, &i1, &i2, ipiv, &inc);        cublasSetMatrix( n, nrhs, sizeof(float), work, n, dB, lddb);    }`

Stan
Stan Tomov

Posts: 258
Joined: Fri Aug 21, 2009 10:39 pm

### Re: Solvers for triangular matrix

That's good to hear!
In general, all magma routines are coded in terms of cublas, but if for some routines magmablas is faster, we redefine it for the particular routine at the beginning with a define pragma statement, e.g., for the file mentioned above cublas is faster for one right-hand side and we use it, but for multiple we have redefined the cublas calls to call magmablas with a
Code: Select all
`  #define cublasStrsm magmablas_strsm`

at the beginning of the file.
Stan
Stan Tomov

Posts: 258
Joined: Fri Aug 21, 2009 10:39 pm