Skip to content

fix(nvvm): use PassMode::Cast for align(16) ADTs#362

Merged
LegNeato merged 1 commit intoRust-GPU:mainfrom
Snehal-Reddy:fix/nvvm-align-16
Feb 26, 2026
Merged

fix(nvvm): use PassMode::Cast for align(16) ADTs#362
LegNeato merged 1 commit intoRust-GPU:mainfrom
Snehal-Reddy:fix/nvvm-align-16

Conversation

@Snehal-Reddy
Copy link
Contributor

The NVVM backend was defaulting to PassMode::Direct for all ADTs. On NVPTX, LLVM often aligns generic aggregate types to 8 bytes, even if the Rust type requires 16-byte alignment. This caused the kernel to read arguments from incorrect offsets, leading to crashes.

The Fix:

  1. High Alignment (>= 16): For structs requiring 16+ byte alignment, force
    PassMode::Cast using i128 units. This compels LLVM to emit .param .align 16 (or
    .b128) in PTX, guaranteeing the correct ABI contract.
  2. Standard Alignment: For other ADTs, explicitly set attrs.pointee_align when using
    PassMode::Direct to ensure LLVM respects the type's alignment attribute.

Fixes #361

@LegNeato
Copy link
Contributor

I'm not really qualified to review this as I am shaky on the LLVM side, but let's land it and see how it goes. Thank you!

@LegNeato LegNeato added this pull request to the merge queue Feb 26, 2026
Merged via the queue into Rust-GPU:main with commit 2479a9c Feb 26, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel arguments with #[repr(align(16))] cause misaligned access / IllegalAddress

2 participants