Results 1 to 3 of 3

Thread: OpenCL Kernel code issue

  1. #1

    OpenCL Kernel code issue

    Hi everyone.
    I am pretty new to OpenCL. I am having some problems with the clBuildProgram function. In my case, the program is not getting built and the error code is giving the error CL_BUILD_PROGRAM_FAILURE.

    I am trying to parallelise the following code snippet:

    for (k = kernel.width-1 ; k >= 0 ; k--)
    sum += *ppp++ * kernel.data[k];

    This is the kernel code that I have written for parallelizing the same:

    __kernel void convolveImageHoriz(__global float *ppp, __global float *kernel, float sum, int width)
    {
    int k = get_global_id(0);

    if (k >= 0 && k < width)
    {
    sum = ppp[width-k-1] * kernel[k];
    }
    }

    I know for a fact that there is an issue with my Kernel code because when I load some other working kernel, then the program builds successfully.

    I am under a deadline so I would request someone to respond quickly.

  2. #2
    mohitu
    1) Try to print the buld log to see the build error:
    Code :
    #include <cstdio>
    #include <vector>
     
    //....
     
    size_t n = 0;
    cl_int ret = clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, n, NULL, &n);
    if (n > 1) {
    	std::vector<char> buildLog;
    	buildLog.resize(n);
    	ret = clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, n, &buildLog[0], &n);
    	fprintf(stderr, "\nOpenCL Build log: %s\n", &buildLog[0]);
    }
    I have result of compilation of your kernel:

    OpenCL Build log: <kernel>:1:71: error: expected ')'
    __kernel void convolveImageHoriz(__global float *ppp, __global float *kernel, float sum, int width)
    ^
    <kernel>:1:33: note: to match this '('
    __kernel void convolveImageHoriz(__global float *ppp, __global float *kernel, float sum, int width)
    ^
    <kernel>:1:71: error: parameter name omitted
    __kernel void convolveImageHoriz(__global float *ppp, __global float *kernel, float sum, int width)
    ^
    <kernel>:5:19: error: use of undeclared identifier 'width'
    if (k >= 0 && k < width)
    ^
    <kernel>:7:1: error: use of undeclared identifier 'sum'
    sum = ppp[width-k-1] * kernel[k];
    ^
    <kernel>:7:11: error: use of undeclared identifier 'width'
    sum = ppp[width-k-1] * kernel[k];
    ^
    <kernel>:7:24: error: expected expression
    sum = ppp[width-k-1] * kernel[k];

    You cannot use keyword "kernel" in your OpenCL code.Try to use the fixed code:

    Code :
    __kernel void convolveImageHoriz(__global float *ppp, __global float *Kernel, float sum, int width)
    {
    int k = get_global_id(0);
     
    if (k >= 0 && k < width)
    {
    sum = ppp[width-k-1] * Kernel[k];
    }
    }

  3. #3

    Solved!!

    Hi.
    Thanks for your reply.

    I replaced "kernel" with "Kernel" and got the code to work properly.
    Thanks for your help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean