Array parameters lose alignment metadata and ICE on >16 byte alignments
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu trong crates/rustc_codegen_nvvm/src/abi.rs, đọc readjust_fn_abi và so sánh cách xử lý mảng với nhánh fallback của ADT. Tái hiện vấn đề bằng các kernel mảng được căn chỉnh đã cung cấp, bao gồm các trường hợp căn chỉnh 16 byte và 32 byte, sau đó xác minh rằng PTX được tạo ra vẫn giữ nguyên căn chỉnh cần thiết và trường hợp căn chỉnh cao hơn không còn kích hoạt ICE đã được báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 5.4k
- Fork
- 251
- Merge trung bình
- 4 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Rust-GPU/rust-cuda
-
Default NvvmArch::Compute75 silently produces InvalidPtx on pre-Turing GPUs (Pascal/Maxwell/Volta)Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
-
Support llvm-19 in containersĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của Rust-GPU/rust-cuda
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
objectionary/sodg.rs#301 ·
-
[Bug] Completion info popup (.cm-completionInfo) ignores the configured editor fontCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug user-priority/P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
t8y2/dbx#11718 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
rescript-lang/rescript#8765 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
nautechsystems/nautilus_trader#5287 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
farion1231/cc-switch#8072 ·
Maintainer thường phản hồi trong vòng 1 ngày