pyopencl示例设备错误

时间:2014-10-16 02:12:50

标签: python pyopencl


运行program..error时

Choose platform:
[0] <pyopencl.Platform 'Experimental OpenCL 2.0 CPU Only Platform' at 0x3c14d8>
[1] <pyopencl.Platform 'Intel(R) OpenCL' at 0x3faa30>
Choice [0]:1

设置环境变量

PYOPENCL_CTX='1' to avoid being asked again.
Traceback (most recent call last):
File "C:/Python34/gpu1.py", line 10, in <module>
ctx = cl.create_some_context()
File "C:\Python34\lib\site-packages\pyopencl\__init__.py", line 891, in create_some_context
return Context(devices)
pyopencl.RuntimeError: Context failed: device not available

1 个答案:

答案 0 :(得分:3)

您的某个平台/设备很可能会创建上下文。

我建议您明确指定上下文,而不是ctx = cl.create_some_context(),而是选择要使用的平台和设备。像这样:

platform = cl.get_platforms()[0]    # Select the first platform [0]
device = platform.get_devices()[0]  # Select the first device on this platform [0]
context = cl.Context([device])      # Create a context with your device

如果第一个设备/平台[0]无效 - 请尝试第二个[1]。尝试所有设备/平台组合,直到其中一个工作。

如果您想查看自己拥有的平台/设备,请运行this script