Maybe some elaboration is in order. Our lab has GPGPU code that calls the GPU from MATLAB entirely through shared libraries involving a lot of our own CUDA code. An M-coded handle class object is used to invoke these libraries as needed.
Currently, when the handle object is cleared, the class delete() method is called and issues a clearing command to the GPU similar (but not indentical) to invoking gpuDevice([]). However, problems arise when there are also gpuArray variables present in the workspace. Any subsequent attempt to use the gpuArray variables after the handle object is deleted then crash the GPU.
So the question is, during deletion of the handle object, what needs to be done to the GPU (what state does it need to be left in) to safely let go of the graphics card and to ensure that the gpuArray variables continue to be valid?