我有一些内核在 gpu 上工作,但是我不能假设代码只会在具有兼容 gpu 的计算机上使用。我尝试使用 cpu 设备运行相同的内核,但是当我尝试创建上下文时,我不断收到 OutOfHostMemory 错误。
我曾尝试在运行 gpu 代码但选择 cpu 作为我的设备的同一台计算机上,以及只有板载图形的计算机上出现的唯一设备是 cpu - 两者都给我同样的错误。
我已确认我可以使用该设备 (GetDeviceInfo) 拨打其他电话,并且我得到了我所期望的。
什么会导致此错误发生?文档只说“主机内存不足”,但这对我没有帮助。
编辑:对评论的反馈
我正在使用的代码是:
ErrorCode error;
Platform[] platforms = Cl.GetPlatformIDs(out error);
List<Device> devicesList = platforms.SelectMany(platform => Cl.GetDeviceIDs(platform, DeviceType.Gpu, out error)).ToList();
if (devicesList.Count == 0)
{
// no gpus detected - revert to cpus
devicesList = platforms.SelectMany(platform => Cl.GetDeviceIDs(platform, DeviceType.Cpu, out error)).ToList();
}
// select first device in list
Device device = devicesList[0];
// confirm we can talk to the device
InfoBuffer infoBuffer = Cl.GetDeviceInfo(device, DeviceInfo.Name, out error);
info = infoBuffer.ToString();
string name = infoBuffer.ToString();
// Try to create context
Context context = Cl.CreateContext(null, 1, new[] { this.Device }, this.ContextNotify, IntPtr.Zero, out error);
// this gives error: OutOfHostMemory
之前返回的所有错误代码都是成功的,无论我使用的是gpu还是cpu,我都可以看到设备的名称,但我只能在使用gpu时成功创建上下文。
我认为我还没有达到任何无限循环,而且在这些调用之前我还没有在 opencCl 中做任何其他事情。