Last active
December 3, 2015 16:34
-
-
Save lebedov/2b0017b537dfd78d3bf3 to your computer and use it in GitHub Desktop.
Simple demo of how to use scikit-cuda with multiprocessing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Simple demo of how to use scikit-cuda with multiprocessing. | |
""" | |
import atexit | |
import multiprocessing as mp | |
import numpy as np | |
import pycuda.driver as drv | |
import pycuda.gpuarray as gpuarray | |
import skcuda.linalg as linalg | |
def my_proc(n): | |
drv.init() | |
dev = drv.Device(n) | |
ctx = dev.make_context() | |
atexit.register(ctx.pop) | |
linalg.init() | |
# Generate different pseudorandom sequences for each GPU: | |
np.random.seed(n) | |
a_gpu = gpuarray.to_gpu(np.random.rand(2, 2)) | |
b_gpu = gpuarray.to_gpu(np.random.rand(2, 2)) | |
print 'GPU %s: ' % n | |
print linalg.dot(a_gpu, b_gpu) | |
if __name__ == '__main__': | |
num_gpus = 2 | |
for i in range(num_gpus): | |
p = mp.Process(target=my_proc, args=(i, )) | |
p.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment