Skip to content

feat: add ldmatrix warp-level shared memory matrix loads - #311

Merged
nihalpasham merged 4 commits into
NVIDIA:mainfrom
honeyspoon:add-ldmatrix-v2
Jul 1, 2026
Merged

nihalpasham merged 4 commits into
NVIDIA:mainfrom
honeyspoon:add-ldmatrix-v2

Conversation

@honeyspoon

Copy link
Copy Markdown
Contributor

Summary

Add all 6 ldmatrix variants across all four compiler layers
(cuda-device, dialect-nvvm, mir-importer, mir-lower):

  • ldmatrix_x1 / ldmatrix_x1_trans: load 1 tile, returns u32
  • ldmatrix_x2 / ldmatrix_x2_trans: load 2 tiles, returns [u32; 2]
  • ldmatrix_x4 / ldmatrix_x4_trans: load 4 tiles, returns [u32; 4]

These are the warp-cooperative building blocks for loading matrix
fragments from shared memory in the layout expected by mma.sync
tensor core instructions.

Design notes:

  • x1 variants use the standard scalar-return pattern (1 operand, 1 result)
  • x2/x4 variants use the alloca-slot pattern (same as stmatrix): the
    importer passes the destination slot pointer as an operand, and the
    lowered inline PTX writes results directly to the slot via st.b32
  • All variants emit convergent inline assembly with cvta.to.shared
    pointer conversion (shared memory 32-bit addressing)

Ref #274 (Phase 2: Matrix operations)

Test plan

  • 5 new lowering tests covering x1, x1_trans, x2, x4, x4_trans
  • cargo clippy -- -D warnings clean across all 4 crates
  • cargo fmt --check clean
  • All existing tests pass (32 integration + 80 unit in mir-lower)

@honeyspoon
honeyspoon force-pushed the add-ldmatrix-v2 branch 4 times, most recently from 5929c5d to d9a0ebc Compare June 30, 2026 04:14
@nihalpasham nihalpasham added enhancement New feature or request miscompile Produces incorrect PTX/IR (wrong generated code) perf Performance of generated code or of the compiler itself intrinsics Device intrinsics and libdevice math mappings codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) tests Adds or improves test coverage Depends Blocked on another PR/issue or an upstream dependency labels Jul 1, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR. LGTM.

I confirmed that all six ldmatrix forms now assemble at the true sm_75 / PTX 6.5 floor.

A couple of points:

  • I changed x2/x4 to return register tuples directly, modeled every load as a convergent shared-memory read, and completed the target and lane-address rules.
  • Since we are here, also fixed stmatrix x4-transpose, its packed-register contract, its sm_90 / PTX 7.8 target selection, and related target and cluster-register detection.

Reviewer note: This work partially addresses #274, which remains open. Runtime fragment values and performance were not tested on a GPU.

@nihalpasham
nihalpasham merged commit 72956e6 into NVIDIA:main Jul 1, 2026
28 checks passed
@honeyspoon
honeyspoon deleted the add-ldmatrix-v2 branch July 23, 2026 13:53
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
)

Type inference rewrites a free-function call to a trait-dispatch wrapper
(`load_tile_like(x, out)`) into the method call `x.load_tile_like(out)`
before the inline compiler runs. The rewritten expression mixed tokens from
two source texts (the user's receiver and arguments, the wrapper body's
method name and parentheses) and a defaulted dot token, so `Spanned::span()`
degraded to `Span::call_site()`, which the span base resolves to the
module's first line. Every op of the inlined dispatch body was attributed
to `mod ... {` instead of the call: no line-table rows for the call line,
so a cuda-gdb breakpoint there slid to the next statement with code.

The synthesized tokens now carry the user's call span, and the node-id
marker attribute (the expression's first token) is anchored at the
replaced call's span instead of the mixed expression's span. Unit test on
the lowering and an end-to-end test on the compiled module's `load_view_tko`
location (fails on main with `[module line]`).

Found via Dmitry's debug_kernels report; the remaining misattributed lines
in his trace (67-74 on the assert failure path) come from the assembler's
assert lowering, not from our debug section; see the internal note.

Signed-off-by: Melih Elibol <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) Depends Blocked on another PR/issue or an upstream dependency enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) miscompile Produces incorrect PTX/IR (wrong generated code) perf Performance of generated code or of the compiler itself tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants