incorrect memory copy when using property size validator
Mostrar comentarios más antiguos
When using a size validator in a property block of a class an assigned variable's memory is copied instead of just pointing to it. This is 1) not expected due to standard matlab behavior, and 2) does not happen if using a manual set.prop(this, in) method to do the validation check.
There is then a secondary bug that when assigning a gpu variable and memory runs out (due to this memory bug) instead of giving an out of memory error, I instead get a size validation check did not pass error.
I see the same error on 2019b on a different computer. Example code below:
classdef TestClass < handle
properties
prop (1, :) % also happens with hard coded sizes and n-dimensional arrays
end
end
g = gpuDevice; g.AvailableMemory
ans =
5.2493e+09
>> a = ones(1, 3e8, 'single', 'gpuArray');
g = gpuDevice; g.AvailableMemory
ans =
4.0493e+09 % 1.2GB hit as expected
>> obj = TestClass;
>> obj.prop = a;
>> g = gpuDevice; g.AvailableMemory
ans =
2.8493e+09 % another 1.2GB hit, not expected
Respuesta aceptada
Más respuestas (1)
Kyle
el 17 de En. de 2020
0 votos
1 comentario
Joss Knight
el 18 de En. de 2020
Editada: Joss Knight
el 18 de En. de 2020
I guess all I was trying to point out was that shared data copies are just an optimisation that shouldn't be 'expected behaviour' because MATLAB provides no documentation about when it will or won't happen. If anything it should be more of a surprise when copying a into obj.Prop doesn't use up memory than when it does. You certainly shouldn't come to rely on the behaviour.
It does not seem like designed behaviour if property validators return a failed validation if they OOM though ... I'll follow up on that one.
Categorías
Más información sobre Software Development Tools en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!