在不同设备上运行时,PyOpenCL排队_拷贝挂起
我很难让内核在两个不同的OpenCL平台上运行。平台的唯一区别是一个是OpenCL 1.1,另一个是OpenCL 1.2: 代码在此设备(OS X 10.8)上工作: 目标设备(Ubuntu 11.04): 我已将我认为的挂起源代码追溯到以下代码:在不同设备上运行时,PyOpenCL排队_拷贝挂起,opencl,pyopencl,Opencl,Pyopencl,我很难让内核在两个不同的OpenCL平台上运行。平台的唯一区别是一个是OpenCL 1.1,另一个是OpenCL 1.2: 代码在此设备(OS X 10.8)上工作: 目标设备(Ubuntu 11.04): 我已将我认为的挂起源代码追溯到以下代码: # set up host_array = numpy.array(arr) device_buffer = pyopencl.Buffer(context, pyopencl.mem_flags.WRITE_ONLY, host_array.nb
# set up
host_array = numpy.array(arr)
device_buffer = pyopencl.Buffer(context, pyopencl.mem_flags.WRITE_ONLY, host_array.nbytes)
# run the kernel
program.run(queue, host_array.shape, None, device_buffer)
# copy the results back --- this call causes the code to hang ----
pyopencl.enqueue_copy(queue, host_array, device_buffer)
两台设备之间没有代码更改,并且两台设备都运行PyOpenCL 2013.1。我错过什么了吗?任何建议都将不胜感激 尝试向
程序添加.wait()
。运行。这将确定挂起的是否是程序。结果表明问题是线程问题。我使用线程模块生成的第二个线程来调用pyopencl。我认为问题在于我用来调用pyopencl的上下文是在主线程上创建的,我认为这导致了某种问题
为了解决这个问题,我只是确保在第二个线程而不是主线程上声明我的上下文、队列和创建的程序 我尝试将.wait()
添加到程序中。运行以及调用程序时收到的事件对象。运行,但程序在第一次调用enqueue\u copy
时仍然挂起(我在两次调用之间使用了print
)。如果不运行内核,是否也会发生挂起?是的。原来是pyopencl外部的线程问题。
===============================================================
('Platform name:', 'NVIDIA CUDA')
('Platform profile:', 'FULL_PROFILE')
('Platform vendor:', 'NVIDIA Corporation')
('Platform version:', 'OpenCL 1.1 CUDA 4.2.1')
---------------------------------------------------------------
('Device name:', 'Tesla M2050')
('Device type:', 'GPU')
('Device memory: ', 3071, 'MB')
('Device max clock speed:', 1147, 'MHz')
('Device compute units:', 14)
===============================================================
('Platform name:', 'NVIDIA CUDA')
('Platform profile:', 'FULL_PROFILE')
('Platform vendor:', 'NVIDIA Corporation')
('Platform version:', 'OpenCL 1.1 CUDA 4.2.1')
---------------------------------------------------------------
('Device name:', 'Tesla M2050')
('Device type:', 'GPU')
('Device memory: ', 3071, 'MB')
('Device max clock speed:', 1147, 'MHz')
('Device compute units:', 14)
# set up
host_array = numpy.array(arr)
device_buffer = pyopencl.Buffer(context, pyopencl.mem_flags.WRITE_ONLY, host_array.nbytes)
# run the kernel
program.run(queue, host_array.shape, None, device_buffer)
# copy the results back --- this call causes the code to hang ----
pyopencl.enqueue_copy(queue, host_array, device_buffer)