AnsweredAssumed Answered

OPENCL clBuildProgram fails with no return

Question asked by Mauro Manzo on Dec 24, 2014
Latest reply on Dec 25, 2014 by igorpadykov

Hi to all,

 

I have a Udoo Quad board with the i.mx6Quad CPU and the Vivante GC2000 GPU. The OS is UDOObuntu, that essentially is an Ubuntu 12.04 based distro.

In CodeBlocks I'm trying to run a simple "helloWorld" OpenCL program. The program is built and the libraries are linked, but at runtime there is a strange error after calling "clBuildProgram".

 

The kernel computes a simple C=A+B vector sum:

 

__kernel void hello_kernel(__global const float *a,__global const float *b,__global float *result)
{
     int gid = get_global_id(0);
     result[gid] = a[gid] + b[gid];
}

 

The C++ file is very simple. I'll show only the function that should create and build the CL program;

 

cl_program CreateProgram(cl_context context, cl_device_id device, const char* fileName)
{
    cl_int errNum = -1000;
    cl_program program;

    std::ifstream kernelFile(fileName, std::ios::in);
    if (!kernelFile.is_open())
    {
        std::cerr << "Failed to open file for reading: " << fileName << std::endl;
        return NULL;
    }

    std::ostringstream oss;
    oss << kernelFile.rdbuf();

    std::string srcStdStr = oss.str();
    const char *srcStr = srcStdStr.c_str();
    program = clCreateProgramWithSource(context, 1,(const char**)&srcStr,NULL, NULL);

    if (program == NULL)
    {
        std::cerr << "Failed to create CL program from source." << std::endl;
        return NULL;
    }

    ///////////////////// ERROR IS HERE //////////////////////
    try 
    {
      //errNum = clBuildProgram(program, 1, &device, "-cl-std=CL1.1 -w -cl-opt-disable", NULL, NULL);
        errNum = clBuildProgram(program, 0, NULL, "", NULL, NULL);
    } catch(...)
    {
        std::cout<< __LINE__<<", "<<__FILE__<<": errNum="<<errNum<<std::endl;
    }

    std::cout<< __LINE__<<", "<<__FILE__<<": errNum="<<errNum<<std::endl;

    if (errNum != CL_SUCCESS)
    {
        // Determine the reason for the error
        size_t logSize;
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &logSize);

        char* buildLog = new char[logSize];
        clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,sizeof(buildLog), buildLog, NULL);

        std::cerr << "Error in kernel: " << std::endl;
        std::cerr << buildLog;

        clReleaseProgram(program);
        delete[] buildLog;
        return NULL;
    }

    return program;
}

 

 

Both the version in line 29 and the version in line 30 crash. The catch block is never reached, and the program exits immediately.

 

The compiler options are:

-march=native -fexceptions -DLINUX -DUSE_SOC_MX6 -Wall  -fsigned-char  -mfloat-abi=hard -mfpu=neon -DEGL_API_FB -DGPU_TYPE_VIV -DGL_GLEXT_PROTOTYPES -DENABLE_GPU_RENDER_20

 

I'm linking glib2.0, OpenCL, GAL, CLC, dl and pthread. Also the linker has option -mfloat-abi=hard

Outcomes