Matrix vector multiplication using cuSparse

Hi,

I am trying to perform sparse matrix-vector multiplication using cuSparse, see below code,

for (int k = 0; k < 100; k++)
{
std::cout << "row[" << k << "] = " << lamvm_row_csr_idx[k] << "  val[" << k << "] = " << lamvm_vals[k] << std::endl;
}
cusparseStatus_t status_mv = cusparseScsrmv(handle, CUSPARSE_OPERATION_NON_TRANSPOSE, img_vec_len, img_vec_len, img_vec_len,

				&alpha, descr, thrust::raw_pointer_cast(&lamvm_vals[0]), thrust::raw_pointer_cast(&lamvm_row_csr_idx[0]), thrust::raw_pointer_cast(&lamvm_col_idx[0]),

				thrust::raw_pointer_cast(&sm_vec[0]), &beta, thrust::raw_pointer_cast(&sm_lam_vec[0]));

			}

cusparseStatus_t status_genA = cusparseScsrgeam(handle, img_vec_len, img_vec_len,
				&alpha,
				descr, img_vec_len,
				thrust::raw_pointer_cast(&lamvm_vals[0]), thrust::raw_pointer_cast(&lamvm_row_csr_idx[0]), thrust::raw_pointer_cast(&lamvm_col_idx[0]),
				&gamma,
				descr, img_vec_len,
				thrust::raw_pointer_cast(&d_lapm_vals[0]), thrust::raw_pointer_cast(&d_lapm_row_csr_idx[0]), thrust::raw_pointer_cast(&d_lapm_col_idx[0]),
				descr,
				thrust::raw_pointer_cast(&A_vals[0]), thrust::raw_pointer_cast(&A_row_csr_idx[0]), thrust::raw_pointer_cast(&A_col_idx[0]));

I am using thrust::device_vector for describing the “sparse” matrix and “dense” vector.

Vectors “lamvm_vals”,“lamvm_row_csr_idx”,“lamvm_col_idx” represent: the sparse matrix values, compressed row pointers and column indices respectively. Please note that I am using “thrust::raw_pointer_cast” to extract data pointer from device_vector.

Just before passing the arguments in the “cusparseScsrmv” function I try to print them using a for-loop and I get the correct values.

However, I get a memory access violation exception when I try to execute the “cusparseScsrmv” function. I would really appreciate if anyone can give me some hint as to what might be the cause of this error.

Please note that just below the “cusparseScsrmv” function, I compute matrix addition using “cusparseScsrgeam”, where I again make use of thrust::device_vector and this works fine without any memory access violation.

Best Regards,
Sumit