Repository navigation
Conversation
`#[constant]` statics are written by the host after module load
(cuModuleGetGlobal + copy), but were lowered to an ordinary zero-initialized
addrspace(4) global that was neither rooted nor marked as externally
initialized. The PTX route survived because its own internalize step keeps
every defined global public. The materialized-cubin route (libNVVM -gen-lto,
nvJitLink -lto) is whole-program LTO: it internalized the never-stored
global, folded its loads to the zero initializer and dropped the symbol, so
the host lookup failed with CUDA_ERROR_NOT_FOUND ("named symbol not found")
and the kernels computed with zeros.
create_device_global now marks constant-memory globals retained (@llvm.used,
for constants no kernel reads) and host-written; the exporter renders
host-written globals `externally_initialized`, as clang does for CUDA
__constant__ variables. Ordinary device globals are unchanged.
Signed-off-by: Alex Khal <joss13@gmail.com>
Signed-off-by: ssoj13 <96214515+ssoj13@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Host writes to
#[constant]memory must remain observable after libNVVM/nvJitLink LTO. Mark these globals retained andexternally_initialized, so optimization cannot fold their loads to the zero initializer or drop the symbol used bycuModuleGetGlobal.Fixes #1507.
Port of ansidium/cuda-rust-windows#10, independently rebased onto NVIDIA main
bc46b1ffb. Private device globals are unchanged. Tests cover both modern and legacy LLVM IR and distinguish host-written constant globals from private allocations.Verified on the pinned nightly-2026-10-11, Linux/WSL2, CUDA 13.3 and RTX 3080 Ti:
cargo test --locked -p llvm-export -p mir-lowerpasses.-D warnings, formatting and SPDX checks pass.constant_memory --materialize-cubin --arch sm_86: both 256-element launches match their respective coefficients, including rewriting the constant between launches.The original change was authored by Alex Khal with Claude Code. This transplant and current verification were prepared with Codex; original attribution and DCO are preserved.