microsoft / microsoft/onnxruntime

not work for OrtCUDAProviderOptionsV2 to release GPU memory in C++

Open
#12,748 4 comments 0 reactions 1 assignee View on GitHub

@petermcaughan is already working on this.

Since Sep 1, 2022.

core runtime ep:CUDA
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:

  1. Not allocate weights memory through the arena: See here

  2. Configure the arena to have high enough initial chunk to support most Run() calls. See "initial_chunk_size_bytes" here

  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.