【问题标题】:cublasSgetrsBatched error in kernel内核中的 cublasSgetrsBatched 错误
【发布时间】:2016-06-15 11:48:59
【问题描述】:

我想使用 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

我不明白如何让这个函数在一个简单的线性方程上工作。

有人可以帮我吗?

【问题讨论】:

  • 您能重新格式化您的代码以便我们阅读吗?

标签: kernel cublas


【解决方案1】:

你可能有几个问题。

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

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

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

  4. d_A 中的矩阵应该是 LU 因式,但你可以给任意一个。您应该在此函数之前调用cublasSgetrfBatched 进行 LU 分解。这里是an example code (with performance issue but working)解决AX=I,你可以作为参考解决AX=B。您可以阅读 this 了解为什么需要 LU 分解。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多