forked from karthikncode/direction_decomposition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multigpu.py
30 lines (26 loc) · 767 Bytes
/
multigpu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import threading
from pycuda import driver
class gpuThread(threading.Thread):
def __init__(self, gpuid, id_num):
threading.Thread.__init__(self)
self.ctx = driver.Device(gpuid).make_context()
self.device = self.ctx.get_device()
self.id = id_num
def run(self):
print "%s has device %s, api version %s" \
% (self.getName(), self.device.name(), self.ctx.get_api_version())
for i in range(1000):
print self.id, i
# Profit!
def join(self):
self.ctx.detach()
threading.Thread.join(self)
driver.init()
ngpus = driver.Device.count()
threads = []
for i in range(ngpus):
t = gpuThread(i, i)
t.start()
threads.append(t)
for t in threads:
t.join()