Cuda 库布拉斯逆冲断层

Cuda 库布拉斯逆冲断层,cuda,segmentation-fault,thrust,cublas,Cuda,Segmentation Fault,Thrust,Cublas,我是CUDA编程新手。我正在编写一个示例代码,它将矩阵与向量相乘,然后打印结果。我正在使用Cublas Dgemv API进行乘法运算。使用cuda memcheck运行程序时,我得到以下错误: Error: process didn't terminate successfully ========= The application may have hit an error when dereferencing Unified Memory from the host. Please rer

我是CUDA编程新手。我正在编写一个示例代码,它将矩阵与向量相乘,然后打印结果。我正在使用Cublas Dgemv API进行乘法运算。使用cuda memcheck运行程序时,我得到以下错误:

Error: process didn't terminate successfully
========= The application may have hit an error when dereferencing Unified Memory from the host. Please rerun the application under cuda-gdb or Nsight Eclipse Edition to catch host side errors.
========= Internal error (20)
========= No CUDA-MEMCHECK results found
最小完整代码在这里

#include <thrust/device_vector.h>
#include <cublas_v2.h>
#include <iostream>
int main(void)
{
int rowDimension = 3; // number of rows
int columnDimension = 6; // number of columns

// initialize data
thrust::device_vector<double> weightMatrix;
weightMatrix.resize(rowDimension * columnDimension);

thrust::device_vector<double> inputVector;
inputVector.resize(columnDimension);

thrust::device_vector<double> F;
F.resize(rowDimension);

for (size_t i = 0; i < rowDimension; i++)
    for (size_t j = 0; j < columnDimension; j++)
        weightMatrix[j * rowDimension + i]=i;

for (size_t j = 0; j < columnDimension; j++)
    inputVector[j] = j;

for (size_t i = 0; i < rowDimension; i++)
    F[i]=0;

cublasHandle_t handle;

/* Initialize CUBLAS */
cublasStatus_t status = cublasCreate(&handle);

if (status != CUBLAS_STATUS_SUCCESS)
    std::cerr << "!!!! CUBLAS initialization error\n";

double alpha = 1.0f;

//  cudaDeviceSynchronize();
status = cublasDgemv(handle, CUBLAS_OP_N, rowDimension, columnDimension, &alpha, thrust::raw_pointer_cast(weightMatrix.data()), rowDimension,
        thrust::raw_pointer_cast(inputVector.data()), 1, 0, thrust::raw_pointer_cast(F.data()), 1) ;;
//  cudaDeviceSynchronize();

if (status != CUBLAS_STATUS_SUCCESS)
    std::cerr << "!!!! kernel execution error.\n";

for (size_t j = 0; j < rowDimension; j++)
    std::cout << F[j] << " ";

status = cublasDestroy(handle);
if (status != CUBLAS_STATUS_SUCCESS)
    std::cerr << "!!!! shutdown error (A)\n";

return 0;
}
#包括
#包括
#包括
内部主(空)
{
int rowDimension=3;//行数
int columnDimension=6;//列数
//初始化数据
推力:装置矢量权重矩阵;
权重矩阵。调整大小(行维度*列维度);
推力:设备\矢量输入矢量;
inputVector.resize(columnDimension);
推力:装置_矢量F;
F.调整大小(行尺寸);
对于(大小i=0;i请看一看的文档

签名为:

cublasDgemv(cublasHandle_t handle, 
            cublasOperation_t trans,
            int m,
            int n,
            const double *alpha,
            const double *A, 
            int lda, 
            const double *x, 
            int incx, 
            const double *beta, 
            double *y, 
            int incy)
beta
必须作为指针提供。但是您将
NULL
指针传递给它,而不是指向值的指针
0

因此,以下内容将解决您的问题:

double alpha = 1.0;
double beta = 0;

status = cublasDgemv(handle,
                     CUBLAS_OP_N,
                     rowDimension,
                     columnDimension,
                     &alpha,
                     thrust::raw_pointer_cast(weightMatrix.data()),
                     rowDimension,
                     thrust::raw_pointer_cast(inputVector.data()),
                     1,
                     &beta, // note the change here!
                     thrust::raw_pointer_cast(F.data()),
                     1);

谢谢,你救了我一天。