Solvers for triangular matrix

Open discussion for MAGMA

Re: Solvers for triangular matrix

Postby Stan Tomov » Tue Nov 22, 2011 1:31 pm

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: 253
Joined: Fri Aug 21, 2009 10:39 pm

Re: Solvers for triangular matrix

Postby Stan Tomov » Wed Nov 23, 2011 1:02 am

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: 253
Joined: Fri Aug 21, 2009 10:39 pm


Return to User discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest