# Restarting CUDA

**URL:** <https://discourse.julialang.org/t/restarting-cuda/122163>\
**Category:** GPU\
**Created:** [November 2, 2024, 8:48am UTC](https://discourse.julialang.org/t/restarting-cuda/122163 "2024-11-02T08:48:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabrice\_Rosay](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabrice_rosay/32/15689_2.png) [@Fabrice\_Rosay](https://discourse.julialang.org/u/Fabrice_Rosay)\
**Post date:** [November 2, 2024, 8:48am UTC](https://discourse.julialang.org/t/restarting-cuda/122163/1 "2024-11-02T08:48:14Z")

</div>

Is there a way to reset CUDA without restarting julia and be sure everything in memory related to gpu is wiped ? (multiple call to GC.gc and CUDA.reclaim or unsafe\_free! seems to miss some objects, leading to increase memory usage and call to GC in my use case). I have a loop that takes quite a long time to execute and i would like to make such a reset after each iteration of the loop.

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [November 4, 2024, 4:30pm UTC](https://discourse.julialang.org/t/restarting-cuda/122163/2 "2024-11-04T16:30:24Z")

</div>

Not really. We kind-of support resetting the device’s context with `CUDA.device_reset!`, but doing so complicates lots of things (e.g. using a `CuArray` from before a reset will instantly trigger illegal memory errors that necessitate restarting the process) and even breaks some NVIDIA libraries. So I would advise against this.

CUDA’s new “green contexts” may be a way to implement this more robustly, but I haven’t looked into this.
