pyopencl.RuntimeError:clBuildProgram失败:无效的构建选项

时间:2014-03-13 00:06:26

标签: python opencl pyopencl

我是OpenCL的新手,在设置OpenCL程序时遇到一些问题。为了说明我的问题,请查看代码(取自https://github.com/benshope/PyOpenCL-Tutorial):

# Use OpenCL To Add Two Random Arrays (This Way Hides Details)

import pyopencl as cl  # Import the OpenCL GPU computing API
import pyopencl.array as pycl_array  # Import PyOpenCL Array (a Numpy array plus an OpenCL buffer object)
import numpy as np  # Import Numpy number tools

context = cl.create_some_context()  # Initialize the Context
queue = cl.CommandQueue(context)  # Instantiate a Queue

a = pycl_array.to_device(queue, np.random.rand(50000).astype(np.float32))
b = pycl_array.to_device(queue, np.random.rand(50000).astype(np.float32))  
# Create two random pyopencl arrays
c = pycl_array.empty_like(a)  # Create an empty pyopencl destination array

program = cl.Program(context, """
__kernel void sum(__global const float *a, __global const float *b, __global float *c)
{
  int i = get_global_id(0);
  c[i] = a[i] + b[i];
}""").build()  # Create the OpenCL program

program.sum(queue, a.shape, None, a.data, b.data, c.data)  # Enqueue the program for execution and store the result in c

print("a: {}".format(a))
print("b: {}".format(b))
print("c: {}".format(c))  
# Print all three arrays, to show sum() worked

如果我执行脚本,我会收到以下错误:

"C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\python.exe" D:/python/openCL/020_array_sum.py
Traceback (most recent call last):
   File "D:/python/openCL/020_array_sum.py", line 20, in <module>
}""").build() # Create the OpenCL program
   File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 166, in build
options=options, source=self._source)
   File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 206, in _build_and_catch_errors
     raise err
pyopencl.RuntimeError: clBuildProgram failed: invalid build options - 


(options: -I c:\program files\winpython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\cl)
(source saved as c:\appdata\local\temp\tmp0bj_ij.cl)

使用退出代码1完成处理

据我了解,这是由build()函数引起的,但我不明白为什么。在一个论坛中,他们建议仅使用一个"而不是"""来定义内核。这也没有帮助。

我使用WinPython-64bit-2.7.6.3pycharm-community-3.1.1。对于我已安装的openCL:AMD-APP-SDK-v2.9-Windows-641Mako-0.9.1.win-amd64-py2.7pytools-2014.1.2.win-amd64-py2.7pyopencl-2013.2.win-amd64-py2.7

我的显卡是Radeon HD 7850,我有一台AMD PhenomII处理器。

P.S。:当我在Spyder中编译时,错误消息显示为:

>>> runfile('D:/python/openCL/020_array_sum.py', wdir=r'D:/python/openCL')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "D:/python/openCL/020_array_sum.py", line 20, in <module>
}""").build() # Create the OpenCL program
File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 166, in build
options=options, source=self._source)
File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 206, in _build_and_catch_errors
raise err
pyopencl.RuntimeError: clBuildProgram failed: invalid build options - 


(options: -I c:\program files\winpython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\cl)
(source saved as c:\users\andreas\appdata\local\temp\tmpzrgacv.cl)

编辑:我现在也在另一台PC上测试过:同样的错误。它还有一个Nvidia显卡。两者在commen中都有,它们仅在OpenCL 1.1中指定。可能是,我需要OpenCL 1.2吗?

2 个答案:

答案 0 :(得分:3)

我想我发现了这个问题。我更改了WinPython的installtion目录,使路径不再包含空格,现在为C:\WinPython-64bit-2.7.6.3。然后它奏效了。再次感谢您的所有建议和时间。

答案 1 :(得分:0)

这对我有用,我禁用了内置内核的缓存。如果您使用 pyopencl

,我的解决方案将非常有用
import os
os.environ['PYOPENCL_NO_CACHE'] = '1'