Multiple GPU's used in parallel.

7 visualizaciones (últimos 30 días)
David Short
David Short el 29 de Abr. de 2015
Comentada: Joss Knight el 28 de Mayo de 2015
I'm using R2014b and I'm fortunate enough to be in an environment where I have multiple GPU's available.
I have code that uses parfor's to divide the code up over multiple workers. It works fine.
I have code that uses a single GPU by using gpuArray to load the input variables, native Matlab routines to do the processing and gather to retrieve the output. It works fine.
I am familiar with Loren's blog which seems to be a cookbook for my next step, using multiple GPU's. http://blogs.mathworks.com/loren/2013/06/24/running-monte-carlo-simulations-on-multiple-gpus/
The thing is she doesn't push any old data out onto the GPU's and is using arrayfun instead of gpuArray and native matlab.
stay with me here.... Computation within my parfor loop uses several variables from earlier in the code. These variables are all input which will not be changed within the parfor. The code executes fine in that state. When I set my number of workers to 1 the code works fine.
When I start trying to use a single GPU (with one worker) and try to load data into the GPU I hit a snag.
workers = 1;
Zc=2.25;
parfor www = 1:workers;
ftemp=zeros(nx,ny);
ftemp = gpuArray(ftemp);
Zc = gpuArray(Zc);
...
loading Zc onto the GPU gives me the following error.
Error using testz (line 513)
An UndefinedFunction error was thrown on the workers for 'Zc'. This might be because the file containing 'Zc' is
not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached.
See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Caused by:
Undefined function or variable 'Zc'.
Going back to Loren's blog it seems the best solution may be to refactor my code to use arrayfun instead of gpuarray, but I hate to get into that without really understanding the root of my problem and why my current approach is exploding.
Advice is welcome. Other than the blog referenced above, there just isn't a lot of current info about using multiple GPUs. Thanks for reading.
  5 comentarios
David Short
David Short el 14 de Mayo de 2015
All,
With some experimentation I have something close to what I need.
What I wanted to do. For i = 1,N Allocate GPU i End
Parfor GPUARRAY.. (Pass the data to the GPU) Computation Get (Return data from GPU) End
What matlab actually needs. Parfor Allocate a GPU GPUARRAY Computation Get End
So I'll need to think about partially refactoring and rolling out some of the parfor loop. Much closer to what I need. Not what I desired, but I CAN get there from here.
David
Joss Knight
Joss Knight el 28 de Mayo de 2015
David, you won't be able to allocate GPU memory in one loop that you can access in another, especially when you have multiple GPUs. The host machine owns all arrays outside the loops and any gpuArrays must be stored on its GPU - and the mechanism for passing data back and forth to the workers uses CPU memory so you're gaining nothing. Keep your data in CPU memory and send it to the device inside your loops for your computations.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by