XCode中未打开内核文件:C ++ openCL代码

时间:2015-06-15 19:39:53

标签: c++ xcode opencl

我试图从Mali OpenCL SDK运行sobel过滤器示例,但我在XCode上运行它。

我的程序构建,但是我收到以下错误,表明我的内核文件没有打开。我是C ++,openCL和XCode的新手,所以我不完全确定会出现什么问题。我的内核文件保存在与XCode中的.cpp文件相同的位置。

这是错误:

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

调用createProgram()函数时代码失败。这就是它在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;
}

这里是common.h中的createProgram()函数的代码(在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 个答案:

没有答案