In-place operation at gpuarray

3 views (last 30 days)
David Rozenberg
David Rozenberg on 13 Jan 2016
Edited: Joss Knight on 4 Feb 2016
I'm using Matlab 2015b on Ubuntu 14.04
I'm unable to perform inplace operations on gpuarray even when both left & right hand variables are the same.
For example:
gpA = ones (N,M,'single','gpuarray');
S = 5;
gpA = gpA.*S;
gpA = abs (gpA);
If N & M are big enough so gpA occupies more than half of the GPU memory, the above operations results in out of memory exception.
How do I perform simple inplace operations without writing a proprietary kernel?
Thanks in advance, David

Answers (1)

Joss Knight
Joss Knight on 4 Feb 2016
Edited: Joss Knight on 4 Feb 2016
Do it inside a function. On the command line MATLAB cannot operate on the arguments to functions in-place, because (to cite one of the reasons) if a function errors or the user hits Ctrl-C it needs to be able to return your workspace to the state it was in before you ran the function, not some half-completed state.

Community Treasure Hunt

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

Start Hunting!