Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Array parameters lose alignment metadata and ICE on >16 byte alignments

オープン
#387 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
rust
領域
compilers

調査の方向性

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:

  1. Lost Alignment Metadata (IllegalAddress traps): If you pass an array of 16-byte aligned elements (like [u128; 4] or [AlignedStruct; 2]), the compiler forces it to PassMode::Direct and 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 an IllegalAddress error.
  2. Internal Compiler Error (ICE) for >16-byte alignments: Because arrays bypass the 16-byte PassMode::Cast workaround 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 はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Rust-GPU/rust-cuda のほかの issue

Rust-GPU/rust-cuda の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。