PyOpenCL enqueue_copy在不同设备上运行时挂起

时间:2013-02-04 20:30:34

标签: opencl pyopencl

我无法让内核在两个不同的OpenCL平台上运行。平台的唯一区别是一个是OpenCL 1.1,另一个是1.2:

代码适用于此设备(OS X 10.8):

===============================================================
('Platform name:', 'Apple')
('Platform profile:', 'FULL_PROFILE')
('Platform vendor:', 'Apple')
('Platform version:', 'OpenCL 1.2 (Sep 20 2012 17:42:28)')
---------------------------------------------------------------
('Device name:', 'Intel(R) Core(TM) i5-3427U CPU @ 1.80GHz')
('Device type:', 'CPU')
('Device memory: ', 8192L, 'MB')
('Device max clock speed:', 1800, 'MHz')
('Device compute units:', 4)

目标设备(Ubuntu 11.04):

===============================================================
('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)

两台设备之间没有代码更改,两台设备都运行PyOpenCL 2013.1。我错过了什么吗?任何建议都非常感谢。

2 个答案:

答案 0 :(得分:1)

尝试向.wait()添加program.run。这将确定它是否实际上是悬挂的程序。

答案 1 :(得分:0)

原来问题是线程问题。我使用了使用线程模块生成的第二个线程来进行pyopencl调用。我相信问题是我用来调用pyopencl的上下文是在主线程上创建的,我认为这会引起某种问题。

要修复我只是确保在第二个线程而不是主线程上声明我的上下文,队列和创建的程序。