Adding a kernel renames other kernels' shared-memory statics, so their PTX changes
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 43/100
Research direction
Start by reading mir-lower/src/lib.rs, especially next_shared_mem_index, then trace how SharedArray statics get their PTX symbols. Reproduce the two-kernel and three-kernel examples and compare the emitted PTX names. Done when adding, removing, or reordering an unrelated kernel leaves existing kernels’ shared-memory symbols and PTX unchanged.
Written by the indexing model from the issue text.
Description
What problem does this solve?
Adding a kernel renames the shared-memory statics of every other kernel in the crate, so their PTX changes even though their code didn't.
On main (bafffe45), a SharedArray static becomes __shared_mem_<hash>_<n>. The <hash> changes whenever the crate gains a kernel. The index <n> comes from a per-module counter (next_shared_mem_index in mir-lower/src/lib.rs), assigned in MIR walk order, which is neither declaration order nor alphabetical.
Minimal repro: two kernels, c4_a and c4_b, each with one static. Then the same crate with a third kernel c4_new declared first:
#[kernel]
pub fn c4_a(out: *mut f32) {
static mut TILE: SharedArray<f32, 128, 16> = SharedArray::UNINIT;
let tile = unsafe { SharedArray::as_raw_mut_ptr(&raw mut TILE) };
let tid = thread::threadIdx_x() as usize;
unsafe { *tile.add(tid & 127) = tid as f32 };
thread::sync_threads();
unsafe { *out.add(tid) = *tile.add((tid + 1) & 127) };
}
// c4_b: the same with SharedArray<f32, 256, 16>; c4_new: the same with SharedArray<f32, 64, 16>
two kernels: __shared_mem_31951401fd83021e_0[512] (c4_a) _1[1024] (c4_b)
c4_new first: __shared_mem_a0cee6ee76594339_0[512] (c4_a) _1[256] (c4_new) _2[1024] (c4_b)
c4_new in a submodule declared last:
__shared_mem_e66d4dd7193f23e0_0[512] (c4_a) _1[1024] (c4_b) _2[256] (c4_new)
Built with cargo +nightly-2026-08-28 oxide build for sm_80 and assembled with ptxas 13.0.88. The PTX bodies of c4_a and c4_b differ only in these names, and their SASS is identical.
Why it matters
speakrs commits its PTX and per-architecture cubins and checks their hashes in CI (see #1464). When we added spk_lstm_recurrence_resident (https://github.com/avencera/speakrs/pull/61), the two existing recurrence kernels' PTX changed only in these names, and every cubin hash in the module changed with them. To confirm the existing kernels were unchanged, we had to diff the PTX with the names normalized. #711 and #1289 made the names reproducible and crate-scoped, but adding a kernel still renames them.
Proposed behavior
Derive the symbol from the static's own identity, such as its def path or the enclosing kernel plus the static's name, not from a crate-wide hash and walk-order counter. Then adding, removing or reordering an unrelated kernel leaves the other kernels' PTX and cubins byte-identical.
Alternatives considered
We normalize the names before diffing, which is what we do now. That works for review, but the cubin hashes still change, along with everything keyed on them.
- Dominant language
- Rust
- Stars
- 3.8k
- Forks
- 325
- Avg merge
- 5d 21h
- Merged PRs (30d)
- 67
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/cuda-rust
-
cutile-rs supply-chain
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NVIDIA/cuda-rust#1568 · 1 comment ·
Maintainers usually reply within 2 days
-
[BUG]: The doc of trait `LoadTileLike` is incorrectMay be free again @akhil9tiet claimed this 10 days ago, and no pull request is open. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
NVIDIA/cuda-rust#1523 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
All issues in NVIDIA/cuda-rust
Similar issues
-
bug priority: P3 ready-for-agent
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
shep-pm/shep-kelpie#1332 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ramensoftware/windhawk#1156 · 2 comments ·
-
units: No `#` in rustdoc headingPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 67/100
rust-bitcoin/rust-bitcoin#7089 · 1 comment · 1 reaction ·
Maintainers usually reply within 2 days
-
phase:3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pchrysostomou/ananke#183 ·
Maintainers usually reply within 1 day
-
area/tools bug session-analysis
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day