Skip to content

Add view-based atomic reductions and ct.@atomic#283

Open
maleadt wants to merge 12 commits into
mainfrom
tb/atomics
Open

Add view-based atomic reductions and ct.@atomic#283
maleadt wants to merge 12 commits into
mainfrom
tb/atomics

Conversation

@maleadt

@maleadt maleadt commented Jul 23, 2026

Copy link
Copy Markdown
Member

Add tile-level atomic reductions backed by Tile IR 13.3's atomic_red_view_tko, including atomic_store_add, atomic_store_max, atomic_store_min, and the bitwise variants.

Add a Base-style ct.@atomic interface for statement and value forms, with explicit memory-order support. Statement forms use the no-return reduction path when possible, while value forms return old => new.

This also aligns the existing atomic operations with Tile IR for unsigned min/max, bitwise update types, and BFloat16 support.

Closes #50

maleadt and others added 10 commits July 23, 2026 15:08
View-based atomic reduction, new in Tile IR 13.3: it reduces a tile into a
view without returning the old value. Wire format mirrors cuTile Python's
encode_AtomicRedViewTkoOp; gated on bytecode >= 13.3 like MakeStridedViewOp.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
atomic_max/atomic_min always emitted the signed MAX/MIN modes, so
Unsigned element types compared incorrectly across the sign boundary.
Factor a select_rmw_mode helper mirroring Python's _select_rmw_mode (float
add -> ADDF, unsigned max/min -> UMAX/UMIN) and route emit_atomic_rmw!
through it. Fix the docstrings that unconditionally said "signed".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
atomic_and/or/xor inherited the implicit TileOrScalar->T conversion from
the shared overload, silently widening a mismatched update. cuTile Python's
_cast_rmw_update_dtype forbids this for bitwise ops (the bit pattern, not
the numeric value, is what's combined). Reject mismatches with a clear
error; add/max/min/xchg keep converting. Updates the atomic_xor Int test,
which passed an Int32 bid into an Int64 array.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tile-granular atomic reductions that do not return the old value (issue #50).
Six atomic_red_view_* intrinsics share emit_atomic_red_view! (view + index +
value, single token result, relaxed/device), classified as plain stores in
effects.jl — never eligible for the parallel-store optimization, so
overlapping reductions stay token-ordered like store_strided_view. The
language functions atomic_store_add/max/min/or/and/xor mirror store's
TileArray and TiledView method families, reusing make_tile_view so
partition/strided (eachtile) selection and broadcasting work unchanged.
Bitwise variants require an exact update dtype; add/max/min convert. A
friendly >= 13.3 check runs ahead of the encoder's hard error; bf16 ADDF is
gated for both the rmw and view-reduction paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Statement forms (`A[i] += v`, `A[i] = op(A[i], v)`) return nothing; value
forms (`A[i] + v`, `max(A[i], v)`) follow Base and return `old => new`. The
macro only parses syntax and picks the ordering literally; the choice between
a view reduction and a fetching atomic is left to type dispatch, so no
ordering value is compared inside the kernel. Statement forms default to
Relaxed (so a tile or view target uses atomic_red_view_tko), value forms to
AcqRel. :sequentially_consistent is rejected (no Tile IR equivalent). Adds
unary negation for tiles, needed to lower `-=` (add of the negated value).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maleadt
maleadt requested a review from AntonOresten July 23, 2026 14:08
@maleadt
maleadt marked this pull request as ready for review July 24, 2026 07:45
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.

High-level atomic operations

1 participant