Array parameters lose alignment metadata and ICE on >16 byte alignments
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia in crates/rustc_codegen_nvvm/src/abi.rs, leggi readjust_fn_abi e confronta la gestione degli array con il ramo di fallback di ADT. Riproduci il problema con i kernel di array allineati forniti, inclusi i casi di allineamento a 16 byte e 32 byte, quindi verifica che il PTX generato preservi l'allineamento richiesto e che il caso con allineamento maggiore non attivi più l'ICE segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
There is a bug in rustc_codegen_nvvm/src/abi.rs where arrays passed by value to CUDA kernels discard their underlying alignment metadata, forcing them into PassMode::Direct(ArgAttributes::new()).
This presents two distinct issues:
- Lost Alignment Metadata (
IllegalAddresstraps): If you pass an array of 16-byte aligned elements (like[u128; 4]or[AlignedStruct; 2]), the compiler forces it toPassMode::Directand generates PTX expecting 8-byte boundaries (e.g.,.param .align 8 .b8 param_0[32]). However, the Host driver packs the array at a 16-byte boundary. If the kernel subsequently attempts an aligned/vectorized 128-bit load, it can trap with anIllegalAddresserror. - Internal Compiler Error (ICE) for >16-byte alignments: Because arrays bypass the 16-byte
PassMode::Castworkaround that is correctly applied to ADTs, passing an array requiring 32-byte or greater alignment (e.g.,[AlignedStruct32; 2]) triggers an ICE in the upstream NVPTX ABI handling:internal error: entered unreachable code: Align is given as power of 2 no larger than 16 bytes.
Reproduction Case
Define an aligned struct and pass an array of them to a kernel:
#[derive(Copy, Clone)]
#[repr(C, align(16))]
pub struct AlignedStruct {
a: u64,
b: u64,
}
#[cuda_std::kernel]
pub unsafe fn array_kernel2(arr: [AlignedStruct; 2], out: *mut u128) {
// PTX generates: .param .align 8 .b8 array_kernel2_param_0[32]
// The missing 16-byte alignment metadata leads to an ABI mismatch
// between the host and device.
unsafe {
*out = arr[0].a as u128 + arr[1].a as u128;
}
}
If the struct is changed to #[repr(C, align(32))], compiling the kernel causes the compiler to panic with internal error: entered unreachable code: Align is given as power of 2 no larger than 16 bytes.
Issue Details
In crates/rustc_codegen_nvvm/src/abi.rs, the function readjust_fn_abi handles arrays blindly without preserving or checking arg.layout.align.abi:
// Current array handling in abi.rs
if arg.layout.ty.is_array() && !matches!(arg.mode, PassMode::Direct { .. }) {
arg.mode = PassMode::Direct(ArgAttributes::new());
}
Unlike the ADT fallback branch (attrs.pointee_align = Some(arg.layout.align.abi)), the array block throws away all alignment metadata. It also completely misses the PassMode::Cast workaround needed for types with align >= 16.
- Lingua principale
- Rust
- Stelle
- 5.4k
- Fork
- 249
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Rust-GPU/rust-cuda
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Default NvvmArch::Compute75 silently produces InvalidPtx on pre-Turing GPUs (Pascal/Maxwell/Volta) Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
Tutte le issue di Rust-GPU/rust-cuda
Issue simili
-
bug github_actions
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
registrystack/registry-stack#1393 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
longbridge/gpui-kit#3223 ·
-
bug engine
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rocky-data/rocky#2181 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
oasisprotocol/oasis-sdk#2523 ·
-
[indexer] [QA] Add a focused test for the new NonRetryableError / assertSocketAlive() behavior. Apertabot:ai-assisted component:indexer QA-roadmap status:untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
midnightntwrk/midnight-indexer#1557 ·