Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Copy link
Contributor

Snehal-Reddy commented Feb 10, 2026

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

Copy link
Contributor

LegNeato commented Feb 26, 2026

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 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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

2 participants