Bug in index output of max and min on gpuArray

2 visualizaciones (últimos 30 días)
Kyle Watson
Kyle Watson el 26 de Oct. de 2020
Respondida: Srivardhan Gadila el 30 de Oct. de 2020
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.

Respuestas (1)

Srivardhan Gadila
Srivardhan Gadila el 30 de Oct. de 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';

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by