我是OpenCL的新手,我试图并行边缘检测程序。我试图从边缘检测功能编写内核。 原来的功能:
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;
}
}
当我尝试使用此方法从.cl文件构建程序时(chk是检查是否存在任何失败/错误的函数):
status = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
chk(status, "clBuildProgram");
我收到错误消息,&#34; clBuildProgram失败(-11)&#34;。从我的研究中,我发现通常认为这个错误是由语法错误引起的。但是,经过多次检查后,我看不出内核有什么特别的错误。有人可以帮我弄清楚它有什么问题吗?
答案 0 :(得分:2)
代码中有许多错误:
1)
float* pOut = &out[r*w + c];
这是无效的,应该是:
__global float* pOut = &out[r*w + c];
2)您在内核中使用的F
从未定义过。
3)sqrtf
未在CL中定义,您的意思是sqrt
吗?