When I attempt to initialize PyCUDA immediately before forking a
process via the multiprocessing module and then try to initialize
PyCUDA within the new process, it appears that the forked process
turns into a zombie. Is this behavior expected? To observe this,
uncomment the drv.init() in the main body of the attached script.

I'm using PyCUDA 0.94.2, Python 2.6.5, pyzmq 2.1.1, and zeromq 2.1.4.

                                                    L.G.
import numpy as np
import pycuda.driver as drv

import zmq
import multiprocessing as mp

def _server_func():
    
    # Wait for a connection:
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    socket.bind("tcp://*:5555")

    # Get the device number:
    dev_num = socket.recv_pyobj()
    socket.send_pyobj('ack')

    # Initialize the GPU:
    import pycuda.driver as drv
    drv.init()
    dev = drv.Device(int(dev_num))
    ctx = dev.make_context()
    import atexit
    atexit.register(ctx.pop)
    import pycuda.gpuarray as gpuarray
    
    # Get and process the data:
    data = socket.recv_pyobj()
    data_gpu = gpuarray.to_gpu(data)
    result_gpu = data_gpu*2
    socket.send_pyobj(result_gpu.get())

def func(x, dev_num=0):

    # Start the server:
    server = mp.Process(target=_server_func)
    server.start()

    # Connect to the server:
    context = zmq.Context()
    socket = context.socket(zmq.REQ)
    socket.connect("tcp://localhost:5555")

    # Send the GPU number:
    socket.send_pyobj(dev_num)
    socket.recv_pyobj()
    
    # Send the data:
    socket.send_pyobj(x)
    result = socket.recv_pyobj()

    # Clobber the remote process:
    server.terminate()
    
    return result

if __name__ == '__main__':
    import numpy as np
    # drv.init()
    print func(np.random.rand(3, 3), 1)
    
_______________________________________________
PyCUDA mailing list
PyCUDA@tiker.net
http://lists.tiker.net/listinfo/pycuda

Reply via email to