您好我正在嘗試使用Python的OpenCL。我試圖將一個數組和一個const變量傳遞給cl程序,並簡單地將const變量複製到cl設備上的數組。這應該是很簡單的,但我收到以下錯誤:Python的OpenCL主機程序,以cl程序參數傳遞
Traceback (most recent call last):
File "<pyshell#103>", line 1, in <module>
test()
File "D:/Programming/Programs_OpenCL_Python/Host_CL_Parameter_Passing.py", line 141, in test
event = prg.test(queue, (10,1), None, a_dev, b)
File "C:\Python27\lib\site-packages\pyopencl-2012.1-py2.7-win32.egg\pyopencl\__init__.py", line 457, in kernel_call
self.set_args(*args)
File "C:\Python27\lib\site-packages\pyopencl-2012.1-py2.7-win32.egg\pyopencl\__init__.py", line 509, in kernel_set_args
% (i+1, str(e), advice))
LogicError: when processing argument #2 (1-based): Kernel.set_arg failed: invalid value - invalid kernel argument
下面的代碼代碼:
def test():
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
a = np.empty(10, dtype = int)
b = int(1)
a_dev = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, a.nbytes)
prg = cl.Program(ctx, """__kernel void test(__global int *a, const int b){
int i = get_global_id(0);
a[i] = b;
}""").build()
event = prg.test(queue, (10,1), None, a_dev, b)
event.wait()
cl.enqueue_copy(queue, a, a_dev)
print a
誰能告訴我的問題,並給我一個解決方案嗎?這真讓我抓狂。 三江源
您可能想要編輯的標題反映出你的問題是標量參數,而不是內核的數組參數。 –