Kernel file not opening in XCode: C++ openCL code

343 Views Asked by At

I'm trying to run a sobel filter example from the Mali OpenCL SDK, but I'm running it on XCode.

My program builds, but I'm getting the following error, indicating that my kernel file isn't opening. I'm new to C++, openCL and XCode, so I'm not entirely sure what's going wrong. My kernel file is saved in the same place as the .cpp file in XCode.

Here's the error:

ifstream kernelFile(filename.c_str(), ios::in)

The code fails when the createProgram() function is called. This is where it's called in sobel.cpp:

if (!createProgram(context, device, "sobel.cl", &program))
{
  cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
  cerr << "Failed to create OpenCL program." << __FILE__ << ":"<< __LINE__ << endl;
  return 1;
}

Here's the code for the createProgram() function in common.h (found in the SDK):

 bool createProgram(cl_context context, cl_device_id device, string filename, cl_program* program)
{
    cl_int errorNumber = 0;
    ifstream kernelFile(filename.c_str(), ios::in);

    if(!kernelFile.is_open())
    {
        cerr << "Unable to open " << filename << ". " << __FILE__ << ":"<< __LINE__ << endl;
        return false;
    }

    /*
     * Read the kernel file into an output stream.
     * Convert this into a char array for passing to OpenCL.
     */
    ostringstream outputStringStream;
    outputStringStream << kernelFile.rdbuf();
    string srcStdStr = outputStringStream.str();
    const char* charSource = srcStdStr.c_str();

    *program = clCreateProgramWithSource(context, 1, &charSource, NULL, &errorNumber);
    if (!checkSuccess(errorNumber) || program == NULL)
    {
        cerr << "Failed to create OpenCL program. " << __FILE__ << ":"<< __LINE__ << endl;
        return false;
    }
0

There are 0 best solutions below