5

I am trying to get familiar to the cuSparse library. In my simple code, the function cusparseSnnz returns the status 6 which is CUSPARSE_STATUS_INTERNAL_ERROR. I think the CUDA driver and cuSparse library are correctly installed. I would be really appreciated if someone could help me. Thanks.

cusparseStatus_t status;
cusparseHandle_t handle=0;
cusparseMatDescr_t descr=0;

status = cusparseCreate(&handle);
if (status != CUSPARSE_STATUS_SUCCESS) {
    cout << "CUSPARSE Library initialization failed" << endl;
}
status = cusparseCreateMatDescr(&descr);
if (status != CUSPARSE_STATUS_SUCCESS) {
    cout << "Matrix descriptor initialization failed" << endl;
}
status = cusparseSetMatType(descr, CUSPARSE_MATRIX_TYPE_GENERAL);
if (status != CUSPARSE_STATUS_SUCCESS) {
    cout << "cusparseSetMatType failed" << endl;
}
status = cusparseSetMatIndexBase(descr, CUSPARSE_INDEX_BASE_ZERO);
if (status != CUSPARSE_STATUS_SUCCESS) {
    cout << "cusparseSetMatIndexBase failed" << endl;
}
int nnzPerRow[2];
int nnzTotal;
float tempf[6];
tempf[0] = 1.0;
tempf[1] = 0.0;
tempf[2] = 3.4;
tempf[3] = 0.0;
tempf[4] = 2.2;
tempf[5] = 8.6;
float* d_Temp;
cudaMalloc((void**)&d_Temp, sizeof(float)*6);
cudaMemcpy(d_Temp, tempf, sizeof(float)*6, cudaMemcpyHostToDevice);
status = cusparseSnnz(handle, CUSPARSE_DIRECTION_ROW, 2, 3, descr, d_Temp, 2, nnzPerRow, &nnzTotal);
if (status != CUSPARSE_STATUS_SUCCESS) {
    cout << "nnz calculation failed" << endl;
    cout << "status = " << status << endl;
}
cout << "nnzPerRow[0] = " << nnzPerRow[0] << endl;
cout << "nnzPerRow[1] = " << nnzPerRow[1] << endl;

1 Answer 1

4

I just found what was wrong. nnzPerRow needs to be located in the device.

int nnzPerRow[2]; 

This should be as follows:

int* nnzPerRow=0;
checkCudaErrors(cudaMalloc((void**)&nnzPerRow, sizeof(int)*2));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.