Skip to content

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

Open
Snehal-Reddy wants to merge 1 commit intoRust-GPU:mainfrom
Snehal-Reddy:fix/nvvm-align-16
Open

fix(nvvm): use PassMode::Cast for align(16) ADTs#362
Snehal-Reddy wants to merge 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

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

1 participant