Skip to content

add new CDI hook to set CUDA memory limits [DO-NOT-MERGE] - #1995

Draft
tariq1890 wants to merge 1 commit into
mainfrom
cuda-memory-limits
Draft

add new CDI hook to set CUDA memory limits [DO-NOT-MERGE]#1995
tariq1890 wants to merge 1 commit into
mainfrom
cuda-memory-limits

Conversation

@tariq1890

@tariq1890 tariq1890 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This commit introduces a new CDI hook binary 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(S)
  • NVIDIA_GPU_MEMORY_LIMIT(S)

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 branch 2 times, most recently from 6a201cf to 39d3e0f Compare August 13, 2026 23:04
@tariq1890 tariq1890 changed the title add new CDI hook to set CUDA memory limits hook add new CDI hook to set CUDA memory limits hook [DO-NOT-MERGE] Aug 13, 2026
@coveralls

coveralls commented Aug 14, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 31854831036

Coverage decreased (-0.4%) to 43.194%

Details

  • Coverage decreased (-0.4%) from the base build.
  • Patch coverage: 187 uncovered changes across 6 files (27 of 214 lines covered, 12.62%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
cmd/nvidia-cdi-hook/apply-cuda-memory-limits/apply-cuda-memory-limits.go 103 0 0.0%
internal/info/cgroup/cgroup_path.go 72 0 0.0%
internal/discover/hooks.go 8 1 12.5%
pkg/nvcdi/cuda-memory-limits.go 25 23 92.0%
pkg/nvcdi/full-gpu-nvml.go 5 3 60.0%
cmd/nvidia-cdi-hook/commands/commands.go 1 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15479
Covered Lines: 6686
Line Coverage: 43.19%
Coverage Strength: 0.48 hits per line

💛 - Coveralls

@tariq1890 tariq1890 self-assigned this Aug 14, 2026
@tariq1890
tariq1890 force-pushed the cuda-memory-limits branch 6 times, most recently from 363243d to 4361243 Compare August 14, 2026 00:45
@tariq1890 tariq1890 changed the title add new CDI hook to set CUDA memory limits hook [DO-NOT-MERGE] add new CDI hook to set CUDA memory limits [DO-NOT-MERGE] Aug 14, 2026
@tariq1890
tariq1890 force-pushed the cuda-memory-limits branch 3 times, most recently from 3265fc2 to b0fcb92 Compare August 15, 2026 00:49
Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>
@@ -0,0 +1,185 @@
/**
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: remove the year from the copyright header

&cli.StringFlag{
Name: "driver-root",
Usage: "Specify the driver root",
Destination: &cfg.driverRoot,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question -- do we need to define a default value for this field, or validate that it is specified in validateFlags()?

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.

Good question. What would you suggest here?

Comment on lines +116 to +118
if !ok1 || !ok2 {
return nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question -- does this mean that it is invalid to only specify one of these envvars (but not the other)?

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.

I am open to changing this. We can just limit it to 2 out of the 4 env vars here (maybe drop the plurals?) for the sake of simplicity here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My question was more so out of curiosity. Is it valid to only specify a memory limit and not a request?

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.

Yes, I believe it is. If unspecified, the value stays the same as it was

@@ -0,0 +1,137 @@
/**
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: let's remove the year from the copyright header

myCgroupPath := spec.Linux.CgroupsPath
parts := strings.Split(myCgroupPath, ":")
if len(parts) != 3 {
return "", fmt.Errorf("expected cgroupsPath to be of format \"slice:prefix:name\" for systemd cgroups, got %q instead", myCgroupPath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question -- does this only work when systemd is managing cgroups? What about cgroupfs?

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.

Yes, this PR only supports systemd as the cgroup manager in its current state. I think cgroupfs needs to be supported too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add some unit tests for this file.

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.

will do

deviceNodes,
)

cudaMemoryLimitsHook, err := (*nvcdilib)(l.nvmllib).newCudaMemoryLimits(d)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious, is the NVML API for setting memory limits only supported on full GPUs? What about MIG devices?

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.

I will need to find out

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants