Veridian - 1 year ago 100

C++ Question

I have a matrix in C00 format, which I convert to CSR format via the following code:

`status = cusparseXcoo2csr(handle, cooRowIndex, nnz, n,`

csrRowPtr, CUSPARSE_INDEX_BASE_ZERO);

I then want to convert the matrix from CSR format to HYB format, but I am not sure how much memory I need to allocate for the matrix in HYB format. I've looked online and can't find any resources on this. How much memory should be allocated?

Here is what I plan to use for converting from csr to hyb format:

`cusparseScsr2hyb(handle_array[i], m, n,`

descr,

cooVal,

csrRowPtr,

cooColIndex,

hybA,

CUSPARSE_HYB_PARTITION_AUTO);

Here is my code for allocating memory, but I'm not sure what to add to allocate memory for hybA.

`cudaStat1 = cudaMalloc((void**)&cooRowIndex, nnz*sizeof(cooRowIndex[0])); // Row indices for A`

cudaStat2 = cudaMalloc((void**)&cooColIndex, nnz*sizeof(cooColIndex[0])); // Column indices for A

cudaStat3 = cudaMalloc((void**)&cooVal, nnz*sizeof(cooVal[0])); // Data values for A

cudaStat4 = cudaMalloc((void**)&csrRowPtr, (n + 1)*sizeof(csrRowPtr[0]));

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Thanks to @RobertCrovella for his comment.

Here is how a hybrid matrix is used:

First Create the hybrid matrix object:

```
cusparseHybMat_t hybA;
cusparseCreateHybMat(&hybA);
```

Then convert your coo matrix to csr format:

```
status = cusparseXcoo2csr(handle, cooRowIndex, nnz, m,
csrRowPtr, CUSPARSE_INDEX_BASE_ZERO);
```

Then convert your csr matrix to hyb format:

```
cusparseScsr2hyb(handle, m, n, descr, cooVal,
csrRowPtr, cooColIndex, hybA_array[i],
0, CUSPARSE_HYB_PARTITION_AUTO);
```

Then perform the sparse matrix * dense vector operation:

```
status = cusparseShybmv(handle,CUSPARSE_OPERATION_NON_TRANSPOSE, &alpha,
descr, hybA, &xVal[0], &beta, &y[0]);
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**