内核中的 cublasSgetrsBatched 错误

cublasSgetrsBatched error in kernel

我想使用 cublasSgetrsBatched 函数用 CuBLAS 求解线性方程。 这是我的程序:

__global__ void invokeDeviceCublasSgemm(cublasStatus_t *returnValue,
                                        int n,
                                        const float *d_alpha,
                                        float *d_A,
                                        float *d_B,
                                        const float *d_beta,
                                        float *d_C)
{
    cublasHandle_t cnpHandle;
    cublasStatus_t status = cublasCreate(&cnpHandle);

    if (status != CUBLAS_STATUS_SUCCESS)
    {
        *returnValue = status;
        return;
    }



    int indice = 0;
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<5;j++)
        {
            if(i==j)
            {
                d_A[i*5+j] = 1;
            }else
            {
              d_A[i*5+j] = 0;
            }
            d_A[i*5+j] = indice++ +1;
        }
        d_B[i] = i*i+2;
    }




    //A*At

    float alpha = 1.0;
    float beta  = 0;
    int devIpiv = 5;
    int info;



    cublasSgetrsBatched(cnpHandle,
                CUBLAS_OP_N,
                5,
                1,
                &d_A,
                5*5,
                (&devIpiv),
                &d_B,
                (#VERSION1)5, or (#VERSION2)1,
                &info,
                1);


    printf("info %d ",info);


    cublasDestroy(cnpHandle);

    *returnValue = status;
}

此函数为第一个版本的 cublasSgetrsBatched #VERSION1

生成
  info 0 !!!! device to host memory copy error

我无法复制数据,但没有信息错误。

在版本 2 #VERSION2:

 info -8

我不明白如何让这个函数对一个简单的线性方程起作用。

有人可以帮助我吗?

您可能有几个问题。

  1. 根据the doc of cublasSgetrsBatched,你的d_Ad_B的类型应该是const float* []float*[],但是你使用float*.

  2. #VERSION2 的条件 ldb>=max(1,n) 失败。

  3. devIpiv 应该是数组而不是标量。

  4. d_A 中的矩阵应该是 LU 因式分解的,但你给了一个任意的。您应该调用 cublasSgetrfBatched to do LU factorization before this function. Here is to solve AX=I, you could use as a reference to solve AX=B. You could read this 来了解为什么需要 LU 分解。

  5. 与示例代码相同的性能问题。