MATLAB: Does norm(gpuArray) return a double in Matlab 2015b

gpugpu computingParallel Computing Toolbox

I have Matlab 2015b and Matlab 2017a, and I noticed that the two versions of Matlab were treating "norm" differently. One would output a double and the other would output a gpuArray. The example is below.
Matlab 2017a
class(norm(gpuArray)) = gpuArray
Matlab 2015b
class(norm(gpuArray)) = double
My question is: Is Matlab 2015b gathering the data off the gpu every time you run a built in function like norm?

Best Answer

The debate over this could go round the houses 100 times! The logic was that scalars should always be returned on the CPU because it's more efficient to do scalar operations there. But all gpuArray scalar operations are computed on the host anyway (for efficiency), and it's just as likely that the result of norm will be used in an array operation (such as normalizing an array). So the new logic is that scalars that are computed on the GPU should stay on the GPU, because to gather them to the CPU incurs a device synchronization that could slow down people's code. This is annoying if you immediately pass the norm to a function that doesn't support gpuArray, but it's easy enough to call gather in that case.
So the answer to your question is no, MATLAB always returns results on the GPU, with the exception of querying array properties ( size, nnz, bandwidth etc). But norm used to be an outlier to that guarantee.
Related Question