I am a newbie to the CUDA. When I use cuSPARSE to solve a linear system, I adopt Cholesky factorization.
My program crashes when I use the function cusolverSpScsrcholBufferInfo(...)
after cusolverSpXcsrcholAnalysis(...)
. Visual Studio shows “Access violation reading location”.
I doubt that I input the wrong parameters so I write a simple code with a small 3x3 matrix to test this function, but come with the same error.
My GPU device is GeForce GTX Titan Black, released in 2014.
CUDA version: 10.1
IDE: Visual Studio 2019
If I don’t offer enough information, please let me know.
Here is my code a.cu:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <cusolverSp.h>
#include <cusolverSp_LOWLEVEL_PREVIEW.h> //cusolverSpXcsrcholAnalysis
#include <cusolverRf.h>
#include <stdio.h>
#include "cusolverSp.h"
#include <iostream>
using namespace std;
void cudaSafeCall(cudaError_t err, char* msg) {
if (err != cudaSuccess) {
printf("Error(%s)! number %d, %s\n", msg, err, cudaGetErrorString(err));
exit(1);
}
}
void cusolverCheck(cusolverStatus_t st, const char* msg)
{
//std::cout << st << std::endl;
if (st != CUSOLVER_STATUS_SUCCESS)
{
std::cout << "[cusolver error( " << st << ")]: " << msg;
throw std::exception();
}
}
int main()
{
cusolverSpHandle_t spHandle;
cusolverSpCreate(&spHandle);
cusparseMatDescr_t desc;
cusparseCreateMatDescr(&desc);
csrcholInfo_t m_info = nullptr;
cusolverSpCreateCsrcholInfo(&m_info);
int row = 3, nnz = 3;
int* rowId, * colId;
float* value;
cudaMallocManaged(&rowId, sizeof(int) * (row + 1));
cudaMallocManaged(&colId, sizeof(int) * nnz);
cudaMallocManaged(&value, sizeof(float) * nnz);
// [ 1 0 0 ]
// [ 0 2 0 ]
// [ 0 0 3 ]
for (int i = 0; i < nnz; ++i)value[i] = i + 1;
for (int i = 0; i < row + 1; ++i)rowId[i] = i;
for (int i = 0; i < nnz; ++i)colId[i] = i;
size_t* internalDataInBytes, * workspaceInBytes;
cusolverSpXcsrcholAnalysis(spHandle, row, nnz, desc, rowId, colId, m_info);
cusolverSpScsrcholBufferInfo(spHandle, row, nnz, desc, value, rowId, colId, m_info,
internalDataInBytes, workspaceInBytes);
cudaDeviceSynchronize();
cudaSafeCall(cudaGetLastError(), "cusolverSpScsrcholBufferInfo Error!");
printf("success!!\n");