-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
522d026
commit 9600e7f
Showing
7 changed files
with
34 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Utility functions around cuda, e.g. memory management.""" | ||
|
||
import gc | ||
|
||
import torch | ||
|
||
try: | ||
import cupy as cp | ||
except ImportError: | ||
cp = None | ||
|
||
|
||
def free_cupy(): | ||
"""Free the CUDA memory of cupy.""" | ||
if cp is not None: | ||
gc.collect() | ||
cp.get_default_memory_pool().free_all_blocks() | ||
cp.get_default_pinned_memory_pool().free_all_blocks() | ||
|
||
|
||
def free_torch(): | ||
"""Free the CUDA memory of pytorch.""" | ||
gc.collect() | ||
if torch.cuda.is_available(): | ||
torch.cuda.empty_cache() |