microsoft / microsoft/onnxruntime

[Feature Request]

Open
#14,796 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ep:CUDA feature request
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

Describe the feature request

I am using onnxruntime version 1.14.0 with the programming language C#. When I try to use env.CreateAndRegisterAllocator(memInfo, arenaCfg), I encounter the following error: [ErrorCode:InvalidArgument] Only CPU devices are supported for now.

using (var memInfo = new OrtMemoryInfo(OrtMemoryInfo.allocatorCUDA, OrtAllocatorType.ArenaAllocator, 0, OrtMemType.Default))
using (var arenaCfg = new OrtArenaCfg(1024 * 1024 * 1024, 0, 512 * 1024 * 1024, 0))
{
      var env = OrtEnv.Instance();
      env.CreateAndRegisterAllocator(memInfo, arenaCfg);
 }
 

I would like to request for support for CUDA configuration in the onnxruntime library for C#. Alternatively, I would also like to request for a solution to clear the GPU memory after a model run without clearing the model itself.

Describe scenario use case

My scenario is that I need to use a lot of models on the GPU, and the memory is not enough. I want to clear the calculation cache after each model run, but for the overall time, I don't want to clear the model itself. I have already read - https://github.com/microsoft/onnxruntime/issues/9509#issuecomment-951546580 and - https://github.com/microsoft/onnxruntime/issues/13936; by upgrading to 1.14.0 I can already use runOp.AddRunConfigEntry("memory.enable_memory_arena_shrinkage", "gpu:0"), but now I cannot fully implement the functionality in C# due to the above feature not being supported.

It's also possible that my method is incorrect, so I sincerely request help. 😔🤞

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.

Research direction

Start with the C# APIs OrtEnv.CreateAndRegisterAllocator and RunOptions memory.enable_memory_arena_shrinkage, then read the guidance linked from issues 9509 and 13936. Done means establishing whether CUDA allocator configuration or post-run GPU memory clearing can be supported through C#, with the supported usage or limitation documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.