0
votes

I'm new to OpenCL and i'm trying to parallelise an edge detection program.I'm trying to write a kernel from the edge detection function. The original function:

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;
        }
    }
}

My OpenCL Kernel:

__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;
   }
}

When I try to build the program from the .cl file using this(chk is a function to check if there are any failures/errors):

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

I get an error saying, "clBuildProgram failed (-11)". From my researches, I've seen that it is commonly tought that this error is caused by a syntax error. However, after checking many times I cannot see anything particularly wrong with my kernel. Can somebody help me figure out what's wrong with it?

1
Use khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/… with CL_PROGRAM_BUILD_LOG to get the compiler log on what went wrong in the compilation. It is probably some silly error. Is F defined in your kernel?DarkZeros

1 Answers

2
votes

There are many errors in the code:

1)

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

This is invalid, it should be:

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

2) You are using F in the kernel which was never defined.

3) sqrtf is not defined in CL, did you mean sqrt instead?