Why does norm(gpuArray) return a double in Matlab 2015b?

2 次查看(过去 30 天)
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?

采纳的回答

Joss Knight
Joss Knight 2017-8-10
编辑:Joss Knight 2017-8-10
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 GPU Computing in MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by