0

I want to write the input image into the buffer and execute the kernel file in the while loop of the host program (not in the kernel file). I did set OpenCL stuff (context, device, buffer, command queue, etc) out of the while loop, write the image to the buffer I created in the loop, and run the kernel. It works on my desktop, but when i executed it on i.mx6 board, it returns segmentation fault error in second while loop. The code is below.

while (count < 10)
{
    unsigned char* input = (unsigned char*)inImg.data;
    start = clock();

    unsigned char* output = (unsigned char*)malloc(width * height * sizeof(unsigned char));

    size_t localWorkSize[2] = { WGX, WGY };
    size_t globalWorkSize[2] = { RoundUp(WGX, width), RoundUp(WGY, height) };
    cl_mem cl_inImg = clCreateBuffer(context, CL_MEM_READ_ONLY, width * height * sizeof(unsigned char) * inImg.channels(), NULL, &ret);
    /*error check*/


    cl_mem cl_outImg = clCreateBuffer(context, CL_MEM_WRITE_ONLY, width * height * sizeof(unsigned char) * inImg.channels(), NULL, &ret);
    /*error check*/

    int filterSize = 5;
    int paddingSize = (int)(filterSize / 2) * 2;
    int localWidth = WGX + paddingSize;
    int localHeight = WGY + paddingSize;

    size_t localMemSize = (localWidth * localHeight * sizeof(unsigned char) * inImg.channels());

    clEnqueueWriteBuffer(queue, cl_inImg, CL_TRUE, 0, width * height * sizeof(unsigned char) * inImg.channels(), input, 0, NULL, NULL);

    cl_int errNum = 0;
    errNum = clSetKernelArg(kernel, 0, sizeof(cl_mem), &cl_inImg);
    errNum |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &cl_outImg);
    errNum |= clSetKernelArg(kernel, 2, localMemSize, NULL);
    errNum |= clSetKernelArg(kernel, 3, sizeof(int), &filterSize);
    errNum |= clSetKernelArg(kernel, 4, sizeof(int), &localWidth);
    errNum |= clSetKernelArg(kernel, 5, sizeof(int), &localHeight);
    errNum |= clSetKernelArg(kernel, 6, sizeof(int), &width);
    errNum |= clSetKernelArg(kernel, 7, sizeof(int), &height);
    /*error check*/


    errNum = clEnqueueNDRangeKernel(queue, kernel, 2, NULL,
        globalWorkSize, localWorkSize,
        0, NULL, NULL);
    /*error check*/


    clFinish(queue);

    errNum = clEnqueueReadBuffer(queue, cl_outImg,
        CL_TRUE, 0, width * height * sizeof(unsigned char) * inImg.channels(), output, 0, NULL, NULL);
    /*error check*/    
}

I can't find where i did incorrectly, because it works normally on my PC. How should i fix this?

BHYoo
  • 11
  • 3
  • Try valgrind to detect where error is. – Boris Ivanov Aug 06 '18 at 11:30
  • Thank you for your reply. The segfault error occurs at clFinish. If i comment clFinish the same error occred in clEnqueueReadBuffer function. I don't know why the error appears from the second trial of loop. – BHYoo Aug 07 '18 at 00:12

0 Answers0