NVIDIA / NVIDIA/TensorRT

TensorRT uses a large amount of virtual cpu memory after calling createExecutionContext

Open
#4,684 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module:Runtime
Dominant language
C++
Stars
13.4k
Forks
2.4k
Avg merge
5d 3h
Merged PRs (30d)
2

Description

Description

On Windows, TensorRT reports a GPU out-of-memory error when 12 models are loaded(16G free memory of gpu ). Further investigation shows that TensorRT execution contexts consume a large amount of system virtual memory, which eventually becomes exhausted and triggers the error. I found that any model consumes a large amount of virtual memory. why ?

Environment

TensorRT Version: 8.6 or 10.x

NVIDIA GPU: all

NVIDIA Driver Version:

CUDA Version: cuda12.8

CUDNN Version: None

Operating System:

Python Version (if applicable):

Tensorflow Version (if applicable):

PyTorch Version (if applicable):

Baremetal or Container (if so, version):

Relevant Files

Model : same onnx

Steps To Reproduce

Commands or scripts:

auto GetCurrentProcessCommitBytes = []() {
  PROCESS_MEMORY_COUNTERS_EX pmc{};
  if (!GetProcessMemoryInfo(GetCurrentProcess(),
                            reinterpret_cast<PROCESS_MEMORY_COUNTERS *>(&pmc),
                            sizeof(pmc))) {
    return 0;
  }

  // Commit Bytes = PrivateUsage
  auto bytes = static_cast<uint64_t>(pmc.PrivateUsage);
  SPDLOG_INFO(" ----------------- commit memory ----------------- {}  GB",
              bytes / (1024 * 1024 * 1024));
  return bytes;
}
  
  std::unique_ptr<nvinfer1::ICudaEngine> engine_;
  std::unique_ptr<nvinfer1::IExecutionContext> context_;
  ........................ 
  context_.reset(engine_->createExecutionContext());
  GetCurrentProcessCommitBytes();

result :
[2026-01-21 16:30:44.209] [info] [trt_onnx_engine.cpp:50] ----------------- commit memory ----------------- 4 GB

and

  ........................ 
  context_.reset(engine_->createExecutionContext());
  GetCurrentProcessCommitBytes();
  context_.reset(engine_->createExecutionContext(
      nvinfer1::ExecutionContextAllocationStrategy::kUSER_MANAGED));
  auto size = context_->updateDeviceMemorySizeForShapes();
  cudaMalloc((void **)&buffer_, size);
  context_->setDeviceMemoryV2(buffer_, static_cast<int64_t>(size));
  GetCurrentProcessCommitBytes();
 

result :
[2026-01-21 16:30:44.209] [info] [trt_onnx_engine.cpp:50] ----------------- commit memory ----------------- 0 GB
[2026-01-21 16:30:44.209] [info] [trt_onnx_engine.cpp:50] ----------------- commit memory ----------------- 4 GB

Have you tried the latest release?:

Attach the captured .json and .bin files from TensorRT's API Capture tool if you're on an x86_64 Unix system

Can this model run on other frameworks? For example run ONNX model with ONNXRuntime (polygraphy run <model.onnx> --onnxrt):

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 reproduction around createExecutionContext and the memory measurement reported at trt_onnx_engine.cpp:50. Compare the default context with kUSER_MANAGED, including updateDeviceMemorySizeForShapes and setDeviceMemoryV2, while collecting the missing driver, model, and complete environment details. Done means identifying whether the virtual-memory behavior is expected or reproducible as a TensorRT bug.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.