Ошибка сегментации тяги Cublas

Я новичок в программировании на CUDA. Я работал над примером кода, который умножает матрицу на вектор и печатает результаты. Я использую API Cublas Dgemv для выполнения умножения. При запуске программы с помощью 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;
}

Приведенная выше программа вызывает ошибку сегментации в функции cublasDgemv. При запуске cuda-memcheck я получаю сообщение, указанное выше. На Google я не мог найти много помощи.

Может кто-нибудь, пожалуйста, помогите мне решить эту проблему.


person Rudra Murthy    schedule 01.07.2015    source источник


Ответы (1)


Ознакомьтесь с документацией cublasDgemv.

Подпись:

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);
person m.s.    schedule 01.07.2015
comment
Спасибо, вы спасли мой день. - person Rudra Murthy; 01.07.2015