OpenCL helloworld

时间:2017-04-20 13:13:59

标签: opencl

我是OpenCl的新手,我正在努力学习它。 我为OpenCL™应用程序安装了英特尔®SDK,现在我正在尝试将它与visual studio 2015一起使用。 当我试图运行一个hello world示例时,它会在以下代码部分的“program.build”-part中返回错误。

有人可以告诉我我错过了什么吗?

谢谢:)

consol返回:

Using platform: Intel<R> OpenCL
Using device: Intel<R> Core<TM> i7-3770 CPU e 3.40 GHz
-44
Error building: 

示例代码:

//get all platforms (drivers)
std::vector<cl::Platform> all_platforms;
cl::Platform::get(&all_platforms);
if (all_platforms.size() == 0) {
    std::cout << " No platforms found. Check OpenCL installation!\n";
    exit(1);
}

cl::Platform default_platform = all_platforms[0];
std::cout << "Using platform: " << default_platform.getInfo<CL_PLATFORM_NAME>() << "\n";

//get default device of the default platform
std::vector<cl::Device> all_devices;
default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
if (all_devices.size() == 0) {
    std::cout << " No devices found. Check OpenCL installation!\n";
    exit(1);
}
cl::Device default_device = all_devices[0];
std::cout << "Using device: " << default_device.getInfo<CL_DEVICE_NAME>() << "\n";


cl::Context context({ default_device });

cl::Program::Sources sources;

// kernel calculates for each element C=A+B
std::string kernel_code =
    "   void kernel simple_add(global const int* A, global const int* B, global int* C){       "
    "       C[get_global_id(0)]=A[get_global_id(0)]+B[get_global_id(0)];                 "
    "   }                                                                               ";
sources.push_back({ kernel_code.c_str(),kernel_code.length() });



cl::Program program(context, sources);
if (**program.build({ default_device }) != CL_SUCCESS**) {
std::cout << program.build({ default_device }) <<"\n";
std::cout << " Error building: " <<    program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(default_device) << "\n";
exit(1);
}

1 个答案:

答案 0 :(得分:0)

错误代码-44表示“程序对象无效”。但是,这还没有定论,暗示了其他一些损坏内存的问题。另请参见this question

两次调用Parse是-尽管不是很好的做法-不是这里的问题,但也许是线程问题?问题当然不在于您提供的代码片段。