【问题标题】:getting cl_build_program_failure error获取 cl_build_program_failure 错误
【发布时间】:2015-04-07 20:59:22
【问题描述】:

我目前正在从事一个关于 OpenCL 的项目,在尝试构建该程序时遇到了一些麻烦。所以我有以下代码:

    //Read source file
    std::ifstream sourceFile("calculation_kernel.cl");
    std::string sourceCode(std::istreambuf_iterator<char>(sourceFile), (std::istreambuf_iterator<char>()));
    cl::Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length()+1));

    if (sourceFile.is_open()){
        printf("the file is open\n");
    }else{
        printf("error opening file\n");
    }

    // Make program of the source code in the context
    cl::Program program = cl::Program(context, source);

    // Build program for these specific devices
    program.build(devices);

代码编译得很好,但是当我尝试运行它时会得到一个 clBuildProgram(-11) 错误。我已经验证我的内核文件可以成功打开。 我在这里错过了什么吗?或者有没有办法调试这个错误?

提前致谢!

【问题讨论】:

    标签: c++ opencl


    【解决方案1】:

    错误代码-11对应CL_BUILD_PROGRAM_FAILURE。这表明您的内核代码编译失败,可能是由于语法错误。假设您在 OpenCL C++ 绑定 (#define __CL_ENABLE_EXCEPTIONS) 中启用了异常,您可以使用以下内容检索构建日志:

    try
    {
      program.build(devices);
    }
    catch (cl::Error error)
    {
      if (error.err() == CL_BUILD_PROGRAM_FAILURE)
      {
        // Get the build log for the first device
        std::string log = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]);
        std::cerr << log << std::endl;
      }
      throw(error);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 1970-01-01
      • 2012-03-16
      • 2019-01-28
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      相关资源
      最近更新 更多