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

1 回表示 (過去 30 日間)
Hannah
Hannah 2017 年 8 月 10 日
編集済み: Hannah 2017 年 8 月 10 日
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 Center および File ExchangeGPU Computing in MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by