fix(cuda): call cuDeviceTotalMem_v2 to report memory above 4 GiB #2062
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 567 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.379
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2062"
general
weight: 0.35
tariq1890
Description
On Tegra, NVML is unavailable, so device discovery resolves to the CUDA resource manager
and
cudaDevice.GetTotalMemoryMiB()reads total memory throughcuDeviceTotalMem.internal/cuda/cuda.gohand-writes the prototype for that symbol rather than includingcuda.h, so the versioning macro (#define cuDeviceTotalMem cuDeviceTotalMem_v2) neverapplies and cgo binds the unversioned entry point. The unversioned symbol libcuda exports
is the pre-CUDA-3.2 API that writes an
unsigned int, so the value saturates atUINT_MAXandGetTotalMemoryMiB()returns4294967295 / 1048576 = 4095on any devicewith more than 4 GiB of memory.
The effect is that GPU Feature Discovery labels every Jetson
nvidia.com/gpu.memory=4095regardless of the board, so anything that sizes or admits workloads by that label treats a
64 GiB Orin as a 4 GiB GPU. Scheduling through the
nvidia.com/gpuextended resource isunaffected — only the label is wrong. There is no configuration workaround:
--device-discovery-strategy=tegraresolves to the same CUDA manager, and a manual nodelabel is reverted by NFD.
This declares the versioned entry point explicitly.
cuDeviceTotalMem_v2has been thecurrent API since CUDA 3.2, so the minimum supported driver is unchanged. The other six
symbols declared in that file have no
_v2variant in libcuda, so this is the only oneaffected.
The defect predates this repository: the two lines changed here arrived verbatim in
NVIDIA/gpu-feature-discovery@cc205a87 ("Add basic CUDA wrapper to generate Tegra labels",
2022-08) and were copied over in b9fe486d. It is plausibly invisible on the smaller Jetsons
— a Jetson Nano reports 3963 MiB, below the saturation point. It also survived
3f0378dc ("Address integer overflow linting errors"), which edited this package: a Go-side
overflow audit cannot see a truncation that happens on the C side of the boundary.
Closes #2061
Checklist
make lint)make test)make check-modules)make check-third-party-notices)On the last box: I could not write a regression test that fails without this fix.
The defect is in which C symbol cgo binds, so reproducing it needs a real
libcuda.so.1and a device with more than 4 GiB.
internal/cudais a thin cgo binding with no testharness and no current coverage, and
cudaDeviceis not reachable through theresource.Devicemock in a way that would exercise the binding. Rather than add a testthat passes either way, I verified against real hardware — below. Happy to add one if you
can point at a pattern you would accept.
Testing
CI has not run on this PR —
copy-pr-botis waiting on a vetter — so I ran the repository'sown targets locally (darwin/arm64, Go 1.26.4, golangci-lint v2.6.2):
make test-e2ewas not run; no GPU cluster available here.Verified on real hardware: Jetson AGX Orin Developer Kit, JetPack 7 / L4T R39.2.1, CUDA
driver 13.2, 61.4 GiB unified memory, k3s v1.36.3, GFD v0.18.2.
Both symbols are exported by the driver, and they disagree:
To confirm the binding is what drives the label, I forced the unversioned name to resolve
to
cuDeviceTotalMem_v2under the running gpu-feature-discovery pod — same image, samedriver, one variable changed. The published label moved from
nvidia.com/gpu.memory=4095to
nvidia.com/gpu.memory=62877, matching_v2exactly, and the fullnvidia.com/*labelset was captured before and after with nothing else changed.