nkhdiscovery commented on issue #4659: gpu memory allocate will be error when 
using multiprocessing.Process
URL: 
https://github.com/apache/incubator-mxnet/issues/4659#issuecomment-466630959
 
 
   @leezu 
   Here is something even more complex which works, I thought anybody else may 
come here and needs the solution - which does not work if you do not force  
`mp.set_start_method('forkserver', force=True)`
   
   `import random
   import numpy as np
   import mxnet as mx
   import multiprocessing as mp
   
   def test():
       mx.random.seed(random.randint(10,200))
       a = mx.nd.random_normal(shape=(2,2), ctx=mx.gpu(0))
       print('child no. ', mp.current_process().name, ':' , a)
   
   if __name__ == '__main__':
       mp.set_start_method('forkserver', force=True)
       ab = mx.nd.random_normal(shape=(2,2), ctx=mx.gpu(0))
       print('main proc.: ', ab)
       runs = [mp.Process(target=test) for i in range(3)]
       for p in runs:
         p.start()
       for p in runs:
         p.join()
   
       print('done')`
   
   Hope it helps.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to