Help with Matrix descriptors, and CSR to BSR manipulation

Hi everybody,

I’m involved into some sparse manipulation program, and my final goal is to perform the basic cusparsebsrmv() operation. In order to achieve that, I had first to build my matrices, and I firstly decided to do that with CreateCoo() function, but since I’ve faced some problems with this format, I’ve changed my code to build them with cusparseCreateCsr().

Now, I’m in some problems because bsrmv operation needs a BSR converted matrix, and I can’t figure out how to do that conversion. I’ve tried two different approaches, but none of them worked. First of all, I saw that both functions cusparsecsr2bsrNnz() and cusparsecsr2bsr() ask for parameters of type cusparseMatDescr_t. However, my matrix, which I have to manipulate earlier, is built with type cusparseSpMatDescr_t. I tried to cast it to cusparseMatDescr_t, but it didn’t worked; I received CUSPARSE_STATUS_INVALID_VALUE. I’m pretty confident that the matrix is well-formed; I’ll show you an example:

LENGTH = 5
Values ::       [
        0.333,  1.000,  0.500,  0.333,  1.000,  0.333,  0.500, 
]
Columns ::      [
        0,      2,      3,      0,      1,      0,      3, 
]
Row offsets ::  [
        0,      3,      5,      7,      7,      7, 
]
Matrix should be = [
       0.333, 0, 1, 0.5, 0;
       0.333, 1, 0, 0, 0;
       0.333, 0, 0, 0.5, 0;
       0, 0, 0, 0, 0;
       0, 0, 0, 0, 0
]

I thought later about creating new descriptors (but didn’t know exactly why), with this code:

cusparseMatDescr_t A_CSR, A_BSR;

assert(CUSPARSE_STATUS_SUCCESS == cusparseCreateMatDescr(&A_CSR));
assert(CUSPARSE_STATUS_SUCCESS == cusparseCreateMatDescr(&A_BSR));

assert(CUSPARSE_STATUS_SUCCESS == cusparseSetMatType(A_CSR, CUSPARSE_MATRIX_TYPE_GENERAL));
assert(CUSPARSE_STATUS_SUCCESS == cusparseSetMatIndexBase(A_CSR, CUSPARSE_INDEX_BASE_ZERO));
assert(CUSPARSE_STATUS_SUCCESS == cusparseSetMatType(A_BSR, CUSPARSE_MATRIX_TYPE_GENERAL));
assert(CUSPARSE_STATUS_SUCCESS == cusparseSetMatIndexBase(A_BSR, CUSPARSE_INDEX_BASE_ZERO));

cusp_status = cusparseXcsr2bsrNnz(
    handle,
    CUSPARSE_DIRECTION_COLUMN,
    LENGTH,
    LENGTH,
    A_CSR,
    row_int_indexes,
    cols_int_indexes,
    BLOCK_DIM,
    A_BSR,
    bsr_rows,
    nnzTotalDevHostPtr
);

but now I got CUSPARSE_STATUS_EXECUTION_FAILED. Can anybody tell me how could I use the functions to convert the matrix and to perform matrix operations, since I have a matrix built with cusparseCreateCsr(), whose type isn’t compatible with those functions?

Thank you in advance

Hi, you can find attached a minimal code example to convert your matrix from CSR to BSR. You can easily extend it to any matrix.csr2bsr.cu (3.1 KB)