microsoft / microsoft/onnxruntime
not work for OrtCUDAProviderOptionsV2 to release GPU memory in C++
@petermcaughan is already working on this.
Since Sep 1, 2022.
- Dominant language
- C++
- Stars
- 21.9k
- Forks
- 4.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 179
Description
Thanks @Z-XQ for the explanation.
The GPU memory is backed by a memory pool (arena) and we have a config knob to shrink the arena (de-allocated unused memory chunks).
Not sure if we have enough tools to accomplish this in Python just yet. The best way to use this feature in C++ is to:
-
Not allocate weights memory through the arena: See here
-
Configure the arena to have high enough initial chunk to support most Run() calls. See "initial_chunk_size_bytes" here
-
Finally, configure the arena to shrink on every Run(). See here. This will keep the initial chunk allocated but de-allocate any unused chunk remaining after the Run() call ends.
For example, if the initial chunk size is set as 500MB, the first Run() will allocate 500MB + any additional chunks required to service the Run() call. The additional chunks will get de-allocated after Run() and only keep 500MB of memory allocated. It is important to not allocate weights (initializers) memory through the arena as that complicates the shrinkage. Hence, step (1).
Originally posted by @hariharans29 in https://github.com/microsoft/onnxruntime/issues/9509#issuecomment-951546580
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.