2016-04-25 115 views
0

我是OpenCL的新手,我試圖並行化邊緣檢測程序。我試圖從邊緣檢測函數編寫內核。 原有的功能:OpenCL內核錯誤-11

void edgeDetection(float *out, float *in, int w, int h) { 
    int r,c; 
    for (r = 0; r < h-2; r++) { 
     for (c = 0; c < w-2; c++) { 
      float G; 
      float* pOut = &out[r*w + c]; 
      float Gx = 0.0; 
      float Gy = 0.0; 

      int fr,fc; 
      /* run the 2d-convolution filter */ 
      for (fr = 0; fr < 3; fr++) { 
       for (fc = 0; fc < 3; fc++) { 
        float p = in[(r+fr)*w + (c+fc)]; 
        /* X-directional edges */ 
        Gx += p * F[fr*3 + fc]; 
        /* Y-directional edges */ 
        Gy += p * F[fc*3 + fr]; 
       } 
      } 
      /* all edges, pythagoral sum */ 
      G = sqrtf(Gx*Gx + Gy*Gy); 
      *pOut = G; 
     } 
    } 
} 

我的OpenCL內核:

__kernel 
void edgeDetection(__global float *out, 
__global float *in, int w, int h) 
{ 

    // Get the work-item’s unique ID 
    const int r = get_global_id(0); 
    const int c = get_global_id(1); 
    if(r>=0 && c>=0 && r<h-2 && c<w-2){ 
      float G; 
      float* pOut = &out[r*w + c]; 
      float Gx = 0.0; 
      float Gy = 0.0; 

      int fr,fc; 

      for (fr = 0; fr < 3; fr++) { 
       for (fc = 0; fc < 3; fc++) { 

        float p = in[(r+fr)*w + (c+fc)]; 

        Gx += p * F[fr*3 + fc]; 

        Gy += p * F[fc*3 + fr]; 
       } 
      } 
      G = sqrtf(Gx*Gx + Gy*Gy); 
      *pOut = G; 
    } 
} 

當我嘗試使用這個(CHK是一個函數來檢查,如果有任何故障從.CL文件生成程序/錯誤):

status = clBuildProgram(program, 1, &device, NULL, NULL, NULL); 
chk(status, "clBuildProgram"); 

我收到一個錯誤,說:「clBuildProgram失敗(-11)」。從我的研究中,我發現這種錯誤通常是由語法錯誤引起的。但是,經過多次檢查後,我發現內核看不到任何特別的錯誤。有人能幫我弄清楚它有什麼問題嗎?

+1

使用https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clGetProgramBuildInfo.html和CL_PROGRAM_BUILD_LOG,讓編譯器記錄編譯過程中出錯的地方。這可能是一些愚蠢的錯誤。 F是在你的內核中定義的? – DarkZeros

回答

2

有在代碼中的許多錯誤:

1)

float* pOut = &out[r*w + c]; 

這是無效的,它應該是:

__global float* pOut = &out[r*w + c]; 

2)你在內核中使用F這從未被定義。

3)sqrtf未在CL中定義,您的意思是sqrt而不是?