Strange sparse matrix error on GPU

I have a sparse matrix with a relatively small (16 MB) memory footprint
>> Whos A
Name Size Kilobytes Class Attributes
A 100000x100000 16406 double sparse
When I send it to the GPU and add the scalar 0, I get a puzzling error
>> gpuArray(A)+sparse(0);
Error using +
Maximum variable size allowed on the device is exceeded.
I really cannot see why this operation would cause any excessively large memory allocations. This is in Matlab version R2018a and the following GPU details. Does anyone have any insights as to why this occurs?
>> gpuDevice
ans =
CUDADevice with properties:
Name: 'GeForce GTX TITAN X'
Index: 1
ComputeCapability: '5.2'
SupportsDouble: 1
DriverVersion: 9.2000
ToolkitVersion: 9
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 1.2885e+10
AvailableMemory: 1.2259e+10
MultiprocessorCount: 24
ClockRateKHz: 1076000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 0
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1

1 comentario

Matt J
Matt J el 13 de Dic. de 2018
Editada: Matt J el 14 de Dic. de 2018
Here's a simple command to reproduce the problem,
>> gpuArray(speye(1e5))+sparse(0);
Error using +
Maximum variable size allowed on the device is exceeded.

Iniciar sesión para comentar.

 Respuesta aceptada

Edric Ellis
Edric Ellis el 14 de Dic. de 2018
The maximum number of elements in a gpuArray is intmax('int32'). In this case, the scalar addition is forcing your sparse matrix to become a full array of size 1e5×1e5. (In this particular case, because the scalar you are adding is precisely zero, then it could theoretically become a no-op.)
>> (1e5*1e5) <= intmax('int32')
ans =
logical
0

3 comentarios

Matt J
Matt J el 14 de Dic. de 2018
Hi Edric,
Sorry, I mistyped the test. It should be,
>> gpuArray(speye(1e5))+sparse(0);
Error using +
Maximum variable size allowed on the device is exceeded.
Because the added 0 is in sparse form, it should not be triggering the creation of a full matrix.
Edric Ellis
Edric Ellis el 17 de Dic. de 2018
Editada: Edric Ellis el 17 de Dic. de 2018
Ok, but even so, number of non-zeros required for the result exceeds intmax('int32') because unfortunately the gpuArray implementation of plus doesn't make a special case for adding zero - sparse gpuArray plus scalar always results in a "big sparse" array which is essentially a full array but with sparse storage.
Not terribly useful perhaps, but the following does work correctly:
>> gpuArray(speye(1e5)) + spalloc(1e5,1e5,0);
Matt J
Matt J el 17 de Dic. de 2018
Editada: Matt J el 17 de Dic. de 2018
OK. Well, I hope it's on the todo list of things to fix. :-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 13 de Dic. de 2018

Editada:

el 17 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by