Skip to content

fix(cuda-host): accept CUDA-specific cubin ELF versions - #389

Closed
niklebedenko wants to merge 1 commit into
NVIDIA:mainfrom
niklebedenko:upstreaming/cubin-cache-validation
Closed

niklebedenko wants to merge 1 commit into
NVIDIA:mainfrom
niklebedenko:upstreaming/cubin-cache-validation

Conversation

@niklebedenko

@niklebedenko niklebedenko commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #388.

Summary

The cubin cache rejected genuine nvJitLink output because it treated generic
ELF EV_CURRENT as the only valid CUDA ELF version. This accepts CUDA's
non-zero version encodings while preserving the validator's structural and
content-integrity checks.

Before: valid cubins with observed CUDA versions such as 0x73 and 0x80
were rebuilt instead of cached. After: those cubins are cacheable, while zero
and malformed ELF inputs remain rejected.

What changed

CUDA ELF version validation

  • looks_like_cubin now accepts any non-zero e_version after identifying a
    64-bit, little-endian ET_EXEC file for EM_CUDA.
  • Generic version 1 remains valid, and zero remains an explicit invalid
    value.

Validation boundaries

  • ELF identity, class, byte order, CUDA machine, header size, extended-count
    rejection, table bounds, and file-backed segment/section bounds checks are
    unchanged.
  • Cache manifests and content digests remain independently verified.
  • The regression fails on unmodified upstream main specifically at the
    e_version = 0x80 assertion.

Known separate limitations

  • This is a structural cubin validator, not a substitute for driver-loading
    every cached artifact.
  • The change does not alter cache key construction, routing, locking, or
    eviction behavior.
  • Non-zero versions are accepted only after the existing CUDA ELF identity and
    bounds checks succeed.

Testing

  • cargo fmt --all -- --check
  • cargo test -p cuda-host cubin_validation -- --nocapture
  • cargo test -p cuda-host --all-targets (61 passed, 1 ignored; integration
    suites: 9 passed and 13 passed)
  • cargo clippy -p cuda-host --all-targets -- -D warnings
  • cargo test -p cuda-host ltoir::tests::live_file_cache_hits_and_source_changes_miss -- --exact --ignored --nocapture
  • Added coverage for versions 1, 0x73, and 0x80, explicit rejection of
    zero, and retained truncated-header and out-of-bounds-table assertions.
  • On upstream main, the focused regression failed at the expected
    cubin-validation assertion with e_version = 0x80; it passes on this branch.

Checklist

  • The branch is based on current upstream main.
  • The focused regression fails on upstream main and passes on this branch.
  • Corrupt and truncated cubins remain fail-closed.
  • Formatting, focused tests, all-target tests, clippy, and the live cache test pass.
  • Commits include DCO signoff and the patch is fork-neutral.

@niklebedenko
niklebedenko marked this pull request as draft July 12, 2026 23:41
@niklebedenko
niklebedenko marked this pull request as ready for review July 12, 2026 23:55
@nihalpasham nihalpasham added bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) on-hold Paused: valid but deferred until a prerequisite decision or dependency resolves perf Performance of generated code or of the compiler itself and removed bug Something isn't working labels Jul 22, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks @niklebedenko — caching correctness matters, but after a full forensic pass I can't accept this change, because the premise doesn't hold up:

  • Every real cubin we can produce or find carries ELF version 1: fresh nvcc 13.0/13.3 output for sm_75/sm_90/sm_100, all 49 cubins in this repo's tree, and the nvJitLink-produced entries this cache actually stores.
  • The reported 0x73/0x80 values look like a misread hexdump: in this repo's own merged.cubin, those exact bytes sit at e_shoff (0x7390) and e_phoff (0x8010), two rows below e_version in a hex view.
  • Current main also hard-gates every nvJitLink cubin link on this same validator (it moved to cuda-artifact-finalizer in feat(codegen): opt-in build-time cubin materialization for embedded artifacts #340). If real cubins carried other versions, every LTOIR example would fail loudly on every run. They don't.
  • Because of that move, the patch also no longer applies: it edits a copy of looks_like_cubin that main deleted from cuda-host.

Accepting any non-zero version would weaken a fail-closed corruption check to fix a bug we can't reproduce. If you have an actual cubin whose readelf -h shows Version != 0x1, please attach it along with the exact toolkit and command that produced it, and we'll gladly revisit. Closing this together with #388 for now.

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

Labels

build-related Build scripts, toolchain discovery, or compilation setup host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) on-hold Paused: valid but deferred until a prerequisite decision or dependency resolves perf Performance of generated code or of the compiler itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cubin cache rejects valid CUDA-specific ELF versions

2 participants