I am using pycuda to compute holograms for an optical trapping
application that uses PyQt4 for a GUI front end. I would like to move
the pycuda computation into a QThread to keep the GUI responsive.
Is there an up-to-date working example of "the right way" to move a
pycuda computational object into a QThread using moveToThread?
Despite much searching, I have not turned up sample code. The
pycuda FAQ addresses subclassing threads, but not moveToThread
method of QThread.
The following minimal example of a "do nothing" background
object appears to work correctly. It creates an object,
moves it into a thread, creates a pycuda context for the object in
its thread, and then stops the object by quitting the thread.
Before I dig deeper, can anyone confirm that this is the right approach?
Or am I missing something
=== snip for minimal example ===
from PyQt4 import QtCore
import pycuda.driver as cuda
def __init__(self, deviceID=0):
self.deviceID = deviceID
self.device = cuda.Device(self.deviceID)
self.context = self.device.make_context()
self.context = None
if __name__ == '__main__':
from PyQt4.QtGui import QApplication
app = QApplication(sys.argv)
obj = ComputeObject()
thread = QtCore.QThread()
*David G. Grier <http://physics.nyu.edu/grierlab/>*
Department of of Physics <http://physics.nyu.edu/> and Center for Soft
Matter Research <http://csmr.as.nyu.edu/>
New York University <http://nyu.edu/>
726 Broadway, room 873, New York, NY 10003 <https://goo.gl/maps/Tbs7JatcW4y>
Show replies by date