Repository navigation
The charge comes back from the load that will deliver it (#29) - #82
Merged
Merged
Conversation
Every TMA producer wrote its own transaction-byte total by hand and had to keep it in step with the set of `tma_load` calls it issued. Under-charging flips the barrier before the data lands and the consumer reads a half-written tile — no fault, no diagnostic. Over-charging hangs the block. Nothing was watching for either. `tma_load` and its family now return a `TransactionBytes`, and `Semaphore::expect_tx` takes nothing else. There is no public constructor, so a wrong number is not expressible; the type is `#[must_use]` and not `Copy`, so issuing a load and dropping its charge, or paying one charge twice, are compile errors. `expect_tiles(&[…])` was the lighter alternative and is the same fact stated twice: a list can omit a tile exactly as a sum can omit a term. The cluster case is `TransactionBytes::across_ranks(RANKS)` — the `RANKS *` form #50 named as the interface between the two issues, now derived from the loads each rank issued rather than written down. Charge and completions still commute; the GEMM's charge simply follows the calls it comes from.
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.
Closes #29.
Every TMA producer wrote its own transaction-byte total and kept it in step
with the loads it issued by reading both:
Now the charge comes back from the load:
Which shape, and why
#29 named two and preferred the second, wanting a look at the pipeline stages
first. The look says take it, and the reason is sharper than "convenient":
expect_tiles(&[…])is the same fact stated twice with nicer syntax. Alist can omit a tile exactly as a sum can omit a term. What has to agree with
the charge is the set of loads issued, so the charge has to come from them
and not from anything that restates them.
Semaphore::expect_txtherefore takes aTransactionBytesand nothing else,and the only way to obtain one is to issue a load. Two things fall out, and
they are the point:
integer. There is nothing to mistype.
TransactionBytesis#[must_use], sotile.tma_load(…);as a statementfails under
-D warnings— that is the "add a load, forget the sum" editexpect_tx byte accounting is hand-summed and can silently disagree with the loads issued #29 is about — and a charge bound to a name that never reaches an
expect_txfails as an unused binding. It is also notCopy, socharging the same bytes to two barriers is a use of a moved value.
The lint is not theoretical: it fired on
tests/gaps.rsthe moment the returntype existed, on the two calls that name the signatures without using them.
Stated plainly, because the type does less than it looks: it says how many
bytes, never which barrier. A load aimed at one semaphore whose charge is
paid to another still type-checks — and has to, because that is exactly what a
cluster stage does.
The cluster case, which #50 settled and this had to honour
#71 said the
RANKS *form was the interface between the two issues and thatwhichever shape #29 took, the cluster case is that total scaled by the ranks
staging into the barrier. It is:
Every rank derives the same half-stage charge from the loads it just issued,
because a cluster stage is symmetric by construction — the same symmetry the
MMA descriptor reads across the pair on. The leader scales its half by
RANKSto cover the peer's; the peer drops its copy. Nothing new is expressed and
nothing is fought: the leader still charges its own barrier for bytes it does
not issue, because
mbarrier.arrive.expect_txis.shared::ctaonly.Charge and completions still commute. The GEMM's
expect_txnow sitsafter its loads rather than before, which the signed transaction counter
permits and
sync.rsalready documented. No sync sits between them and nonebecame owed. This is the one ordering change in the PR and it is the one the
B200 run is the gate on.
Where the charge could still be prose, and now cannot
tma_load_at— the partial-box form that builds a 128-row operand out of two64-row global ranges — asked its caller in prose to charge
box_rows * C * E::BYTES, withbox_rowsa property of the map andunreadable from the tile. It is
tma_load_at::<BOX_ROWS>now, const so thecharge is derivable, with a
const { assert!(BOX_ROWS <= R) }under it. Ithas no callers in the repo; leaving the one load in the family whose charge is
a sentence would have left the hole open for the kernel that first wants it.
SharedTile::BYTESstays public and is untouched: it is a layout fact, andthe four kernels' shared plans are built out of it.
CHARGEis the transferfact and is crate-private, because a kernel able to name a charge without
issuing a load is back to writing the number down.
flash_forward'sKTile/VTilealiases are gone. Their last use was thehand-sum.
The test that would have caught the drift
every_producers_derived_charge_is_the_sum_it_used_to_write_down— one caseper
expect_txinexamples/, with the tile types the kernel declares on oneside and the literal byte count its hand-sum came to on the other. Both sides
are spelled out; a derivation checked against a hand-sum computed from the
same expression would be testing nothing.
a_tiles_charge_is_the_boxes_its_load_issuesholds the identity underneathit:
CHARGEcounts what the load loop does — one box per subtile,Rrows ofone swizzle atom each — and
BYTEScounts the tile, and they are the samenumber at every legal shape. Plus the partial-box arithmetic: half the rows,
half the bytes, and two halves back to the whole.
Verification
All run against this branch.
modal run modal_app.py::build— passes. Realcargo oxide build --arch sm_100aon library, examples and harness; 86 host tests.modal run modal_app.py::examples—pass gemm 512x256x256 exacton aB200, plus
pass softmaxandpass layernorm. The gate that matters: thefailure modes under change here are a deadlock and silently wrong numbers.
modal run modal_app.py::device_tests— 30 of 30 cases passed on a B200.modal run modal_app.py::regcount— measured on this branch and onmain,byte-for-byte identical across all 168 entry functions, every counter.
A call-site refactor should move no registers, and it moves none.
cargo fmt,cargo clippy --all-targets -- -D warnings,cargo test(76passed) locally.
One thing outside my lane
device-tests/src/main.rshas tenexpect_txcall sites and would not compileagainst the new signature, so they are converted here — mechanically, two lines
each, no test's behaviour touched. Another agent is working in that directory
on a residency probe; this is a signature migration and should merge past it,
but it is worth knowing about rather than discovering in a conflict.
tma_load_2d_multicast_cg2hands back one tile — what a single destinationreceives, which is the whole of it for the own-bit mask the GEMM uses and the
only mask any kernel here passes. Whether a truly replicating mask charges its
one named barrier once or once per destination is #49's question, and it is
documented as open rather than guessed at here.