SVD of a real matrix in CUDA

The calculation of the Singular Value Decomposition (SVD) of a matrix is at the basis of many computations and approaches in applied science. One example is the regularized solution of linear systems of equations. Another is Principal Component Analysis. Many times, the applications requiring the SVD calculation deal with large matrices and/or request the SVD computation in an iterative process. Fortunately, the SVD can be quickly computed in CUDA using the routines provided in the cuSOLVE...
More

Singular values calculation only of a real matrix with CUDA

Besides the full SVD of a matrix, see SVD of a real matrix, by cusolverDnSgesvd, it is possible also to calculate only the singular values of a matrix. On our GitHub website, we report a sample code with two calls to cusolverDnSgesvd, one performing the singular values calculation only cusolverDnSgesvd(solver_handle, 'N', 'N', M, N, d_A, M, d_S, NULL, M, NULL, N, work, work_size, NULL, devInfo) and one performing the full SVD calculation cusolverDnSgesvd(solver_handle, 'A', 'A', M, N, d_...
More

Sparse 3D Matrices in Matlab

As known, Matlab does not directly deal with 3D matrices. A workaround is using cell arrays of sparse matrices. Suppose that you want to create a sparse matrix containing only the elements (1, 1, 1) and (1, 3, 50) and suppose that A(1, 1, 1) = 1 and A(1, 3, 10) = 54. You can do the following: mySp{1}  = sparse(3, 3); mySp{10} = sparse(3, 3);   mySp{1}(1, 1) = 3; mySp{10}(1, 3) = 54; In this way, >> mySp   mySp = [3x3 double]    []    []    []    []    []...
More

Sparse matrix-matrix multiplication in CUDA using cuSPARSE

We are providing a fully worked code implementing matrix-matrix sparse multiplication using CSR format. To avoid any ambiguity on sparse matrix format, the code starts from dense matrices and uses cusparse<t>dense2csr to convert the matrix format from dense to CSR. The two matrices involved in the code are A and B. Matrix B is a permutation matrix. The code, available on our GitHub website, calculates C = B * A.
More

Sparse matrix-vector multiplication in CUDA

We want to highlight that cuSPARSE (since some time now) makes routines for the multiplication between sparse matrices or between a sparse matrix and a dense vector available. For the csr format, the relevant routine for the multiplication between a sparse matrix and a dense vector is cusparse<t>csrmv. On our GitHub website, a fully worked example showing its use is shown.
More

Find the minima of the columns of a matrix along with their corresponding row indices with CUDA Thrust

Suppose to have a matrix and that you want to find the minima (or, of course, the maxima) of the columns of that matrix along with their corresponding row indices. For example, if you have the following matrix: [ 0 1 12 18 20 3 10 8 ] [ 5 15 1 11 12 17 12 10 ] [ 18 20 15 20 6 8 18 13 ] [ 18 20 3 18 19 6 19 8 ] [ 6 10 8 16 14 11 12 1 ] [ 12 9 12 17 10 16 1 4 ] you want the following output: Min position = 0; Min value = 0 Min position = 0; Min value = 1 Min position = 1; Min value = 1 Min positio...
More

Find the minima of the rows of a matrix along with their corresponding column indices with CUDA Thrust

Suppose to have a matrix and that you want to find the minima (or, of course, the maxima) of the rows of that matrix along with their corresponding column indices. For example, if you have the following matrix: [ 0 1 12 18 20 3 10 8 ] [ 5 15 1 11 12 17 12 10 ] [ 18 20 15 20 6 8 18 13 ] [ 18 20 3 18 19 6 19 8 ] [ 6 10 8 16 14 11 12 1 ] [ 12 9 12 17 10 16 1 4 ] you want the following output: Min position = 0; Min value = 0 Min position = 2; Min value = 1 Min position = 4; Min value = 6 Min positio...
More

Tricks and Tips: Submatrix multiplication in CUDA using cuBLAS

We are here providing a full example on how using cublas <t>gemm to perform multiplications between submatrices of full matrices A and B and how assigning the result to a submatrix of a full matrix C. The code makes use of pointer arithmetics to access submatrices; the concept of the leading dimension and of submatrix dimensions.   The code available on our GitHub page considers three matrices: A - 10 x 9; B - 15 x 13; C - 10 x 12.   Matrix C is initialized to all 10s....
More

Tricks and Tips: Row-wise/Column-wise operations on matrices with CUDA

Many times it is necessary to apply the same operation on all the rows or columns of a matrix with CUDA. For example, add the same row vector to all the rows of a matrix or add the same column vector to all the columns of a matrix. This is an operation that can be easily done using CUDA Thrust. On our GitHub page a fully worked example is reported.
More