Main Content


Reset GPU device and clear its memory



reset(gpudev) resets the GPU device and clears its memory of gpuArray and CUDAKernel data. The GPU device identified by gpudev remains the selected device, but all gpuArray and CUDAKernel objects in MATLAB representing data on that device are invalid.


collapse all

Select the GPU device and create a gpuArray.

g = gpuDevice(1);
M = gpuArray(magic(4))
M =

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

Reset the device.


Show that the device is still selected

g = 

  CUDADevice with properties:

                      Name: 'NVIDIA RTX A5000'
                     Index: 1
         ComputeCapability: '8.6'
            SupportsDouble: 1
             DriverVersion: 11.6000
            ToolkitVersion: 11.2000
        MaxThreadsPerBlock: 1024
          MaxShmemPerBlock: 49152 (49.15 KB)
        MaxThreadBlockSize: [1024 1024 64]
               MaxGridSize: [2.1475e+09 65535 65535]
                 SIMDWidth: 32
               TotalMemory: 25553076224 (25.55 GB)
           AvailableMemory: 25153765376 (25.15 GB)
       MultiprocessorCount: 64
              ClockRateKHz: 1695000
               ComputeMode: 'Default'
      GPUOverlapsTransfers: 1
    KernelExecutionTimeout: 0
          CanMapHostMemory: 1
           DeviceSupported: 1
           DeviceAvailable: 1
            DeviceSelected: 1

Show that the gpuArray variable name is still in the MATLAB workspace

  Name      Size            Bytes  Class                      Attributes

  M         4x4                 0  gpuArray                             
  g         1x1                 8  parallel.gpu.CUDADevice 

Try to display the gpuArray.

M =

    Data no longer exists on the GPU.

Clear the variable.

clear M

Input Arguments

collapse all

GPU device, specified as a GPUDevice object that represents the currently selected device


After you reset a GPU device, any variables representing arrays or kernels on the device are invalid; you should clear or redefine them.

Version History

Introduced in R2012a