Repository navigation
Add packed atomic add intrinsics (f16x2, bf16x2) - #322
Merged
Merged
Conversation
honeyspoon
force-pushed
the
add-packed-atomics
branch
2 times, most recently
from
July 1, 2026 15:55
47297f0 to
06b1a6b
Compare
nihalpasham
force-pushed
the
add-packed-atomics
branch
from
July 2, 2026 07:16
06b1a6b to
f81fae1
Compare
Signed-off-by: nihalp <[email protected]>
atom_add_f16x2() and atom_add_bf16x2() return the previous value at the address — callers should not silently discard it. Signed-off-by: nihalp <[email protected]>
…d atomics Both NvvmAtomAddF16x2Op and NvvmAtomAddBf16x2Op now verify their result is a 32-bit integer via a shared verify_packed_atomic_result() helper. Signed-off-by: nihalp <[email protected]>
- Mark atom_add_f16x2 and atom_add_bf16x2 as `unsafe fn` (they take raw pointers, clippy::unnecessary_safety_doc would fire otherwise). - Improve safety docs with exact byte requirements and racing UB note. - Extract shared emit_packed_atom_add helper (eliminates 97% duplicate code between the two emit functions). - Extract shared convert_packed_atom_add helper parameterized by PTX type string. - Run cargo fmt to fix import block wrapping. Signed-off-by: nihalp <[email protected]>
Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
add-packed-atomics
branch
from
July 2, 2026 08:46
f81fae1 to
960bebd
Compare
Collaborator
|
Thanks for the PR. The key semantic detail is that the two packed lanes are atomic independently: The final hardware floors are:
Layered the following on top:
This completes the packed-atomic part of #274, but #274 remains open for its other tracked work. It does not fix #289, which covers broader PTX ISA selection. |
13 of 14 tasks
This was referenced Jul 2, 2026
elibol
pushed a commit
that referenced
this pull request
Nov 14, 2026
…ecode decoder (#1448) Transplanted from NVlabs/cutile-rs#322, which was closed when the repository moved here. Closes #1443. Fixes two input-validation bugs in `cutile-ir`'s bytecode `Reader`: - `read_bytes` checked `self.pos + n > len`, which overflows for a huge section length. Debug builds panic on the overflow. In release builds the sum wraps, the check passes, and the slice then panics. It now checks `n > self.remaining()`. - `read_varint` accepted a 10th byte with payload > 1. The extra high bits were shifted out, so the value was silently truncated. For example, a section length could wrap to 1 and be accepted. It now rejects a 10th byte other than `0x00`/`0x01`. Tests: - `decode_rejection.rs`: `reject_section_length_overflow` and `reject_section_length_varint_overflow` both fail on `main` and pass with this change. - `decoder.rs`: `varint_u64_boundaries` round-trips 0, 127, 128, 2^63 and `u64::MAX`. `cargo test -p cutile-ir`, `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` pass under `cutile-rs/` with the pinned 1.98.0 toolchain. The change is identical to #322, where `bash scripts/run_all.sh` passed locally. Signed-off-by: dawnop <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds low-level packed FP16x2 and BF16x2 global atomic-add intrinsics to
cuda-device, with exact PTX semantics and target requirements.
Each 16-bit lane is atomic independently. The returned lanes are the previous
lane values, but they are not guaranteed to form one coherent old 32-bit
snapshot.
Partially addresses #274. It does not fix #289's general requested-target/PTX
mapping problem; both issues remain open.
What changed
Device API and memory contract
atom_add_f16x2(*mut u32, u32) -> u32andatom_add_bf16x2(*mut u32, u32) -> u32operations.atomicity, unspecified lane order, alignment, and overlapping-access rules.
implied.
Compiler pipeline
u32, an unsignedu32addend, and an unsignedu32result.Target selection
sm_70floor and PTX 6.2.sm_90and PTX 7.8.hardware emulation.
Example and tests
packed_atomic_addexample with a compile-only path and a runtimelane-sum smoke test for
sm_90+hardware.regressions.
Testing
cargo test -p dialect-nvvm -p mir-lower -p mir-importer --all-targetscargo check --workspace --all-targetssm_90and both exact atomicsptxas -arch=sm_90accepts the combined PTXsm_89andsm_80reject native BF16x2 before PTX generationsm_70; the instruction assemblesforward for
sm_75on CUDA 13.3sm_120Checklist
crates/cuda-bindings/files changed