Array parameters lose alignment metadata and ICE on >16 byte alignments
还没有人认领这个 Issue。
评估
调研方向
从 crates/rustc_codegen_nvvm/src/abi.rs 开始,阅读 readjust_fn_abi,并将数组处理与 ADT 回退分支进行比较。使用所提供的对齐数组内核复现该问题,包括 16 字节和 32 字节对齐的情况,然后验证生成的 PTX 保留所需的对齐方式,并确认更高对齐的情况不再触发报告的 ICE。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Rust
- 星标
- 5.4k
- 派生
- 249
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Rust-GPU/rust-cuda 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 1/5 1 小时以内 新手友好度 88/100
-
Default NvvmArch::Compute75 silently produces InvalidPtx on pre-Turing GPUs (Pascal/Maxwell/Volta) 未关闭
难度 4/5 3-5 天 新手友好度 48/100
-
难度 5/5 一周以上 新手友好度 30/100
-
难度 4/5 3-5 天 新手友好度 55/100
查看 Rust-GPU/rust-cuda 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
-
bug core
难度 2/5 1-3 小时 新手友好度 86/100
-
JIT-compiled number -> Decimal conversion silently overflows instead of raising DECIMAL_OVERFLOW 未关闭fuzz
难度 2/5 1-3 小时 新手友好度 82/100
ClickHouse/ClickHouse#122114 ·
-
难度 1/5 1 小时以内 新手友好度 92/100
linebender/vello_svg#90 ·
-
难度 2/5 1-3 小时 新手友好度 74/100