Wrong result when using gpuArray with multiple implicit singleton expansions

1 回表示 (過去 30 日間)
Yunhui Zhou
Yunhui Zhou 2018 年 10 月 3 日
回答済み: Wentao Du 2018 年 10 月 8 日
Hi, I am using Matlab R2017b Update 8, and recently I find Matlab produce wrong result when calculating expressions using gpuArray with multiple implicit singleton expansion.
A minimal test case:
Matrixc = rand(2,2) * 3;
Matrixg = gpuArray(Matrixc);
wc = -2:1:2;
w3c = reshape(wc,1,1,length(wc));
w3g = gpuArray(w3c);
GPUc = gather(Matrixg(1,:).*w3g + 0.5*(Matrixg(1,:).^2+Matrixg.^2));
CPU = Matrixc(1,:).*w3c + 0.5*(Matrixc(1,:).^2+Matrixc.^2);
GPUtemp1 = Matrixg(1,:).*w3g;
GPUTemp2 = 0.5*(Matrixg(1,:).^2+Matrixg.^2);
GPUc2 = gather(GPUtemp1 + GPUTemp2);
disp(max(Matrixg(:) - Matrixc(:)));
disp(max(w3g(:) - w3c(:)));
disp(max(GPUc(:) - CPU(:)));
disp(max(GPUc2(:) - CPU(:)));
Produce results:
0
0
0.635767744700676
0
And as you can see here the problem can be by-passed by splitting up the expression to multiple steps. I want to know is it a Matlab bug or is it designed in this way?
UPDATE:
This is indeed a bug. See this bug report.

回答 (1 件)

Wentao Du
Wentao Du 2018 年 10 月 8 日
As described in the bug report , this bug was fixed as of R2018b and R2018a Update 4.
If you would like to use R2017b, you may try the workaround mentioned in the report.

カテゴリ

Help Center および File ExchangePerformance Profiling についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by