Skip to content

Add prmt.b32 byte permute intrinsic#333

Open
honeyspoon wants to merge 1 commit into
NVlabs:mainfrom
honeyspoon:upstream/add-prmt
Open

Add prmt.b32 byte permute intrinsic#333
honeyspoon wants to merge 1 commit into
NVlabs:mainfrom
honeyspoon:upstream/add-prmt

Conversation

@honeyspoon

Copy link
Copy Markdown
Contributor

Summary

Adds the PTX prmt.b32 byte-permute instruction across all four compiler layers (cuda-device, dialect-nvvm, mir-importer, mir-lower).

prmt.b32 %d, %a, %b, %c;

The prmt instruction selects and rearranges four bytes from two 32-bit source registers according to a control mask, producing a single 32-bit result. Each 4-bit nibble of the control value indexes one of the eight source bytes (four from each operand). This is the foundation for efficient byte manipulation in quantization, dequantization, and format conversion kernels.

Available on all SM architectures (no minimum floor).

Part of tracking issue #274 (Phase 4).

What changed

  • cuda-device: Added prmt module with prmt_b32 user-facing stub.
  • dialect-nvvm: Added PrmtOp operation with verifier tests (3 operands, 1 result, register-only).
  • mir-importer: Added dispatch table entry and prmt intrinsic emitter module.
  • mir-lower: Added lowering conversion using inline asm with =r,r,r,r constraints.
  • Lowering test for the prmt.b32 instruction.

Testing

  • cargo fmt --check clean
  • cargo test -p dialect-nvvm --all-targets — verifier tests pass
  • cargo test -p mir-lower --all-targets — lowering tests pass
  • cargo oxide run e2e on GPU

Checklist

  • Signed-off-by DCO trailer
  • No crates/cuda-bindings/ changes
  • SPDX headers on new source files

Adds the PTX `prmt.b32` byte-permute instruction across all four
compiler layers (cuda-device, dialect-nvvm, mir-importer, mir-lower).

The `prmt` instruction selects and rearranges four bytes from two
32-bit source registers according to a control mask, producing a
single 32-bit result. This is the foundation for efficient byte
manipulation in quantization, dequantization, and format conversion
kernels.

```ptx
prmt.b32 %d, %a, %b, %c;
```

Includes dialect-nvvm verifier tests and mir-lower lowering tests.

Part of tracking issue NVlabs#274 (Phase 4).

Signed-off-by: abder <bobmatt911@gmail.com>
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.

1 participant