Bug in index output of max and min on gpuArray
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Srivardhan Gadila
on 30 Oct 2020
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 Comments
See Also
Categories
Find more on GPU Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!