2016-02-24 167 views
0

嗨,我想修改蒸汽代碼從CPU到GPU版本。理解整個代碼並不是必須的。所以,如果有人感興趣,我會提供片段,一切(源代碼和說明)可以在這裏找到: http://www.dgp.toronto.edu/people/stam/reality/Research/pub.html =>「遊戲的實時流體動力學」。CUDA - 內核調用編譯錯誤

這可能是很容易的任務。但我很久沒有使用過C++,只是在研究CUDA,所以對我來說很難。嘗試很長時間,但沒有影響。

CPU版本(工程):

#define IX(i,j) ((i)+(N+2)*(j)) 

... 

void lin_solve(int N, int b, float * x, float * x0, float a, float c) 
{ 

    for (int k = 0; k<20; k++) 
    { 
     for (int i = 1; i <= N; i++) 
     { 
      for (int j = 1; j <= N; j++) 
      { 
      x[IX(i, j)] = (x0[IX(i, j)] + a*(x[IX(i - 1, j)] + x[IX(i + 1, j)] + x[IX(i, j - 1)] + x[IX(i, j + 1)]))/c; 
      } 
     } 


      set_bnd(N, b, x); 
    } 
} 

我的GPU版本(不編譯):在

Error 23 error : argument of type "int *" is incompatible with parameter of type "int" 

#define IX(i,j) ((i)+(N+2)*(j)) 

__global__ 
void GPU_lin_solve(int *N, int *b, float * x, float * x0, float *a, float *c) 
{ 
    int i = threadIdx.x * blockIdx.x + threadIdx.x; 
    int j = threadIdx.y * blockIdx.y + threadIdx.y; 

    if (i < N && j < N) 
    x[IX(i, j)] = (x0[IX(i, j)] + a*(x[IX(i - 1, j)] + x[IX(i + 1, j)] + x[IX(i, j - 1)] + x[IX(i, j + 1)]))/c; 
} 

void lin_solve(int N, int b, float * x, float * x0, float a, float c) 
{ 

    for (int k = 0; k<20; k++) 
    { 

     int *d_N, *d_b; 
     float **d_x, **d_x0; 
     float *d_a, *d_c, *d_xx, *d_xx0; 

     *d_xx = **d_x; 
     *d_xx0 = **d_x0; 

     cudaMalloc(&d_N, sizeof(int)); 
     cudaMalloc(&d_b, sizeof(int)); 
     cudaMalloc(&d_xx, sizeof(float)); 
     cudaMalloc(&d_xx0, sizeof(float)); 
     cudaMalloc(&d_a, sizeof(float)); 
     cudaMalloc(&d_c, sizeof(float)); 

     cudaMemcpy(d_N, &N, sizeof(int), cudaMemcpyHostToDevice); 
     cudaMemcpy(d_b, &b, sizeof(int), cudaMemcpyHostToDevice); 
     cudaMemcpy(d_xx, &*x, sizeof(float), cudaMemcpyHostToDevice); 
     cudaMemcpy(d_xx0, &*x0, sizeof(float), cudaMemcpyHostToDevice); 
     cudaMemcpy(d_a, &a, sizeof(float), cudaMemcpyHostToDevice); 
     cudaMemcpy(d_c, &c, sizeof(float), cudaMemcpyHostToDevice); 

     GPU_lin_solve << <1, 1 >> > (d_N, d_b, d_xx, d_xx0, d_a, d_c); 

     // compilator showing problem in the line above 
     // Error 23 error : argument of type "int *" is incompatible with parameter of type "int" 

     cudaMemcpy(&*x, d_xx, sizeof(float), cudaMemcpyDeviceToHost); 


     cudaFree(d_N); 
     cudaFree(d_b); 
     cudaFree(d_xx); 
     cudaFree(d_xx0); 
     cudaFree(d_a); 
     cudaFree(d_c); 


      set_bnd(N, b, x); 
    } 
} 

編譯器報告錯誤內核啓動

GPU_lin_solve << <1, 1 >> > (d_N, d_b, d_xx, d_xx0, d_a, d_c); 

我做錯了什麼?

回答

1
if (i < N && j < N) 
    x[IX(i, j)] = (x0[IX(i, j)] + a*(x[IX(i - 1, j)] + x[IX(i + 1, j)] + x[IX(i, j - 1)] + x[IX(i, j + 1)]))/c; 
} 

N在你的條件和宏是一個指針,你把它看作是一個整數。 嘗試解引用它嗎?

+0

該問題將擴展到作爲指向內核的所有其他標量值 – talonmies