Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Hannah
Hannah el 10 de Ag. de 2017
Editada: Hannah el 10 de Ag. de 2017
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?

Respuesta aceptada

Joss Knight
Joss Knight el 10 de Ag. de 2017
Editada: Joss Knight el 10 de Ag. de 2017
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.

Más respuestas (0)

Categorías

Más información sobre GPU Computing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by