【问题标题】:pyopencl.RuntimeError: clBuildProgram failed: invalid build optionspyopencl.RuntimeError:clBuildProgram 失败:无效的构建选项
【发布时间】:2019-08-17 16:25:14
【问题描述】:

我是 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显卡。两者的共同点是它们仅在 OpenCL 1.1 中指定。会不会,我需要 OpenCL 1.2?

【问题讨论】:

  • PyOpenCL 中包含的示例是否有效?我非正式地编写了该教程 - 所以github.com/pyopencl/pyopencl/tree/master/examples 的代码是更好的运行脚本,以查看您的系统是否设置正确。
  • @benshope:github.com/pyopencl/pyopencl/tree/master/examples 上的示例导致相同的错误。我使用了benchmark.py 脚本。在程序崩溃的build() 函数之前执行的所有打印。到目前为止,我也很确定我设置了一些不正确的东西,只是还没弄清楚是什么。
  • @benshope:抱歉,忘了说到目前为止我还没有找到任何例子。
  • 这可能没有帮助,但如果您完全用尽了选项 - 也许将您的机器双引导到 Ubuntu。 Ubuntu 的软件中心有一个包,我认为这是让 PyOpenCL “正常工作”的最简单方法。
  • 你必须寻找启动内核构建的python代码。它可能被某些您可以从外部控制的定义控制。您可能必须禁用/启用其中的一些才能更改默认行为,因为默认选项的错误会让您的平台编译器抱怨。您还可以尝试为您的 OpenCL 安装另一个更新的驱动程序,其中可能包含更新的编译器。你也可以试试.build("")

标签: python opencl pyopencl


【解决方案1】:

我想我找到了问题所在。我更改了 WinPython 的安装目录,使得路径不再包含空格,现在是 C:\WinPython-64bit-2.7.6.3。然后它起作用了。再次感谢您的所有建议和时间。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 2017-11-21
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 2022-01-16
      相关资源
      最近更新 更多