2016-06-13 51 views
0

我想用culasasSgetrsBatched函數解決CuBLAS的線性方程。 這裏是我的程序:cublasSgetrs內核中的內存錯誤

__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 

我不明白如何使一個簡單的線性方程此功能工作。

有人可以幫助我嗎?

+0

您可以重新格式化您的代碼,以便我們可以閱讀嗎? – kangshiyin

回答

1

您可能有幾個問題。

  1. the doc of cublasSgetrsBatched,你d_Ad_B的類型應該是const float* []float*[],但是你用float*

  2. 條件ldb>=max(1,n)對#VERSION2失敗。

  3. devIpiv應該是一個數組而不是標量。

  4. d_A中的矩陣應該是LU的因式分解,但是您給出了任意一個。您應該在此函數之前調用cublasSgetrfBatched來執行LU因式分解。這裏是an example code (with performance issue but working)來解決AX=I,你可以作爲參考來解決AX=B。您可以閱讀this以瞭解爲什麼需要LU因子分解。

  5. 與示例代碼相同的性能問題。