Skip to content

feat: add new CDI hook to set CUDA memory limits - #2075

Merged
tariq1890 merged 1 commit into
mainfrom
cuda-memory-limits-impl
Sep 14, 2026
Merged

tariq1890 merged 1 commit into
mainfrom
cuda-memory-limits-impl

Conversation

@tariq1890

@tariq1890 tariq1890 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

This commit introduces a new subcommand of the nvidia CDI hook called apply-cuda-memory-limits. The purpose of this CDI hook is to apply the desired memory limits to a GPU device.

It reads the following envars from a container spec to fetch the input parameters for the CDI hook

  • NVIDIA_GPU_MEMORY_REQUEST
  • NVIDIA_GPU_MEMORY_LIMIT

Under the covers, the CDI hooks invokes the new NVML SetMemoryLimits_v1 method (introduced in CUDA 13.4) to apply the desired CUDA memory limit values to the cgroup of the GPU container in question

@tariq1890
tariq1890 force-pushed the cuda-memory-limits-impl branch 2 times, most recently from e74a378 to 33c5844 Compare September 10, 2026 23:56
@coveralls

coveralls commented Sep 10, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 34788198846

Coverage decreased (-0.2%) to 43.787%

Details

  • Coverage decreased (-0.2%) from the base build.
  • Patch coverage: 124 uncovered changes across 6 files (39 of 163 lines covered, 23.93%).
  • 4 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
cmd/nvidia-cdi-hook/apply-cuda-memory-limits/apply-cuda-memory-limits.go 117 8 6.84%
internal/discover/hooks.go 5 0 0.0%
internal/info/cgroup/cgroup_path.go 16 11 68.75%
pkg/nvcdi/cuda-memory-limits.go 19 17 89.47%
pkg/nvcdi/full-gpu-nvml.go 5 3 60.0%
cmd/nvidia-cdi-hook/commands/commands.go 1 0 0.0%

Coverage Regressions

4 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
cmd/nvidia-cdi-hook/create-symlinks/container-root_linux.go 4 51.72%

Coverage Stats

Coverage Status
Relevant Lines: 13680
Covered Lines: 5990
Line Coverage: 43.79%
Coverage Strength: 0.44 hits per line

💛 - Coveralls

@tariq1890
tariq1890 force-pushed the cuda-memory-limits-impl branch 2 times, most recently from 18696a4 to fcca9a9 Compare September 11, 2026 03:40
Comment thread cmd/nvidia-cdi-hook/apply-cuda-memory-limits/apply-cuda-memory-limits.go Outdated
Comment thread cmd/nvidia-ctk/cdi/generate/generate_test.go
Comment thread internal/info/cgroup/cgroup_path.go Outdated
Comment thread cmd/nvidia-cdi-hook/apply-cuda-memory-limits/apply-cuda-memory-limits.go Outdated
Comment thread internal/info/cgroup/cgroup_path.go Outdated
@tariq1890 tariq1890 self-assigned this Sep 11, 2026
@tariq1890
tariq1890 force-pushed the cuda-memory-limits-impl branch 4 times, most recently from 465ea21 to d07ebd9 Compare September 12, 2026 00:09
Comment thread cmd/nvidia-cdi-hook/apply-cuda-memory-limits/apply-cuda-memory-limits.go Outdated
@tariq1890
tariq1890 force-pushed the cuda-memory-limits-impl branch 4 times, most recently from 8c66f16 to 567826e Compare September 12, 2026 00:42
Comment thread cmd/nvidia-cdi-hook/apply-cuda-memory-limits/apply-cuda-memory-limits.go Outdated
Comment on lines +124 to +126
if !hasRequest && !hasLimit {
return nil
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdesiniotis this logic has been updated since the last approve. In the latest iteration, setting both the request and limits are no longer mandatory; either one env var being set is enough for the the CDI hook to call the NVML Memory Limits API.

The new behaviour is as follows

i) If both env vars are set, it continues to work as before
ii) If only the request env var is set, the limit is set to the max-possible uint64 values
iii) If only the limit env var is set, then the request is set to the same value as the limit.

Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>

get cgroup path from procfs instead

Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>
@tariq1890
tariq1890 force-pushed the cuda-memory-limits-impl branch from 544986e to 2d76167 Compare September 14, 2026 16:45
@cdesiniotis

Copy link
Copy Markdown
Contributor

/cherry-pick release-1.20

@tariq1890
tariq1890 enabled auto-merge September 14, 2026 17:13
@tariq1890
tariq1890 merged commit 99a0508 into main Sep 14, 2026
21 checks passed
@tariq1890
tariq1890 deleted the cuda-memory-limits-impl branch September 14, 2026 17:17
@github-actions

Copy link
Copy Markdown

🤖 Backport PR created for release-1.20: #2091 ⚠️ (has conflicts)

@tariq1890

Copy link
Copy Markdown
Contributor Author

/cherry-pick release-1.20

@github-actions

Copy link
Copy Markdown

🤖 Backport PR created for release-1.20: #2093 ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants