gpt4 book ai didi

python - pyopencl.运行时错误 : clBuildProgram failed: invalid build options

转载 作者:太空宇宙 更新时间:2023-11-04 01:19:11 25 4
gpt4 key购买 nike

我是 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)

编辑:我现在也在另一台电脑上测试过它:同样的错误。它还具有 Nvidia 图形卡。两者的共同点是它们仅在 OpenCL 1.1 中指定。难道我需要 OpenCL 1.2?

最佳答案

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

关于python - pyopencl.运行时错误 : clBuildProgram failed: invalid build options,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22366517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com