Skip to content

Add portable PTX export and verified modern LLVM cleanup - #4

Draft
brandonros wants to merge 58 commits into
experiment/cuda13.3-llvm21from
poc/portable-ptx-export
Draft

brandonros wants to merge 58 commits into
experiment/cuda13.3-llvm21from
poc/portable-ptx-export

Conversation

@brandonros

@brandonros brandonros commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Upstream review: Rust-GPU#409

Add a GPU-independent Rust-to-PTX exporter, restore default merged-module GlobalDCE on the modern backend, and expose optional verified cleanup pipelines with retention regressions and workload inspection tools. Include modern NVVM shuffle wrappers, guarded-select fixtures, and recorded optimization experiments.

This is the top of stack Rust-GPU#6, based on #3 (experiment/cuda13.3-llvm21). All 52 export commits were rebased intact apart from the DCE conflict resolution. A separate integration commit connects the exporter, cleanup gates, intrinsic assembly, scripts, and workflow caches to LLVM 21. The existing Llvm19Cleanup / llvm19_* experimental API names remain available for caller compatibility.

The checked-in LLVM 19 reports remain historical evidence. They have not been relabeled as LLVM 21 results. Fresh workflow runs are required to validate the combined backend and its generated PTX.

Validation:

  • All nine Python unit tests pass.
  • Offline Cargo metadata accepts ptx_export/llvm21.
  • Formatting checks pass for the touched Rust files; git diff --check passes.
  • git range-diff accounts for every original export commit; pre-rebase backup refs are retained locally.
  • Full Linux LLVM 21/CUDA compilation and GPU numerical validation were not run locally for this rebase.

@brandonros
brandonros added this pull request to stack #5 September 14, 2026 02:36
@brandonros
brandonros removed this pull request from stack #5 September 14, 2026 02:39
@brandonros brandonros closed this Sep 14, 2026
@brandonros brandonros reopened this Sep 14, 2026
@brandonros
brandonros added this pull request to stack #6 September 14, 2026 02:40
@brandonros brandonros changed the title poc/portable ptx export Add portable PTX export and verified modern LLVM cleanup Sep 14, 2026
@brandonros
brandonros force-pushed the poc/portable-ptx-export branch 2 times, most recently from 94b808a to 059beda Compare September 14, 2026 03:00
@brandonros
brandonros removed this pull request from stack #6 September 15, 2026 00:50
brandonros and others added 4 commits September 15, 2026 09:45
`core::intrinsics::{ctpop, ctlz, cttz, ctlz_nonzero, cttz_nonzero}` are
declared as returning `u32` for every operand width, while the LLVM
intrinsics they lower to return a value as wide as their operand.
`rustc_codegen_llvm` casts the result back; this backend did not.

The oversized value was then stored into the 4-byte result slot. For
`u64`/`u128` that store is out of bounds for the slot and is discarded, the
intrinsic call becomes dead, and the device silently computes `0` -- the
emitted PTX contains no `popc`/`clz` at all. For `u8`/`u16` the store is in
bounds, so the high bytes of the result are left uninitialized. Only width
32 was correct, because there the cast is a no-op.

Wrap the whole arm in a single `intcast` to the intrinsic's result layout
rather than casting in each of the five arms. Casting to an identical type
is a no-op, so the intrinsics in this arm that do return the operand width
(`bswap`, `bitreverse`, `rotate_*`, `saturating_*`) are unaffected, and any
intrinsic added here later is covered automatically.

Add `dis` compiletests pinning the emitted PTX for `u64::count_ones`
(`popc.b64`), `u64::leading_zeros` (`clz.b64`), and the emulated
`u128::count_ones` (two `popc.b64` plus the combining `add`). Before this
change all three kernels compiled down to a bare `ret`.

Also correct the 128-bit row in the feature table, which claimed the
bit-manipulation intrinsics were unsupported.

Fixes Rust-GPU#401

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 4aa57f2)
Separate configuration, flag generation, Cargo execution, backend loading, artifact parsing, and errors. Remove backend discovery and automatic builds, updating callers, CI, and documentation.

Use version-independent LLVM cleanup APIs and dialect-based intrinsic filenames. Add focused builder tests and improve failure diagnostics.
Restore CudaBuilder::new(kernels) with a Cargo-managed backend dependency and retain with_backend for external compilers. An internal proc macro identifies the linked backend library without exposing rustc_private to consumer build scripts or scanning directories.

Update examples, CI, documentation, and artifact provenance. Add backend identity tests covering cached builds, feature forwarding, release builds, and stale artifacts.
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.

2 participants