[Rtk-users] Clearing cuda variables in python
Simon Rit
simon.rit at creatis.insa-lyon.fr
Fri Jun 16 08:55:55 CEST 2023
Hi,
If you have a Python variable holding memory, you can simply call
del variable_name
If you want to clear the GPU memory for an image, you can access the CPU
buffer pointer to have it moved to the computer RAM. Examples below.
Simon
>>> import os
>>> os.system('nvidia-smi')
Fri Jun 16 08:49:38 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6
|
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr.
ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute
M. |
| | | MIG
M. |
|===============================+======================+======================|
| 0 Quadro P2000 Off | 00000000:01:00.0 Off |
N/A |
| N/A 52C P8 N/A / N/A | 0MiB / 4096MiB | 0%
Default |
| | |
N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:
|
| GPU GI CI PID Type Process name GPU
Memory |
| ID ID Usage
|
|=============================================================================|
| No running processes found
|
+-----------------------------------------------------------------------------+
0
>>> import itk
>>> from itk import RTK as rtk
>>> img=itk.CudaImage[itk.F, 3].New()
>>> img.SetRegions([500]*3)
>>> img.Allocate()
>>> os.system('nvidia-smi')
Fri Jun 16 08:51:28 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6
|
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr.
ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute
M. |
| | | MIG
M. |
|===============================+======================+======================|
| 0 Quadro P2000 Off | 00000000:01:00.0 Off |
N/A |
| N/A 58C P8 N/A / N/A | 45MiB / 4096MiB | 0%
Default |
| | |
N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:
|
| GPU GI CI PID Type Process name GPU
Memory |
| ID ID Usage
|
|=============================================================================|
| 0 N/A N/A 10890 C python
43MiB |
+-----------------------------------------------------------------------------+
0
>>> img.GetCudaDataManager().GetGPUBufferPointer()
<Swig Object of type 'void *' at 0x7f20d3327f60>
>>> os.system('nvidia-smi')
Fri Jun 16 08:52:05 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6
|
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr.
ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute
M. |
| | | MIG
M. |
|===============================+======================+======================|
| 0 Quadro P2000 Off | 00000000:01:00.0 Off |
N/A |
| N/A 54C P0 N/A / N/A | 525MiB / 4096MiB | 0%
Default |
| | |
N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:
|
| GPU GI CI PID Type Process name GPU
Memory |
| ID ID Usage
|
|=============================================================================|
| 0 N/A N/A 10890 C python
523MiB |
+-----------------------------------------------------------------------------+
0
>>> del img
>>> os.system('nvidia-smi')
Fri Jun 16 08:52:21 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6
|
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr.
ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute
M. |
| | | MIG
M. |
|===============================+======================+======================|
| 0 Quadro P2000 Off | 00000000:01:00.0 Off |
N/A |
| N/A 56C P0 N/A / N/A | 2MiB / 4096MiB | 0%
Default |
| | |
N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:
|
| GPU GI CI PID Type Process name GPU
Memory |
| ID ID Usage
|
|=============================================================================|
| No running processes found
|
+-----------------------------------------------------------------------------+
0
>>> img=itk.CudaImage[itk.F, 3].New()
>>> img.SetRegions([500]*3)
>>> img.GetCudaDataManager().GetGPUBufferPointer()
<Swig Object of type 'void *' at 0x7f20b2c30870>
>>> os.system('nvidia-smi')
Fri Jun 16 08:54:10 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6
|
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr.
ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute
M. |
| | | MIG
M. |
|===============================+======================+======================|
| 0 Quadro P2000 Off | 00000000:01:00.0 Off |
N/A |
| N/A 58C P0 N/A / N/A | 525MiB / 4096MiB | 0%
Default |
| | |
N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:
|
| GPU GI CI PID Type Process name GPU
Memory |
| ID ID Usage
|
|=============================================================================|
| 0 N/A N/A 10890 C python
523MiB |
+-----------------------------------------------------------------------------+
0
>>> img.GetCudaDataManager().GetCPUBufferPointer()
>>> os.system('nvidia-smi')
Fri Jun 16 08:54:20 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.39.01 Driver Version: 510.39.01 CUDA Version: 11.6
|
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr.
ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute
M. |
| | | MIG
M. |
|===============================+======================+======================|
| 0 Quadro P2000 Off | 00000000:01:00.0 Off |
N/A |
| N/A 58C P0 N/A / N/A | 47MiB / 4096MiB | 0%
Default |
| | |
N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:
|
| GPU GI CI PID Type Process name GPU
Memory |
| ID ID Usage
|
|=============================================================================|
| 0 N/A N/A 10890 C python
45MiB |
+-----------------------------------------------------------------------------+
0
On Thu, Jun 15, 2023 at 5:33 PM Rahman, Obaid <rahmano at ornl.gov> wrote:
> Hi,
>
> I am using ink-rtk-cuda116 with *python*.
> I have too many cuda variables (images and filters).
> I would like to clear some of these variables.
>
> I am getting the following error:
> ITK ERROR: CUDA ERROR: out of memory
>
> Does anyone know how to clear Cuda variables in python?
> Thanks.
>
> Best,
> Obaidullah Rahman
> Oak Ridge National Laboratory, TN, United States
> _______________________________________________
> Rtk-users mailing list
> rtk-users at openrtk.org
> https://www.creatis.insa-lyon.fr/mailman/listinfo/rtk-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.creatis.insa-lyon.fr/pipermail/rtk-users/attachments/20230616/b9abd995/attachment-0001.htm>
More information about the Rtk-users
mailing list