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
endend
g = gpuDevice; g.AvailableMemoryans = 5.2493e+09>> a = ones(1, 3e8, 'single', 'gpuArray');g = gpuDevice; g.AvailableMemoryans = 4.0493e+09 % 1.2GB hit as expected
>> obj = TestClass;>> obj.prop = a;>> g = gpuDevice; g.AvailableMemoryans = 2.8493e+09 % another 1.2GB hit, not expected
Best Answer