I am using mex bridge to perform some operations on Sparse matrices from Matlab.
For that I need to convert input matrix into CSR (compressed row storage) format, since Matlab stores the sparse matrices in CSC (compressed column storage).
I was able to get value array and column_indices array. However, I am struggling to get row_pointer array for CSR format.Is there any C library that can help in conversion from CSC to CSR ?
Further, while writing a CUDA kernel, will it be efficient to use CSR format for sparse operations or should I just use following arrays :- row indices, column indices and values?
Which on would give me more control over the data, minimizing the number for-loops in the custom kernel?
I ended up converting CSC format from Matlab to CSR using CUSP library as follows.
After getting the matrix
Afrom matlab and I got itsrow,colandvaluesvectors and I copied them in respectivethrust::host_vectorcreated for each of them.After that I created two
cusp::array1dof typeIndicesandValuesas follows.where
rows,colsandValarethrust::host_vectorthat I got from Matlab.After that I created a
cusp::coo_matrix_viewas given below.where
m,nandNNZaare the parameters that I get frommexfunctions of sparse matrices.I copied this view matrix to
cusp::csr_matrixin device memory with proper dimensions set as given below.After that I just copied the three individual content arrays of this CSR matrix back to the host using
thrust::raw_pointer_castwhere arrays with proper dimension are alreadymxCalloced as given below.Hope this is useful to anyone who is using
CUSPwithMatlab