Cusparse状态映射错误,同时使用CUDA常量内存 [英] Cusparse status mapping error while using cuda constant memory

查看:254
本文介绍了Cusparse状态映射错误,同时使用CUDA常量内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cuda cusparse库来处理稀疏矩阵,我需要执行矩阵向量乘法(cusparseDcsrmv函数)。我有一个稀疏矩阵d_A在csr格式,当我调用这个函数与矢量d_x分配在全局设备内存一切正常工作。但是,虽然我想使用一个向量驻留在常量设备内存我有一个错误:CUSPARSE_STATUS_MAPPING_ERROR
文档说,通常的解决方案是解除绑定任何以前绑定的纹理,但它没有什么与我的

I am using cuda cusparse library to deal with sparse matrices and I need to perform matrix vector multiplication (cusparseDcsrmv function). I have a sparse matrix d_A in csr format and when I call this function with vector d_x allocated in global device memory everything works correctly. But while I want to use a vector residing in constant device memory I've got an error: CUSPARSE_STATUS_MAPPING_ERROR The documentation says that the usual solution is to unbind any previously bound textures but it has nothing do to with what I'm doing.

有人知道发生了什么吗?

Does anyone know what's going on?

const int ONES_SIZE = 5400;
__constant__ static double ONES_DEV[ONES_SIZE];

const cusparseDirection_t dirA_row = CUSPARSE_DIRECTION_ROW;
const cusparseOperation_t NON_TRANS = CUSPARSE_OPERATION_NON_TRANSPOSE;

int main(){    
    cudaSetDevice(0);

    int m = ONES_SIZE; int n = 2500;
    double * HOST_ONES, *A, *d_A, *d_result;
    HOST_ONES = (double*) malloc(ONES_SIZE*sizeof(double));
    for (int i=0; i<ONES_SIZE; i++)
        HOST_ONES[i] = 1.0;
    cudaMemcpyToSymbol(ONES_DEV, HOST_ONES, ONES_SIZE*sizeof(double), 0, cudaMemcpyHostToDevice);

    A = (double *) calloc(m*n, sizeof(double));
    // populate matrix A
    for(int i=0;i<1000; i++)
        A[i*2] = 1.5;

    cudaMalloc((void**)&d_A, m*n*sizeof(double));
    cudaMemcpy(d_A, A, m*n*sizeof(double), cudaMemcpyHostToDevice);

    cusparseHandle_t cusparse_handle = 0;
    cusparseMatDescr_t descrA=0;
    int *nnzTotal, *nnzPerRow, *csrRowPtrA, *csrColIndA;
    double* csrValA;
    int lda = m;
    const double positive = 1.0;
    const double zero = 0.0;

    cusparseCreate(&cusparse_handle);
    cusparseCreateMatDescr(&descrA);
    cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL);
    cusparseSetMatIndexBase(descrA, CUSPARSE_INDEX_BASE_ZERO);

    nnzTotal = (int*)malloc(sizeof(int));
    cudaMalloc((void**)&nnzPerRow, m*sizeof(int));
    cusparseDnnz(cusparse_handle, dirA_row, m, n, descrA, d_A, lda, nnzPerRow, nnzTotal);

    cudaMalloc((void**)&csrValA, (*nnzTotal)*sizeof(double));
    cudaMalloc((void**)&csrRowPtrA, (m+1)*sizeof(int));
    cudaMalloc((void**)&csrColIndA, (*nnzTotal)*sizeof(int));
    cudaMalloc((void**)&d_result, n*sizeof(double));

    // MATRIX CONVERSE FROM DENSE TO SPARSE
    cusparseDdense2csr(cusparse_handle, m, n, descrA, d_A, lda, nnzPerRow, csrValA, csrRowPtrA, csrColIndA);

    // MATRIX VECTOR MULTIPLICATION
    cusparseDcsrmv(cusparse_handle, NON_TRANS, m, n, *nnzTotal, &positive, descrA, csrValA, csrRowPtrA, csrColIndA, ONES_DEV, &zero, d_result);


推荐答案

获取代码示例并使用Visual Profiler运行它,在跟踪API调用时,我会得到以下结果:

Taking your code sample and running it with Visual Profiler, while tracking API calls, I get the following:

其中cusparse方法调用cudaBindTexture。常数内存是一种特殊类型的内存,绑定纹理似乎是不可能的,即使没有记录。

Where cusparse method is making a call to cudaBindTexture. Constant memory being a special type of memory, binding a texture to it seems impossible, even though not documented.

这篇关于Cusparse状态映射错误,同时使用CUDA常量内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆