我的 OpenCL 代码有问题,它在标记的位置崩溃,但仅适用于我的 nvidia gpu (OpenCL 1.1)(英特尔平台(OpenCL 1.2 和 OpenCL 2.0)表现良好)。
cl::Platform::get(&allPlatforms);
allDevices.resize(allPlatforms.size());
size_t noDevices = 0;
for (size_t i = 0, end = allPlatforms.size(); i < end; ++i)
{
allPlatforms[i].getDevices(CL_DEVICE_TYPE_ALL, &allDevices[i]); //here it crashes
noDevices += allDevices[i].size();
}
cl_int getDevices(
cl_device_type type,
VECTOR_CLASS<Device>* devices) const
{
...
devices->assign(&ids[0], &ids[n]); //here it crashes
return CL_SUCCESS;
}
我不知道它为什么会崩溃以及如何修复它。
编辑:我的调试器说 ids 是一个有效的指针并且 n=1(在崩溃的情况下)
最佳答案
你有最新版本的标题吗?它里面有“isReferenceCountable”函数吗?
早期版本的 header 存在一个问题,即 NVIDIA(错误地)发布了带有 1.1 ICD 的 1.2 cl.h。 C__ header 无法知道这是一个链接错误,因为 cl.h 报告 1.2 版本标志并盲目调用 clRetainDevice,这会导致段错误,因为它未在 ICD 中实现。
header 的更高版本通过对设备版本执行版本检查并避免调用保留/释放来解决此问题。如果您处于这种情况,那么下载更新版本的 header 应该可以解决它: https://www.khronos.org/registry/cl/api/1.2/cl.hpp
如果这不起作用,调试器会在哪里报告崩溃?
关于c++ - OpenCL:cl::getDevices 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31591207/