Bug in index output of max and min on gpuArray
1 次查看(过去 30 天)
显示 更早的评论
There is a bug in the index output of max and min for gpuArrays. I am using 2018b and the bug also appears in 2019b. The index of the max (the 2nd output) is wrong for various lengths of arrays. For example:
x = randn(8680, 2, 'gpuArray');
[m, k] = max(x, [], 1);
disp(k)
[mCpu, kCpu] = max(gather(x), [], 1);
disp(kCpu)
isequal(k, kCpu) % different values!!
x = randn(8681, 2, 'gpuArray');
[m, k] = max(x, [], 1);
disp(k)
[mCpu, kCpu] = max(gather(x), [], 1);
disp(kCpu)
isequal(k, kCpu) % nagically now the same value!
OK let's do a test to see which lengths of x faile
n = 1 : 10e3;
bad = [];
for i = 1 : length(n)
x = randn(n(i), 2, 'single', 'gpuArray');
[m1, k1] = max(x, [], 1);
[m2, k2] = max(gather(x), [], 1);
if ~isequal(k1, k2)
bad(end+1) = n(i);
end
end
figure
plot(bad) % there are 410 values between 1 and 10e3 that fail!!
Now let's try again with different 2nd dim lengths of x
n = 1 : 10e3;
bad = [];
for i = 1 : length(n)
x = randn(n(i), 4, 'single', 'gpuArray');
[m1, k1] = max(x, [], 1);
[m2, k2] = max(gather(x), [], 1);
if ~isequal(k1, k2)
bad(end+1) = n(i);
end
end
figure
plot(bad) % now 147 that fail.
0 个评论
回答(1 个)
Srivardhan Gadila
2020-10-30
The issue has been reported to the concerned team.
The workaround would be to transpose the matrix and reducing along the columns:
[m1, k1] = max(x', [], 2);
m1 = m1';
k1 = k1';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!