← Back to Pull requests

fix(cuda): call cuDeviceTotalMem_v2 to report memory above 4 GiB #2062

Closed
unknown closed this pull request without merging on Oct 01, 2026 14:59 UTC
View on GitHub
unknown unknown commented on Sep 24, 2026 17:24 UTC
Author

Description

On Tegra, NVML is unavailable, so device discovery resolves to the CUDA resource manager
and cudaDevice.GetTotalMemoryMiB() reads total memory through cuDeviceTotalMem.

internal/cuda/cuda.go hand-writes the prototype for that symbol rather than including
cuda.h, so the versioning macro (#define cuDeviceTotalMem cuDeviceTotalMem_v2) never
applies 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 at
UINT_MAX and GetTotalMemoryMiB() returns 4294967295 / 1048576 = 4095 on any device
with more than 4 GiB of memory.

The effect is that GPU Feature Discovery labels every Jetson nvidia.com/gpu.memory=4095
regardless 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/gpu extended resource is
unaffected — only the label is wrong. There is no configuration workaround:
--device-discovery-strategy=tegra resolves to the same CUDA manager, and a manual node
label is reverted by NFD.

This declares the versioned entry point explicitly. cuDeviceTotalMem_v2 has been the
current API since CUDA 3.2, so the minimum supported driver is unchanged. The other six
symbols declared in that file have no _v2 variant in libcuda, so this is the only one
affected.

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

  • No secrets, sensitive information, or unrelated changes

  • Lint checks passing (make lint)

  • Unit tests passing (make test)

  • Go mod artifacts in-sync (make check-modules)

  • Third-party notices in-sync (make check-third-party-notices)

  • Test cases are added for new code paths — see below
  • 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.1
    and a device with more than 4 GiB. internal/cuda is a thin cgo binding with no test
    harness and no current coverage, and cudaDevice is not reachable through the
    resource.Device mock in a way that would exercise the binding. Rather than add a test
    that 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-bot is waiting on a vetter — so I ran the repository's
    own targets locally (darwin/arm64, Go 1.26.4, golangci-lint v2.6.2):

    make fmt                        no diff
    make lint                       0 issues
    make test                       ok — all packages
    make check-modules              clean
    make check-third-party-notices  up to date
    

    make test-e2e was 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:

    $ nm -D /usr/lib/aarch64-linux-gnu/libcuda.so.1 | grep cuDeviceTotalMem
    0000000000300460 T cuDeviceTotalMem_v2
    000000000033fd90 T cuDeviceTotalMem
    

    import ctypes
    l = ctypes.CDLL("libcuda.so.1")
    l.cuInit(0)
    dev = ctypes.c_int(0)
    l.cuDeviceGet(ctypes.byref(dev), 0)
    for sym in ("cuDeviceTotalMem", "cuDeviceTotalMem_v2"):
        buf = ctypes.c_ulonglong(0)
        r = getattr(l, sym)(ctypes.byref(buf), dev)
        print(f"{sym}: ret={r} bytes={buf.value} MiB={buf.value // (1024 * 1024)}")
    

    cuDeviceTotalMem:    ret=0 bytes=4294967295   MiB=4095
    cuDeviceTotalMem_v2: ret=0 bytes=65932353536  MiB=62877
    

    To confirm the binding is what drives the label, I forced the unversioned name to resolve
    to cuDeviceTotalMem_v2 under the running gpu-feature-discovery pod — same image, same
    driver, one variable changed. The published label moved from nvidia.com/gpu.memory=4095
    to nvidia.com/gpu.memory=62877, matching _v2 exactly, and the full nvidia.com/* label
    set was captured before and after with nothing else changed.

    Diff: 567 lines (+425 / -142) across 7 files Reviewer: tariq1890 Review duration: 9935m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.7% (MEDIUM) · Higher = larger blast radius
    49.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.6% · Safe to merge
    19.6%