Discussion:
[PyCUDA] GPU selection (round robin)
Keith Brown
2015-12-03 20:07:44 UTC
Permalink
I have several GPUs and I want to distribute my tasks to each GPU. I
would like to use multiprocessing.Pool() to accomplish it

import random
import pycuda.gpuarray as gpuarray
import atexit
import pycuda.driver as cuda
import pycuda.autoinit as autoinit
import time
import numpy as np
import skcuda.linalg as linalg
import skcuda
import multiprocessing as mp
import pycuda.driver as drv

def my_proc(n):
drv.init()
dev = drv.Device(n)
ctx = dev.make_context()
atexit.register(ctx.pop)
linalg.init()
a=np.ones((185,185)).astype(np.float32)
a_gpu = gpuarray.to_gpu(a)
c_gpu = linalg.dot(a_gpu,a_gpu)
return c_gpu.get()

r=[]
Pool=mp.Pool(10)
for i in range(1000):
Pool.apply_async(my_proc,(random.randint(0,1),))


I keep getting
pycuda._driver.LogicError: cuCtxPopCurrent failed: invalid device context

Is there somthing I should be doing?
Andreas Kloeckner
2015-12-03 23:01:33 UTC
Permalink
Post by Keith Brown
I have several GPUs and I want to distribute my tasks to each GPU. I
would like to use multiprocessing.Pool() to accomplish it
import random
import pycuda.gpuarray as gpuarray
import atexit
import pycuda.driver as cuda
import pycuda.autoinit as autoinit
import time
import numpy as np
import skcuda.linalg as linalg
import skcuda
import multiprocessing as mp
import pycuda.driver as drv
drv.init()
dev = drv.Device(n)
ctx = dev.make_context()
atexit.register(ctx.pop)
linalg.init()
a=np.ones((185,185)).astype(np.float32)
a_gpu = gpuarray.to_gpu(a)
c_gpu = linalg.dot(a_gpu,a_gpu)
return c_gpu.get()
r=[]
Pool=mp.Pool(10)
Pool.apply_async(my_proc,(random.randint(0,1),))
I keep getting
pycuda._driver.LogicError: cuCtxPopCurrent failed: invalid device context
Is there somthing I should be doing?
If you have the GPUs set to exclusive mode, then PyCUDA should take care
of round-robin device selection on its own.

Andreas
Keith Brown
2015-12-03 23:22:15 UTC
Permalink
is this something I do a 'root' ? Or via PyCuda? I am afraid I wont
have access to 'root'


On Thu, Dec 3, 2015 at 6:01 PM, Andreas Kloeckner
Post by Andreas Kloeckner
Post by Keith Brown
I have several GPUs and I want to distribute my tasks to each GPU. I
would like to use multiprocessing.Pool() to accomplish it
import random
import pycuda.gpuarray as gpuarray
import atexit
import pycuda.driver as cuda
import pycuda.autoinit as autoinit
import time
import numpy as np
import skcuda.linalg as linalg
import skcuda
import multiprocessing as mp
import pycuda.driver as drv
drv.init()
dev = drv.Device(n)
ctx = dev.make_context()
atexit.register(ctx.pop)
linalg.init()
a=np.ones((185,185)).astype(np.float32)
a_gpu = gpuarray.to_gpu(a)
c_gpu = linalg.dot(a_gpu,a_gpu)
return c_gpu.get()
r=[]
Pool=mp.Pool(10)
Pool.apply_async(my_proc,(random.randint(0,1),))
I keep getting
pycuda._driver.LogicError: cuCtxPopCurrent failed: invalid device context
Is there somthing I should be doing?
If you have the GPUs set to exclusive mode, then PyCUDA should take care
of round-robin device selection on its own.
Andreas
Loading...