OpenCL 内核错误 -11
OpenCL Kernel Error -11
我是 OpenCL 的新手,我正在尝试并行化边缘检测 program.I正在尝试从边缘检测功能编写内核。
原函数:
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 是一个检查是否有任何 failures/errors 的函数):
status = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
chk(status, "clBuildProgram");
我收到一条错误消息,说 "clBuildProgram failed (-11)"。根据我的研究,我发现这个错误通常是由语法错误引起的。然而,在检查了很多次之后,我没有发现我的内核有什么特别的问题。有人可以帮我弄清楚它有什么问题吗?
代码中有很多错误:
1)
float* pOut = &out[r*w + c];
这是无效的,应该是:
__global float* pOut = &out[r*w + c];
2) 您正在内核中使用从未定义的 F
。
3) sqrtf
未在 CL 中定义,您的意思是 sqrt
吗?
我是 OpenCL 的新手,我正在尝试并行化边缘检测 program.I正在尝试从边缘检测功能编写内核。 原函数:
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 是一个检查是否有任何 failures/errors 的函数):
status = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
chk(status, "clBuildProgram");
我收到一条错误消息,说 "clBuildProgram failed (-11)"。根据我的研究,我发现这个错误通常是由语法错误引起的。然而,在检查了很多次之后,我没有发现我的内核有什么特别的问题。有人可以帮我弄清楚它有什么问题吗?
代码中有很多错误:
1)
float* pOut = &out[r*w + c];
这是无效的,应该是:
__global float* pOut = &out[r*w + c];
2) 您正在内核中使用从未定义的 F
。
3) sqrtf
未在 CL 中定义,您的意思是 sqrt
吗?