Massive slowdown for Apple Silicon in computing SVD

29 ビュー (過去 30 日間)
Gregory
Gregory 2024 年 12 月 5 日
回答済み: Heiko Weichelt 2024 年 12 月 21 日
I recently notice that there is an extreme slowdown in my version of Matlab while computing an SVD when the size of the matrix crosses some threshold. I came up with the following example that demonstrates my issue:
N = [10000 11000 12000 13000];
for i = 1:4
A = randn(N(i),3);
tic;
[U,S,V] = svd(A,0);
toc;
end
When I run this in Matlab R2024b (macOS Apple silicon), the output is:
Elapsed time is 0.000396 seconds.
Elapsed time is 0.000275 seconds.
Elapsed time is 0.000264 seconds.
Elapsed time is 0.083150 seconds.
Of course the exact numbers vary trial to trial, but the speed for the last run (where N = 13000) is consistently orders of magnitude slower.
When I run this same code on Matlab R2024b (Intel processor) on the same computer, this slow down does not happen. I was able to replicate this issue across two different Macs (one with M1 and another with M3) and different versions of Matlab (going back to R2023b).
Any idea why this might be happening in the silicon version?
Edit: I'm running macOS 15.1.1

採用された回答

Mike Croucher
Mike Croucher 2024 年 12 月 5 日
Hi
I have reproduced your times on my M2 MacbookPro using R2024b using both the default BLAS and also the Apple Silicon BLAS as described in my blog post https://blogs.mathworks.com/matlab/2023/12/13/life-in-the-fast-lane-making-matlab-even-faster-on-apple-silicon-with-apple-accelerate/
I am not sure what causes this but have reported it to development.
Thanks for the report.
Mike

その他の回答 (1 件)

Heiko Weichelt
Heiko Weichelt 2024 年 12 月 21 日
Thanks for reporting this.
We identified the problem and are working on improving this in a future release.
As a temporary workaround, we recommend replacing:
[U,S,V]=svd(A,0);
with
[Q,R]=qr(A,"econ"); [U,S,V]=svd(R); U=Q*U;
In general, this step is not needed as the SVD performs the QR inside itself. The LAPACK library currently used on Apple Silicon, however, had suboptimal tuning parameters for this case.
On my machine, the time for the largest example improved as following:
>> tic; [U,S,V]=svd(A,0); toc
Elapsed time is 0.086851 seconds.
>> tic; [Q,R]=qr(A,"econ"); [U,S,V]=svd(R); U=Q*U; toc
Elapsed time is 0.000977 seconds.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by