Repository navigation
Perf/epv2 1250x ep8 - #723
Merged
Merged
Conversation
…ELF_FIRST) On MTYPE_RW memory a rank's local RMW on its slot allocator word, which the peers' remote RMWs also hit, costs microseconds per call. With selfFirst (default on, gfx125x dispatch only) a sender's slot in a peer is what its remote RMW returns, with no wait on that peer. Each rank publishes, once all its blocks have reserved, how many slots it took in every peer, and places its own tokens above their sum in a pass of its own. A late rank therefore holds up no sender, so the prefill tail measured from the last rank to arrive stays at the original protocol's level. The per-call state is a few hundred bytes of symmetric memory per arena that EpDispatchPlan allocates on the arena's own communicator, found through the new mori.cco.communicator_of_window, so arenas built outside mori need no change. MORI_EP_SELF_FIRST=0 restores the original protocol, the better one where local memory is not mapped MTYPE_RW. Tests: binding tests for the state (one per arena, zeroed, freed with the last plan, refused without a communicator or with a descriptor that misses the local copy); test_op.py RAGGED and NOSELF; bench_ep.py ROUTE=noself and LATE_US.
…y block (MORI_EP_TOKCHUNK) The plain token map fills block b with its warpPerBlock consecutive work units, so a call with fewer units than warps leaves the high blocks idle: 512 tokens on the default 64 x 16 run on 32 blocks. When the units fit in gridDim.x * 8, block b now takes units [8b, 8b + 8) on its first 8 warps. Where the payload pass walks the token map, the 8 warps left without a token then take every metadata run, one peer each, and the token warps none: the tensorcnt wait that ends the metadata pass counts every TDM op of the wave, so a token warp that also sent metadata issued no payload until those stores completed. selfFirst only. Under the original protocol every block that holds tokens also RMWs the rank's own slot word, and there the chunked map measured slower at 512 tokens on EP8 (+2 to +8 us, 3/3 rounds). Geometries with at most 8 warps per block, such as EP4's tuned 64 x 8, and every selfFirst=false kernel compile to the same instructions as before; -DMORI_EP_TOKCHUNK=0 restores the previous code everywhere (all checked by disassembly). EP8 fp4 dispatch, two 4-GPU gfx1250 hosts over UALink, top-k 6, 96 experts per rank, graph-replay median against the selfFirst commit alone, 3 alternating rounds: 16 tokens 33.3 -> 27.2 us, 128: 35.8 -> 30.4, 256: 36.7 -> 30.0, 512: 39.9 -> 34.2, 4096 unchanged. EP4 at its tuned geometry: 16 and 512 tokens run the same instructions, 768 and 1536 are not slower, 4096 is within 0.7 us.
… TokOffExt only on one host selfFirst saves the RMW a rank makes on its own slot allocator word, which only costs anything when the word is in the cco window. With TokOffExt holding it -- the hip backend's default for a single-host gfx1250 EP -- that RMW is cheap and selfFirst is pure overhead: against origin/main, EP4 fp4 dispatch measured 2-3 us slower at 16 tokens and 3-15 us at 768-1536, and up to 29 us with the chunked map compiled in. MORI_EP_SELF_FIRST unset now resolves on exactly when the word is in the window; 1/0 still force either protocol. TokOffExt opens each peer's word by hipIpc handle, which no other host can open, so an EP spanning hosts could not build the op at its defaults (hipIpcOpenMemHandle(pe 4) returned hipError 17). It is now used only when every rank shares this host's kernel boot id; otherwise the word stays in the cco window, which is mapped across hosts, and selfFirst turns on with it. Measured on two 4-GPU gfx1250 hosts over UALink, fp4 dispatch, top-k 6, 96 experts per rank, both variables unset, graph-replay median, 3 alternating rounds: EP4 on one host matches origin/main within 0.7 us at 16-4096 tokens and 1.5 us at 16384; EP8 across the two hosts is 3.1-7.9 us faster than origin/main (run with MORI_EP_TOKOFF_EXT=0, the only way it builds there) at 16-512 tokens, 4096 unchanged.
…ce, bf16 pull loads every source at once fp4 push combine: a run sends four rows where the warp tile holds them (EP8, and EP4 at 64x8). At eight ranks and up with 8-warp blocks, the first four warps of a block load and quantize and the other four only store: a block owns one contiguous range of received rows, cut into 6-row chunks that pass through an LDS ring, and a store warp merges the rows of a chunk that return to one rank into one TDM store, with up to four chunks in flight. Loads and stores then retire on different waves, so no load waits behind a store. Below 64 rows a block the per-warp runs stay. Once every warp has a token, the reduce takes a whole token per item and prepares the next item while the rows of this one load. bf16 pull combine: the rows loaded together before folding cover every source a token can have (min(npes, topk), at least 4), and a chunk is rounded to the fold stride of one 16 B vector a lane where that fits, so no element falls to the scalar tail. EP8, two hosts x 4 gfx1250, topk 6, graph median, 3 rounds, checks pass, against the combine of 3145152: fp4 ct512 / 1536 / 4096 29.9 / 77.7 / 207.9 -> 25.1 / 56.1 / 119.6 us; bf16 53.4 / 119.4 / 291.3 -> 44.9 / 100.4 / 243.6 us. EP4: machine code unchanged except the 64x8 fp4 units (ct <= 256), A/B within 0.11 us.
At eight ranks and up, a 64x16 fp4 combine with e8m0 scales splits each block: eight warps send (four load and quantize, four store through the block's LDS ring) and the other eight reduce. A store warp flags each row at its destination with the call's epoch once the row's stores are done, and a reducing warp reduces a token as soon as every row of it is flagged or comes from a peer that has already arrived at the barrier, which also covers a peer that picked 64x8 and writes no flags. The barrier is arrived at after the send and waited on at the end of the kernel. Once its send is done, each sending warp takes tokens from the reducing warp it is paired with, through a per-warp LDS word cleared with atomicAnd, so the tail of the reduce runs on all sixteen warps. A block sends its rows grouped by origin token, eight groups of numTokens / 8 from a stable counting sort in LDS (a block with more than 1024 rows sends in receive order), so every rank finishes a group at about the same time and the receivers reduce it while the next one is in flight. A 16-warp block that does not overlap splits its send six load warps to ten store warps and reduces through a block-shared LDS ring wherever a warp tile cannot hold a token's rows. The 64x8 reduce at eight ranks and up cuts a small call's tokens into up to seven items spread over the blocks first, reads the row count once a warp and decodes with the packed fp4 converter. EP8 fp4 combine geometry: 64x8 up to 1536 tokens a rank, 64x16 up to 14336, 64x8 above. out_tok gets one uint64 flag a landing row at eight ranks and up. EP8, two hosts x 4 gfx1250, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, equal tokens a rank, graph median, 3 alternating rounds, checks pass, combine us against 084b78e (max 4096 tokens a rank; 16384 for 8192 and 16384): ct 16 / 32 / 64 / 128 / 256 / 512 / 1024: 15.1 / 15.4 / 15.6 / 16.4 / 18.4 / 24.0 / 40.2 -> 14.2 / 14.4 / 14.7 / 15.9 / 18.2 / 23.6 / 39.6 ct 2048 / 4096 / 8192 / 16384: 65.7 / 115.9 / 212.0 / 401.9 -> 60.5 / 100.7 / 181.2 / 395.5 Dispatch code is unchanged, and the EP4 units compile to the same instructions (compared by disassembly).
…ts GPU by LOCAL_RANK COMB_MODE now defaults to push (fp4, PUSH_QUANT), the combine the gfx1250 numbers are taken on. flydsl and parts without that combine need COMB_MODE=pull, which the CI bench step and the README examples now pass. The device is the local rank, so the bench runs across hosts (EP8 on two 4-GPU nodes), where the global rank is not a device index.
…rp, geometry by token count, fp4 own pass on the idle warps Past gridDim * warpPerBlock tokens every warp held two or more tokens and a metadata run, and one wave's TDM ops complete in issue order, so each warp's payload waited for its metadata stores to be acknowledged. There the block's top npes warps now send its metadata, a peer each, and no payload, and the other warps carry the block's tokens; past twice that many tokens those metadata warps also take the whole own pass. Past 22 warps, where an fp4 slab holds one token, metadata warp m works in the W / npes metadata slabs from m * W / npes, the payload warps' included. The split is compiled only where maxTokPerRank exceeds blockNum * warpPerBlock. Below that range an fp4 dispatch (by the dtype the JIT renders into the Cfg) gives the whole own pass to the warps whose metadata run is the own one, idle through the metadata pass, after their own payload, instead of a share to every warp after its payload. fp8 and bf16 move own rows one at a time, and on so few warps fp8 at 512 tokens came out 1.2 us slower, so they keep the even split. EP8 fp4 dispatch geometry by tokens a rank: 64x16 up to 1024, 64x24 up to 1536, 64x32 up to 2048, 64x16 up to 2944, 64x32 up to 4096, 64x16 above; the other dtypes stay on 64x16. MORI_EP_TOKCHUNK becomes the constant kEpTokChunk = 8. EP8, two hosts x 4 gfx1250, bench_ep.py (fp4 push combine), topk 6, 96 experts a rank, SWEEP 512,4096, graph, median of 3 alternating rounds, checks pass, dispatch us against 084b78e: fp4 512 / 4096: 32.86 / 99.88 -> 31.53 / 81.35 fp8 512 / 4096: 39.11 / 132.00 -> 39.26 / 123.08 bf16 512 / 4096: 45.47 / 196.05 -> 45.54 / 187.46 fp4 with a bf16 pull combine (another pair of hosts, 4096 tokens a rank allocated), ct 16 / 512 / 1024 / 1088 / 1536 / 2048 / 3072 / 3328 / 4096: 28.0 / 38.5 / 52.2 / 76.9 / 75.9 / 82.3 / 107.9 / 118.1 / 135.1 -> 25.9 / 37.0 / 50.5 / 54.7 / 63.0 / 75.8 / 97.3 / 102.0 / 122.1 Combine unchanged. The EP4 dispatch and combine units compile to the same instructions (compared by disassembly), and EP4 on one host stays within 0.5 us.
… by default The gfx125x dispatch runs selfFirst wherever the slot allocator word is in the cco window, with no environment override. MORI_EP_TOKOFF_EXT, which moves a single-host EP's word into a separate IPC allocation, is now opt-in (=1): by default a single-host EP keeps the word in the window and runs selfFirst like an EP spanning hosts, and with the opt-in the original protocol runs, as before. The README and the binding test follow.
kPlainMeta, which past gridDim * warpPerBlock tokens gives a block's metadata to its top npes warps, was measured at eight ranks. With selfFirst now the default for a single-host EP it also compiled into the EP4 64x16 dispatch, and there, against the same protocol without it (084b78e with MORI_EP_TOKOFF_EXT=0), fp8 came out 3.9 / 12.8 us slower at 1536 / 4096 tokens a rank and bf16 1.8 / 3.9 us faster. It now needs eight peers or more, so the EP8 units are unchanged and EP4 runs the selfFirst dispatch it had before the split. EP4 on one host, bench_ep.py (fp4 push combine), topk 6, 96 experts a rank, graph, median of 3 alternating rounds on each of two hosts, every point verified: against 084b78e with MORI_EP_TOKOFF_EXT=0 every dispatch cell (bf16 / fp8 / fp4 at 16 / 512 / 1536 / 4096 tokens) is within 0.4 us; fp8 at 4096 was +12.7 / +12.9 us over it and is now -0.03 / +0.12. EP8 across the two hosts against 084b78e, dispatch us: fp4 512 / 4096 32.59 / 100.01 -> 31.75 / 82.07, fp8 39.04 / 131.92 -> 39.34 / 123.33, bf16 45.61 / 196.45 -> 45.67 / 188.16, as before this change. Co-authored-by: Cursor <[email protected]>
…wave scale staging, own pass reads ahead of R The last block to count now tells every peer how many slots this rank takes in it right after the count pass, while warp 0's remote reservations are in flight; it used to wait for the reservations and then the assignment pass. Under selfFirst those per-peer numbers come from the count pass, so the reservations no longer add to destPeTokenCounter. When every warp holds at most one token, the token's scale row is read into registers at the start of the call, and each kept destination stages it with one contiguous whole-wave store instead of eight lanes storing scattered dwords. The own pass now issues every read that does not need R (the staged index, weight and scale rows, the reverse-map entry and the token's top-k row) before it waits for R, so after R it only stores; the scale moves 16 B a lane instead of 4 B, which had cost one round trip per 128 B of scale a lane. A scaled fp8 own pass moves two rows per TDM round trip, which the bf16-wide slab holds. EP4 on one host, bench_ep.py (fp4 push combine), topk 6, 96 experts a rank, graph, median of 3 alternating rounds on each of two hosts, every point verified, dispatch us against 3b02c53 at 16 / 512 / 1536 / 4096 tokens a rank: fp8: 27.95 / 32.50 / 50.24 / 97.55 -> 25.78 / 30.45 / 49.03 / 95.09 (second host 31.08 / 33.14 / 50.94 / 98.69 -> 28.01 / 31.79 / 50.36 / 96.50) fp4: 22.96 / 25.41 / 35.76 / 58.99 -> 20.41 / 23.45 / 34.00 / 59.18 (second host 25.83 / 26.17 / 36.98 / 60.03 -> 22.59 / 25.09 / 35.52 / 60.39) bf16: 27.54 / 37.85 / 66.39 / 132.91 -> 27.44 / 36.56 / 65.98 / 132.26 (second host 29.94 / 38.62 / 67.97 / 133.91 -> 29.65 / 37.65 / 67.35 / 133.07) EP8 across the two hosts, same setup, 16 / 512 / 1024 / 4096: fp4: 27.18 / 31.78 / 41.24 / 81.97 -> 23.42 / 28.63 / 38.43 / 81.30 fp8: 30.91 / 39.19 / 51.06 / 123.07 -> 29.14 / 37.17 / 48.75 / 123.46 bf16: 31.64 / 45.42 / 68.21 / 187.61 -> 31.54 / 44.99 / 65.42 / 187.63 EP4 fp4 at 4096 (+0.2 / +0.4 us) and EP8 fp8 at 4096 (+0.4 us) come out slower; combine is unchanged. test_op.py (bf16, scales, ragged, noself) passes on EP4.
…the count and assignment passes With more than one token a warp, the assignment pass staged each kept (token, destination) pair by reading the token's index, weight and scale rows from global memory and then writing them, the scale four bytes a lane in seven dependent rounds, so at 4096 tokens a rank on 64x16 a warp waited through about forty round trips. Up to four tokens a warp, those rows are now read once at the start of the call, at clamped addresses so that every read issues unconditionally, and the count and assignment passes and the staging take them from registers; each destination gets the scale row as one whole-wave store, its padding zeroed at the store. This replaces the prefetch that covered one token a warp. EP8 across two hosts x 4 gfx1250, bench_ep.py (fp4 push combine), topk 6, 96 experts a rank, graph, median of 3 alternating rounds, every point verified, dispatch us against 0a48447: fp8 2048 / 4096: 75.21 / 123.44 -> 71.35 / 113.11 fp4 4096: 81.35 -> 75.83 bf16 2048 / 4096: 106.69 / 187.82 -> 105.82 / 184.82 16 to 1024 tokens (one token a warp) and the combine are unchanged. EP4 on one host, same setup, on each of two hosts: fp8 1536 / 4096: 48.86 / 95.12 -> 47.45 / 87.83 (second host 50.21 / 96.40 -> 48.45 / 89.32) fp4 4096: 59.00 -> 55.62 (60.28 -> 57.01) bf16 4096: 132.26 -> 129.22 (133.46 -> 130.19) 16 and 512 tokens are unchanged. The combine after a 4096-token EP4 dispatch comes out about 0.4 us slower with its code unchanged. test_op.py (bf16, scales, ragged, noself) passes on EP4.
…token A token's combine rows come from the distinct ranks of its top-k experts, so there are at most min(worldSize, topk) of them, but the fp4 push reduce sized its row arrays and loops by worldSize and took the block-shared ring reduce whenever a warp's tile held fewer than worldSize rows. At 12 and 16 ranks that put the default 64x8 (10 rows a warp) on the ring reduce, and the combine came out about 2.4x slower than at 8 ranks. A token's rows are now min(worldSize, numExpertPerToken) wherever they are staged or counted, so 64x8 keeps the per-warp reduce at any rank count for topk up to 10, and the ws32 fp4 push combine compiles. C rack (4 gfx1250 a host, one UALink vPOD, cross-host load/store), bench_ep.py, bf16 dispatch + fp4 push combine, topk 6, 96 experts a rank, graph, median of 3 alternating rounds, every point verified, combine us against 3b02c53 at 16 / 128 / 512 tokens a rank: EP16 (4 hosts): 36.82 / 41.92 / 88.32 -> 15.35 / 20.21 / 42.31 EP12 (3 hosts): 35.59 / 46.86 / 95.01 -> 15.04 / 19.30 / 39.65 EP8 (2 hosts): 14.51 / 18.05 / 33.73 -> 14.53 / 17.99 / 33.67; on 64x16, the table's choice past 2048 tokens, 3072 / 4096: 135.19 / 174.55 -> 135.20 / 174.66 EP4 at 64x8 / 64x16, and EP8 at topk 8, compile to the same instructions as before. Every combine unit above compiles to the same instructions on this parent as on the measured 3b02c53 with this change. Co-authored-by: Cursor <[email protected]>
… before any rank can call Building the op zeroes this rank's arena (an asynchronous fill) and its selfFirst state, and nothing ordered that against a peer's first dispatch, which already writes into both: its selfFirst count lands in this rank's inbox at the count pass. A zero that ran after that write wiped it, and this rank's first dispatch then waited forever in EpSelfFirstPeerSent for a call number that never came back -- a silent hang of the first call, no error and no timeout, whenever one rank finished building the op later than a peer reached its first count pass. reset() zeroes the same state and had the same race. The constructor and reset() now synchronize the device and barrier on the communicator before returning, as test_op.py already did on the caller side. C rack (gfx1250, one UALink vPOD), bench_ep.py with one rank sleeping 3 s before zeroing its selfFirst state: without this change the first dispatch hung every time (EP12 once; EP8 twice, with the sleeping rank on either host), every rank stuck in the synchronize after it; with it, both EP8 cases pass. Unchanged runs pass on EP4 (one host) and EP8 (two hosts, graph). Kernels and the dispatch / combine paths are unchanged; the internode path and EP12 / EP16 were not rerun with this change. Co-authored-by: Cursor <[email protected]>
…4x16 through 16384 tokens The 64x16 fp4 combine at eight ranks reduces under the send because every block sends its rows grouped by origin token: every rank finishes a group at about the same time, and the receivers reduce it while the next one is in flight. The counting sort that groups them took at most 1024 rows a block, and a block with more sent in receive order, which leaves the receivers no complete token to reduce until the send is over; that is why the table handed the combine back to 64x8 past 14336 tokens a rank, where a block holds about 1000 rows. The sort now takes up to 2048. Up to 1024 rows it runs as before, with every row's group in registers; past that it reads the rows' sources 1024 at a time, every load of a batch in flight at once, and keeps each row's group as one byte at the head of the LDS ring, which no row reaches before the sort is done, for the scatter to read back. EP8 fp4 combine geometry: 64x8 up to 1536 tokens a rank, 64x16 up to 16384, 64x8 above. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us against 9b66e35: 16384 tokens a rank (16384 allocated): combine 394.80 -> 341.61 (-53.19 / -53.21 / -53.33); the dispatch that follows it, whose code is unchanged, 280.58 -> 281.45 (+1.18 / +0.84 / +0.63). 4096 (4096 allocated): combine 100.40 -> 100.49 (+0.10 / -0.13 / +0.01), measured with both arms' EP8 fp4 dispatch at 64x16 instead of the table's 64x32 at 4096; that dispatch kernel stopped with HSA_STATUS_ERROR_ILLEGAL_INSTRUCTION three times on c3-1 the same day, once on 9b66e35 itself. Every 64x8 and EP4 combine unit and every dispatch unit compiles to the same instructions as on 9b66e35; the 64x16 units keep 147 VGPRs and use no scratch. Co-authored-by: Cursor <[email protected]>
… rows as its tile holds Below 64 rows a block the fp4 push combine sends per warp, in runs: a run's rows are loaded and quantized into the warp's LDS tile, their stores go out together and are waited once, and every further run of the warp costs one more row load and one more wait for its stores. A run held 4 rows wherever the tile had room for them, while an 8-warp tile holds 6 ahead of the staged bf16 row (6 x 3808 + 14336 of 38080 bytes), so at EP8 512 tokens a rank, about 4.4 rows a warp, every warp with a fifth row ran a second time for it. A run now holds as many rows as the tile leaves room for, at most 10, so that a run's stores and the next row's load stay within the 11 TDM ops a wave keeps in flight; 16-warp tiles keep their 2. The run size no longer has to divide the receive capacity: the rows of a run are strided by the grid's warps, so nothing tiles the capacity by it. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, combine us against 9b66e35, whose 64x8 units compile to the same instructions as this parent's: EP8 512 tokens a rank (4096 allocated): 23.67 -> 23.31 (-0.36 / -0.28 / -0.40). EP4 on one host, 128 / 256 tokens a rank (256 allocated): 14.60 / 16.04 -> 14.55 / 16.03 (-0.11, +0.02, -0.03 / -0.06, +0.03, 0.00); the dispatch at 256, whose code is unchanged, read +0.42 / +0.24 / +0.18. Only the 64x8 combine units (and the 80x4 single-shot fallback) change; the 64x16 units and every dispatch unit compile to the same instructions as on the parent. Co-authored-by: Cursor <[email protected]>
… warps The 64x16 fp4 combine at eight ranks groups a block's rows by origin token before it sends them, and every wave of the block waited at the barrier behind that counting sort while warp 0 did it alone: at 16384 tokens a rank, about 1133 rows a block, warp 0's sort and the barrier took 16 us of a 341 us combine (MORI_COMB_SEG_PROBE phase probe, 3 rounds, both hosts). Every warp now takes one contiguous run of the block's 32-row chunks (at most 4 at the 2048-row limit), counts its rows a group and leaves the counts at the head of the LDS ring, which no row reaches before the sort is done; after one more barrier each warp scatters its rows from the offsets the warps before it leave. A row lands where one warp walking every chunk in turn would put it, so the send order, and everything after it, is unchanged. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us against 33732a0: 16384 tokens a rank (16384 allocated): combine 341.29 -> 329.39 (-12.01 / -11.90 / -11.64); the dispatch, whose code is unchanged, +0.64 / -0.32 / +0.10. 4096 (4096 allocated): combine 100.61 -> 97.90 (-2.61 / -2.71 / -2.70); the dispatch +0.14 / +0.15 / +0.10. Both arms ran the EP8 fp4 dispatch at 64x16 instead of the table's 64x32 at 4096, as for e7d2d65. 512 (4096 allocated): combine 23.32 -> 23.27 (-0.05 / -0.02 / -0.07), a 64x8 unit. Only the two EP8 64x16 combine units change (10140 -> 4489 instructions, 147 VGPRs, no scratch); every 64x8 and EP4 combine unit and every dispatch unit compiles to the same instructions as on 33732a0. Co-authored-by: Cursor <[email protected]>
…kens, two producers a SIMD The overlapped fp4 combine at eight ranks sends with half its waves -- producers that load bf16 rows and quantize them into an LDS ring, and four store waves that push the ring to the source ranks -- and reduces with the other half. At 16384 tokens a rank its four producers decide the kernel: each quantizes about 283 rows at about 1 us a row (MORI_COMB_SEG_PROBE phase probe). With two producers on every SIMD a row took only 14% longer, so a producer is bound by its own dependent chains and LDS reads rather than by the SIMD's issue rate, but in a 16-warp block that left too few waves to reduce. The overlapped path now also takes 24-warp blocks: eight producers, the same four store waves and twelve reducing waves, the ring two slots shorter (nine) to make room for the four more staging rows. The EP8 fp4 combine table runs 64x24 from 4097 to 16384 tokens a rank. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us against b77f654: 16384 tokens a rank (16384 allocated): combine 329.55 -> 314.35 (-15.20 / -15.31 / -14.99); the dispatch that follows it, whose code is unchanged, 282.25 -> 280.19 (-2.28 / -2.06 / -1.22). An earlier 3 rounds with the 64x24 unit built from the probe header without the probe, the same instructions as this header's, read -15.33 / -14.86 / -14.65. 4096 (4096 allocated), both arms' EP8 fp4 dispatch at 64x16 instead of the table's 64x32: a 64x24 combine tied with 64x16, 97.91 -> 97.85 (-0.06 / -0.10 / -0.03), so the table keeps 64x16 through 4096; 512 unchanged (+0.04 / 0.00 / +0.08). The new 64x24 unit has 147 VGPRs and no scratch. Every existing combine and dispatch unit, EP4 included, compiles to the same instructions as on b77f654. Co-authored-by: Cursor <[email protected]>
…past four tokens a warp The count and assignment passes of the intranode dispatch keep a warp's tokens' expert indices, weights and scale rows in registers only while the warp holds at most kPreK = 4 tokens. Past that every token was staged from global memory: each kept destination by a group of eight lanes that read its indices, its weights and, four bytes a lane in seven trips, its scale row, every read waiting on the store before it. At EP8 16384 tokens a rank on 64x16 a warp holds 16 tokens, and the assignment took ~67 us of the 277 us dispatch (MORI_DISP_SEG_PROBE phase probe) on ~19 dependent loads a token. Past kPreK tokens the same registers now hold a window of one token that slides: each pass reads its next token's row into slot 1 while it handles slot 0, and the indices, weights and the whole-wave scale row are staged from registers, as the kPreK path already did. Only units that can see more than kPreK tokens a warp (maxTokPerRank > 4 x blockNum x warpPerBlock) with 16 or more warps a block build it; the tables take 8-warp blocks only for small token counts, where a first version's extra code alone cost EP4 fp4 0.3-0.5 us at 128 / 512 tokens. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, topk 6, 96 experts a rank, fp4 push combine, graph, 3 alternating rounds, every point verified, us against 93e471b, the op built for 16384 tokens a rank: fp4 dispatch: 16384 279.66 -> 249.53 (-30.79 / -29.99 / -30.13); 1024 +0.13 / +0.22 / -0.04; 512 -0.36 / +0.35 / -0.12; 128 -0.11 / +0.58 / -0.08. fp8 dispatch: 16384 419.61 -> 390.05 (-29.56 / -29.65 / -28.88); 1024 +0.27 / -0.09 / +0.43; 512 +0.05 / +0.02 / +0.14; 128 +0.37 / +0.64 / +0.48. The combine after the 16384-token dispatch, its code unchanged: -1.03 / -1.42 / -1.37 (fp4). The indices, weights and scale rows every rank received were compared row by row with the senders' (bench_ep.py plus a metadata check, fp4, 1024 / 8192 / 12001 / 16384 tokens: no mismatch), and test_op.py at EP4 passes at 16384 tokens (128x16, eight tokens a warp), scales and ragged included. The four 16384-token EP8 dispatch units drop the old per-group fallback (64x16 fp4: 5583 instead of 6222 instructions), keep their VGPR counts and have no scratch. Every unit built for 4096 tokens or fewer, EP4 included, and every combine unit compile to the same instructions as on 93e471b. Co-authored-by: Cursor <[email protected]>
…otating four-token window Past kPreK = 4 tokens a warp the count and assignment passes now run their own loops instead of hooking into the shared ones: the warp's tokens go through the four prefetch slots in turn, each pass handling its k-th token from slot k % 4 and refilling the slot with token k + 4 after its last read, unrolled by four so every slot index is a constant and every load lands in its slot's own registers (a refill issued before the slot's last read was loaded into a temporary and copied back, and the copy waited for the load). The assignment keeps the first lane of each destination with eight ballots, as the count pass does, rather than __match_any_sync, which loops over a shuffle per distinct key, and stages each kept destination in one pass of the whole wave that reads the destination and slot with readlane instead of __shfl: the lanes below topk write the indices and weights, every lane its two dwords of the scale row. The loops shared with smaller token counts are back to their 93e471b text. The window's loads are unconditional, so a warp takes this path only with a scale buffer whenever the scale row is laid out for the wave. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, topk 6, 96 experts a rank, fp4 push combine, graph, 3 alternating rounds, every point verified, us against cd4c9f0, the op built for 16384 tokens a rank: fp4 dispatch: 16384 249.63 -> 232.61 (-17.02 / -16.99 / -17.16); 1024 -0.05 / +0.09 / +0.07; 512 -0.09 / +0.29 / -0.07; 128 +0.18 / +0.51 / +0.10. fp8 dispatch: 16384 390.06 -> 371.41 (-18.81 / -18.68 / -18.37); 1024 -0.54 / -0.59 / -0.50; 512 -0.05 / 0.00 / -0.14; 128 -0.57 / -0.36 / -0.47. The combine after the 16384-token dispatch, its code unchanged: fp4 -0.70 / -0.44 / +0.15, fp8 +0.45 / +0.76 / +1.11. The indices, weights and scale rows every rank received match the senders' row by row (bench_ep.py plus a metadata check, fp4, 1024 / 8192 / 12001 / 16384 tokens), and test_op.py at EP4 passes at 16384 tokens (128x16, eight tokens a warp), scales and ragged included. The four 16384-token EP8 dispatch units keep their VGPR counts and have no scratch. Every unit built for 4096 tokens or fewer, EP4 included, and every combine unit compile to the same instructions as on 93e471b. Co-authored-by: Cursor <[email protected]>
… 1024 tokens: 64x24 to 1536 (fp8 / fp4), 64x22 to 1408 (bf16) EP12 and EP16 had no entry in the HIP geometry table and ran 64x16 at every token count. Past 1024 tokens a 64x16 grid hands the extra tokens to the low blocks, two a warp, and those blocks set the time: on the C rack EP16 64x16 dispatch went from 157 to 238 us between 1024 and 1280 tokens for bf16. 64x24 keeps one token a warp up to 1536 tokens and 64x22 (the most warps a bf16 block holds) up to 1408; past that 64x24 reaches the metadata split at EP12 and two tokens a warp at EP16, and 64x22 two tokens a warp, all slower than 64x16, so the entries go back to 64x16 there. bf16 has its own key, so a dtype without one keeps 64x16. The combine half is the 64x8 default, listed so the dispatch schedule has one; 64x16 measured 0.7-6.9 us slower at EP12. C rack (gfx1250, one UALink vPOD), bench_ep.py, topk 6, 96 experts a rank, fp4 push combine, graph, the op built for 4096 tokens a rank, rank 0's median over the timed replays, us, 64x16 -> this table, 3 alternating rounds, every round the same sign, every point verified (36 runs); EP16 on C16 + C5 + C1 + C9 / EP12 on C5 + C1 + C9: bf16 dispatch: 1280 238.0 -> 189.0 / 211.8 -> 167.4; 1408 240.2 -> 205.4 / 214.9 -> 185.8. fp8 dispatch: 1280 138.9 -> 111.0 / 124.3 -> 102.5; 1408 140.8 -> 120.2 / 125.2 -> 108.0; 1536 142.5 -> 129.2 / 126.6 -> 114.2. fp4 dispatch: 1280 93.8 -> 78.9 / 85.6 -> 72.6; 1408 94.8 -> 81.7 / 85.9 -> 74.0; 1536 95.5 -> 85.2 / 86.1 -> 76.2. 16 / 128 / 512 / 1024 / 2048 / 4096 tokens: within 1.7 us, both signs; combine within 0.6 us. Measured on 93e471b. The twelve EP12 / EP16 dispatch units this table selects, built for 4096 tokens, compile to the same instructions on 9f391fe; built for 8192 or more they take its rotating-window path, which these numbers do not cover. EP4 / EP8 lookups are unchanged.
…ry block, ceil(units / blocks) a block instead of eight Under the chunked token map (selfFirst, more than kEpTokChunk = 8 warps a block, a call of at most gridDim.x * 8 units) block b took units [8b, 8b + 8) on its first eight warps, so 16 tokens ran eight to a block on two blocks and 128 on sixteen. A block's TDM stores leave through its own CU, and at these sizes the call waited on those few blocks: at 16 tokens the dispatch time followed the dtype (EP16 bf16 63.5 / fp8 48.3 / fp4 39.9 us) though the call moves a few hundred KB. Block b now takes t = ceil(units / gridDim.x) units, [b * t, b * t + t), on its first t warps; the warps at or past t take the ids left over as before, so the map stays a bijection and every pass walks the same token set, and the metadata and own-pass warps (at or past kEpTokChunk) are unchanged. At 512 units on 64 blocks t is 8, the old map. C rack (gfx1250, one UALink vPOD), bench_ep.py plus a row-by-row check of the indices, weights and scale rows every rank received, topk 6, 96 experts a rank, fp4 push combine, the HIP table's geometry, graph, the op built for 4096 tokens a rank, rank 0's median over the timed replays, dispatch us, before -> after, 3 alternating rounds, every round the same sign; EP8 on C16 + C9 / EP12 on C5 + C1 + C9 / EP16 on C16 + C5 + C1 + C9: fp4 16: 31.7 -> 25.1 / 36.9 -> 28.7 / 39.9 -> 29.3; 64: 33.1 -> 25.6 / 39.4 -> 30.9 / 42.2 -> 31.6; 128: 34.1 -> 27.1 / 40.4 -> 34.2 / 42.8 -> 36.6; 256: -2.8 / -0.6 / -1.7. fp8 16: 39.1 -> 25.5 / 44.5 -> 29.0 / 48.3 -> 30.6; 64: 40.9 -> 28.2 / 47.9 -> 32.1 / 51.2 -> 33.5; 128: 41.7 -> 32.1 / 49.2 -> 39.0 / 51.9 -> 41.8; 256: -5.6 / -4.6 / -4.0. bf16 16: 52.0 -> 26.0 / 59.0 -> 30.5 / 63.5 -> 31.8; 64: 53.9 -> 29.5 / 63.6 -> 33.9 / 68.2 -> 35.6; 128: 55.2 -> 35.4 / 65.0 -> 42.5 / 68.8 -> 46.7; 256: -11.9 / -10.0 / -9.8. 512 and 4096 tokens within 1.5 us, both signs; combine within 0.8 us. Every point verified: dispatch bytes and the fp4 combine output, and the indices, weights and scale rows row by row (EP8 fp8, EP12 and EP16 all three dtypes, EP16 also at the ragged counts 1 / 7 / 100 / 300 / 511: 7.0 M rows, no mismatch). The measured build was this change behind a compile switch; with the switch on it compiles to the same instructions as this commit for 13 dispatch units (EP4 / EP8 / EP12 / EP16, 64x8 to 64x24, built for 4096 and 16384 tokens), VGPR / SGPR counts unchanged and no scratch. Without selfFirst (EP4's default) or with at most eight warps a block the map stays the plain one at compile time.
…flight on 24-warp blocks On the overlapped fp4 combine's 24-warp blocks (EP8, 4097 to 16384 tokens a rank) the stores bound the push: at 16384 tokens the eight producers waited 94 us for a free ring slot (MORI_COMB_SEG_PROBE phase probe). With the producers' row loads, the overlapped reduce and the row flags all switched off the push still ran at about 1.05 TB/s, against 1.49 TB/s for the dispatch's payload over the same links, while each store wave kept up to four 6-row chunks in flight (about 370 KB a CU; the dispatch keeps about 125 KB). One chunk in flight a store wave pushed faster than four, both in that stripped build (stores done 263.0 -> 256.4 us, two chunks 254.0) and in the full kernel (301.5 -> 294.8 us, one round each), so the chunks behind the first were only queueing. A store wave on a 24-warp block now retires its chunk before it sends the next. 16-warp blocks, whose four producers bound the push, keep four: one in flight tied there. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us against 9f391fe: 16384 tokens a rank (op built for 16384): combine 313.17 -> 309.03 (-3.72 / -4.20 / -4.60); the dispatch, its code unchanged, +0.10 / -0.12 / +0.22. 8192 (op built for 8192): combine 170.98 -> 167.30 (-3.11 / -3.82 / -3.68); dispatch +0.06 / +0.07 / -0.05. Both were measured on 9f391fe with one chunk in flight on 16-warp blocks too; in the same run its 2048 and 4096 points (64x16 combine, both arms' EP8 fp4 dispatch at 64x16 instead of the table's 64x32) read -0.01 / -0.12 / -0.22 and +0.01 / -0.09 / +0.03. On this commit's parent c036041 the change builds the 64x24 combine unit to the same instructions as the measured one (147 VGPRs, no scratch) and every other unit, the 64x16 combine units, every dispatch unit and EP4 included, to the same instructions as c036041; the combine units of c036041 and 9f391fe are the same. Co-authored-by: Cursor <[email protected]>
…nk, not only past 4096 93e471b kept 64x16 through 4096 tokens because 64x24 only tied it there (97.91 against 97.85 us). Since 48916b6 the 24-warp blocks' store waves keep one chunk in flight, and at 4096 tokens 64x24 is now ahead. The EP8 fp4 combine table runs 64x24 from 1537 to 16384 tokens a rank; 1536 and below keep 64x8. Table only, no kernel source changed. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us, both arms on 48916b6's kernels, the op built for 4096 tokens a rank, both arms' EP8 fp4 dispatch at 64x16 instead of the table's 64x32 at 4096: 4096: combine 97.76 -> 96.00 (-1.76 / -1.76 / -1.71); the dispatch after it, its code unchanged, -0.55 / -0.43 / -0.43. 2048: combine 61.29 -> 60.98 (-0.72 / -0.31 / -0.27); dispatch -0.68 / -0.60 / -0.96. Co-authored-by: Cursor <[email protected]>
…roducers on 24-warp blocks On the overlapped fp4 combine's 24-warp blocks each SIMD runs one store wave next to two producers that quantize, and the producers wait on the ring slots the store wave frees. The store wave now sends at the highest wave priority (s_setprio 3) and drops back to 0 before it helps reduce. In the phase probe (16384 tokens, one round) the store waves' own execution fell 59.1 -> 55.3 us and their stores finished 1.1 us earlier. Only the 64x24 combine unit changes (the two s_setprio); every other unit compiles to the same instructions as c239dad. C rack c3 (two hosts x 4 gfx1250, one UALink vPOD), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us against c239dad, the op built for 16384 tokens a rank, both arms' EP8 fp4 dispatch at 64x16 instead of the table's 64x32 at 4096: 16384: combine 309.66 -> 308.33 (-1.27 / -1.00 / -1.45); the dispatch, its code unchanged, +0.20 / +0.09 / +0.30. 4096: combine 96.30 -> 95.83 (-0.23 / -0.63 / -0.49); dispatch -0.02 / +0.17 / -0.04. Co-authored-by: Cursor <[email protected]>
EP sizes that are not a power of two are not supported for now, and their entries only add to what has to be kept in step. EP12 goes back to the single-shot default (64x16 dispatch, 64x8 combine), as before e2b87c1; the EP16 entries stay. The EP16 fp4 push combine entry was the 64x8 default as well and goes too: lookup falls back to _COMBINE_TABLE, whose EP16 64x8 line the dispatch schedule needs anyway. Checked by loading this file and its parent with the device stubbed to gfx1250 and looking up every world size (4 / 8 / 12 / 16 / 32), dispatch dtype (bf16 / fp8 / fp4) and combine quant (none / fp4_blockwise): only EP12 changes, to no schedule; every other lookup is identical.
The EP16 entries chose 64x24 (fp8 / fp4) up to 1536 and 64x22 (bf16) up to 1408 tokens a rank and 64x16 everywhere else, so they only acted on 1025-1536 tokens a rank: too narrow a range to be worth the rows. EP16 goes back to the single-shot default (64x16 dispatch, 64x8 combine), and with the EP12 entries gone in 111a424 the table is as before e2b87c1 apart from the EP8 fp4 combine changes made since. Checked by loading this file and its parent with the device stubbed to gfx1250 and looking up every world size (4 / 8 / 12 / 16 / 32), dispatch dtype (bf16 / fp8 / fp4) and combine quant (none / fp4_blockwise): only EP16 changes, to no schedule; every other lookup is identical.
…24 from 2048 tokens a rank The overlapped fp4 combine -- producers quantize received rows into an LDS ring, store waves push them to the source ranks, and the other half of the block reduces each token as its rows land -- was compiled in only from eight ranks up, so EP4 ran the per-warp send and a separate reduce at every size: at 16384 tokens a rank it took 362 us for 54040 rows, where EP8 takes 308 us for 72461. EpFp4Ovl now also takes 24-warp blocks at four ranks (EP4's 8- and 16-warp units keep the per-warp send), the split send's chunk size follows the overlapped path, and the host sizes the row flags in out_tok from four ranks up (they were allocated only from eight). The EP4 fp4 combine table runs 64x24 from 2048 to 16384 tokens a rank; 257 to 2047 keep 64x16, and so does everything above 16384, which was not measured. C rack c3-2 (4 gfx1250, EP4 on one host), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us, 64x16 against 64x24: 16384: combine 361.86 -> 252.43 (-109.72 / -109.38 / -108.94); 8192: 183.35 -> 137.42 (-46.23 / -30.24 / -53.57); 4096: 97.10 -> 80.33 (-17.07 / -16.77 / -23.57); 2048: 53.96 -> 52.41 (-1.89 / -5.45 / -1.26). Below 2048 64x24 is behind: 1792 +0.48 / +0.82 / +0.91, 1536 +3.94 / +4.11 / +3.92, 1280 +4.77 / +4.58 / +4.22, 1024 +8.09 / +8.14 / +8.15, 512 +11.10 / +11.11 / +10.98. The dispatch, its code unchanged, moved by less than 0.5 at every point but single slow replays. Below 2048, this commit against d8e5a2f: combine 128 / 512 / 1024 / 1536 within 0.2 every round; 2047 +0.38 / +0.39 / +0.35 in one run and -0.53 / +0.27 / -0.11 in the next (an arm with only the branch's hip_backend.py, no EP4 flags, read -0.41 / +0.23 / -0.49 there). The combine output was also checked at 256, 2047, 2048, 2049, 5000, 12001 and 16384 tokens a rank. Every existing unit (37: all of EP8, EP4's 64x8 and 64x16 combine, every dispatch) compiles to the same instructions as on d8e5a2f. Co-authored-by: Cursor <[email protected]>
…ght send metadata on small calls Under the chunked token map a 64 x 16 block sends its metadata from warps 8-15 only, so at EP16 eight warps carry the fifteen remote runs and seven of them send two. A wave issues its remote TDM stores one after another and one run takes a few us to issue, so those warps set the length of the metadata pass, the largest part of a small dispatch (EP16 bf16 at 16 tokens, probe build: 12.5 of the 27.4 us in the kernel). The same map hands tokens only to the first t = ceil(units / gridDim.x) warps of a block (t = 1 at 16 tokens, 2 at 128), and warps t..7 sat idle. Where a block has fewer warps past kEpTokChunk than remote peers but at least one warp a peer (kMetaLo: EP16 at 16 to 22 warps a block), the metadata runs now start at warp t, and the peers are numbered from the rank after this one so that the skipped own run comes last: at 16 tokens every remote peer has a warp of its own. EP32 at 64 x 16 would keep two runs on a wave and is left as it was until it is measured. C rack (gfx1250, one UALink vPOD), EP16 on C13 + C5 + C1 + C9, bench_ep_pr.py plus a row-by-row check of the indices, weights and scale rows every rank received, topk 6, 96 experts a rank, the default 64 x 16 geometry, graph, the op built for 4096 tokens a rank, rank 0's median over the timed replays, dispatch us, before -> after, 3 alternating rounds: bf16 16: 31.7 -> 29.6; 32: 32.4 -> 30.6; 64: 35.5 -> 33.7; 128: 45.8 -> 43.9 (every round -1.4 to -2.5). fp8 16: 30.7 -> 27.0; 32: 31.1 -> 27.9; 64: 33.9 -> 30.6; 128: 42.1 -> 40.6; 256: 52.0 -> 51.5 (every round -0.4 to -3.9). fp4 16: 29.3 -> 26.3; 32: 29.9 -> 26.7; 64: 31.2 -> 28.4; 128: 36.2 -> 35.1; 256: 44.1 -> 43.7 (every round -0.3 to -3.4). bf16 at 256 and every dtype from 512 to 4096 tokens within 1.8 us, both signs (fp4 at 512 and 2048 +0.2 to +1.1 in all three rounds); combine within 0.6 us. Every point passed the dispatch byte check and the row check with no mismatch. The measured build compiles to the same instructions as this commit for EP16 64 x 16 in all three dtypes, built for 4096 and 512 tokens a rank. EP4 at 64 x 8 and 64 x 16, EP8 at 64 x 16, 64 x 24 and 64 x 32, EP16 at 64 x 24, EP32 at 64 x 16 in all three dtypes and the EP16 fp4 combine compile to the same instructions as the parent.
…he next chunk's rows ahead The fp4 combine's send (EpFp4CombineSend) took warpId as threadIdx.x / WS, which lives in a VGPR, so every loop the send runs over it -- chunk counters, in-flight counts, the EpWaitTensorAtMost switch -- was compiled as exec-masked branches. warpId now comes through readfirstlane. On the overlapped 64x24 path, where a store wave keeps one chunk in flight, the store wave also reads the next chunk's rows (sort table) and their ranks (receive map) before it waits for the chunk, and keeps the in-flight chunk's rows and ranks in registers for its retire, instead of reading back after the wait what the producer left in LDS. c3-1 + c3-2 (EP8: 8 gfx1250 on two hosts in one UALink team; EP4: c3-2 alone), bench_ep.py, fp4 dispatch and fp4 push combine, topk 6, 96 experts a rank, graph, 3 alternating rounds, every point verified, us, 37723c9 -> 37723c9 with this change; per round: dispatch + combine, which the bench times back to back in one graph. On d05ab8a, its parent here, every EP8 / EP4 unit measured compiles to the same instructions as in the measured build. EP8 16384: combine 308.30 -> 302.94 (-3.8 / -4.6 / -4.8); 8192: 166.65 -> 163.29 (-3.0 / -2.7 / -3.4); 4096: 95.71 -> 93.22 (-2.2 / -2.6 / -2.3); 2048: 59.04 -> 57.42 (-1.6 / -1.8 / -1.6); 512: 23.27 -> 23.13 (-0.1 / 0.0 / -0.3). EP8 2048 and 4096 were measured with the table's 64x32 dispatch rows replaced by 64x16 on both arms. EP4 16384: combine 252.02 -> 251.00 (-1.4 / -0.8 / -1.2); 4096: 80.25 -> 79.54 (-0.7 / -1.0 / -0.7); 2048: 52.34 -> 51.54 (-1.2 / -0.9 / -1.3); 512: 19.29 -> 19.23 (0.0); 128: 15.26 -> 15.24 (0.0). Every dispatch unit compiles to the same instructions as on 37723c9. VGPRs: EP8 64x24 combine 147 -> 144, 64x8 148 -> 150; EP4 64x24 147 -> 138, 64x16 146 -> 143, 64x8 145 -> 142; no scratch anywhere. Co-authored-by: Cursor <[email protected]>
…ocks past 2048 tokens a rank Past 2048 tokens a rank the table no longer holds the grid at 64 blocks for a co-resident GEMM: the EP8 dispatch (every dtype) takes 128x16, the EP8 and EP4 fp4 push combine 128x24, and the EP4 bf16 / fp8 dispatch moves its 128x16 edge from 4096 down to 2048, where the EP4 fp4 dispatch already was. Up to 2048 tokens nothing changes; the EP8 fp4 dispatch's 64x32 row at 2945-4096 is gone. C rack C12 + C11 (EP8: 8 gfx1250 on two hosts in one UALink vPOD; EP4: C12 alone), bench_ep.py with the metadata check added (every received index / weight / scale row compared with the sender's), topk 6, 96 experts a rank, fp4 push combine, graph, 3 alternating rounds, us, the combine-send commit before this one -> this commit (both arms at 4096 run the EP8 fp4 dispatch as 64x16 rather than the old 64x32 row). Every point verified: payload bytes, fp4 combine output, 0 metadata mismatches in 18.3 M EP8 and 6.8 M EP4 rows; no fabric error on either node. Each per-round difference has the same sign in all three rounds. EP8 dispatch at 4096 / 8192 / 16384: fp4 123.0 -> 82.5, 219.5 -> 135.1, 415.4 -> 240.3; fp8 181.2 -> 120.0, 333.4 -> 209.5, 637.7 -> 387.4; bf16 309.6 -> 198.8, 591.0 -> 363.1, 1151.0 -> 692.0. EP8 combine (every dispatch dtype within 2 us of these): 164.5 -> 97.9, 315.4 -> 178.4, 609.5 -> 340.2. EP4 combine (fp4; fp8 / bf16 within 2 us): 127.2 -> 76.0, 243.1 -> 139.2, 474.5 -> 262.9. EP4 dispatch at 4096: fp8 129.1 -> 86.1, bf16 212.2 -> 134.3; every other EP4 dispatch point keeps its geometry and moved by -1.7 to +1.1. Co-authored-by: Cursor <[email protected]>
…or op, and reads the cco window as constant memory Since d05ab8a the EP16 fp4 dispatch (64 x 16) stopped with HSA_STATUS_ERROR_ILLEGAL_INSTRUCTION in about one bench run in three at 2048 and 4096 tokens a rank (9 of 29 runs). The ROCm debug agent put every faulting wave (16 waves in 9 runs, on three hosts) at the head of the metadata loop over a run's chunks, on a legal s_mov_b32. The 7 dumps read back were identical register for register and show the wave had finished the first chunk, issued the chunk's last tensor_store_from_lds, and reached the head without running the loop latch: the back edge right after that store behaved as if it had landed on the s_branch in front of the latch. Shifting the whole kernel by 4 and by 8 bytes moved the fault with the code, so it is neither memory corrupted at a fixed address, nor the head's 64-byte alignment, nor the store straddling a 64-byte line. Why the parent's code, with the same store and back edge in this loop, never faulted in 10 such runs is not known. TdmIssueLoad / TdmIssueStore now follow every tensor op with an s_nop, so the instruction after it is never a branch; the same reproducer then ran 60 times without a fault (36 runs with the s_nop alone on d05ab8a, 24 with the dispatch of this commit). The asm s_nop alone cost the payload loop: the compiler takes an asm statement as touching memory, so the dispatch reloaded the cco window's winBase / stride4G before every TDM store (bf16 at 4096 tokens +34 us). The dispatch now reads the window through an address-space-4 pointer (EpWinC): the window does not change while a kernel runs, the loads become scalar and are reused across the asm, and dispatch VGPRs drop (EP16 fp4 64 x 16 122 -> 115, bf16 96 -> 81, EP8 fp4 64 x 32 128 -> 116). The combine keeps the generic reads, which measured 0.1-0.3 us faster there at small ct. C rack (gfx1250, one UALink vPOD), EP16 on C14 + C5 + C1 + C9, EP8 on C14 + C5, EP4 on C9, bench_ep_pr.py plus the row-by-row check of the indices, weights and scale rows every rank received, topk 6, 96 experts a rank, graph, rank 0's median over the timed replays, us, before -> after, 3 alternating rounds. On d05ab8a: EP16 dispatch bf16 16: 30.22 -> 29.88; 256: 54.23 -> 53.33; 4096: 373.71 -> 373.42. EP16 dispatch fp8 16: 27.51 -> 27.25; 256: 46.73 -> 45.74; 4096: 220.79 -> 220.64. EP16 dispatch fp4 16: 26.19 -> 25.69; 256: 43.09 -> 41.64; 1024: 61.56 -> 61.51 (the parent faults from 2048; at 2048 against 37723c9: 93.69 -> 93.82). EP8 bf16 dispatch 256: 42.56 -> 41.93; 1024: 94.96 -> 93.91. EP4 fp4 dispatch, 16 to 4096 tokens: -0.10 to -0.45 in every round. On 49ca9d7, the parent here, fp4: EP8 dispatch 4096: 82.27 -> 81.55; 8192: 135.44 -> 134.72. EP8 combine 4096: 97.69 -> 97.86; 8192: 178.62 -> 178.76. EP4 dispatch 8192: 99.75 -> 99.27. EP4 combine 4096: 76.02 -> 76.17; 8192: 138.38 -> 138.95. EP16 dispatch 256: 42.81 -> 42.07; EP16 combine within 0.25 us. Every other combine point within 0.4 us. Every point passed the dispatch byte check and the row check with no mismatch. The dispatch of this commit compiles to the same instructions as the measured builds in every unit checked: EP16 bf16 / fp8 / fp4 64 x 16, EP16 fp4 64 x 24, EP8 fp4 64 x 16 and 128 x 16, EP8 bf16 128 x 16, EP4 fp4 128 x 16 and EP32 bf16 64 x 16 (the measured builds also match each other in EP16 fp4 64 x 32, EP8 fp4 64 x 32, EP8 bf16 64 x 24, EP4 fp4 64 x 16 and EP4 bf16 128 x 16). No unit checked spills.
No code change: the units checked (EP16 bf16 / fp8 / fp4 64 x 16, EP8 fp4 128 x 16, EP4 fp4 64 x 16 and EP32 bf16 64 x 16 dispatch; EP16 fp4 / bf16 64 x 8, EP8 fp4 128 x 24 and EP4 fp4 64 x 24 combine) compile to the same instructions as 87ccc60.
No code change: the units checked (EP16 bf16 / fp8 / fp4 64 x 16, EP8 fp4 128 x 16, EP8 bf16 64 x 16, EP4 fp4 64 x 16 and EP32 bf16 64 x 16 dispatch; EP16 fp4 64 x 8 and EP8 fp4 128 x 24 combine) compile to the same instructions as 78b252b.
QizhouZhang97
pushed a commit
that referenced
this pull request
Oct 9, 2026
…al (#727) FieldCount.MatchesEpCfg pinned 12. #719 grew EpCfg to 14 (combineFp4, combineFp4F32Scale) and #723 to 15 (selfFirst), and both updated only the header's own assert. CCO CI stops at this test on every run since #723 (#719's run had already stopped at an earlier step), so the ops-v2 EP8 steps have not run on main since 8bffec7. Count the VisitFields walk instead. That is the invariant the test is there for, and unlike the header's MORI_JIT_ASSERT_FIELD_COUNT it also catches a field left out of VisitFields. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
jeffdaily
added a commit
to jeffdaily/mori
that referenced
this pull request
Oct 9, 2026
Whitespace and line breaks only, from clang-format 20.1.8 with the repo's .clang-format. ROCm#723 left this file out of format, so the pre-commit check fails on any PR that touches it (the check runs on every changed file); this change touches it. Stripping whitespace, the file is identical before and after. Authored with Claude.
kawhil-amd
pushed a commit
that referenced
this pull request
Oct 19, 2026
…t=True) (#733) * fix(EPv2): give routing handles their own buffers on request (snapshot=True) A handle from dispatch(..., return_routing=True) aliases the op's routing_dest_map and total_recv, so the next return_routing dispatch on the same op overwrites every earlier handle: combine with an older handle returns wrong tokens, and replaying one on flydsl faults in ep_dispatch_0. The HIP intranode combine also zeroed the total_recv it was passed, so even a handle with private buffers could combine only once. Fixes #715. dispatch() takes snapshot=True (with return_routing=True). The handle then gets a fresh torch.empty_like dest map that the dispatch kernel writes directly (no fill and no copy: dispatch writes every (tok, k) entry below num_tokens), plus a 4-byte copy of total_recv. The count is copied rather than handed to the kernel because local_expert_count and the StdMoE convert read it through the op. snapshot=False stays the default and allocation-free; the EpDispatchRoutingHandle docstring now states that such a handle is valid until the next return_routing dispatch on the same op. snapshot=True is rejected on internode and scatter configs, whose combines also read routing state kept in the arena. The total_recv reset moves to the producer. The HIP intranode dispatch zeroes it in its preamble (ordered before the Phase-2 adds by the __syncthreads() on the same warp), and the combine kernels no longer write it: the generic HIP combine, the arch-specific intranode combine body (its dispatch already assigns the count instead of accumulating), and the flydsl combines (flydsl dispatch already self-resets). This drops the host-side total_recv.zero_() before each HIP dispatch and with it the KernelSet.self_resets_counters flag, which no backend sets to False anymore. The internode kernels are unchanged: copystaging already zeroes the count at dispatch, and EpCombineAll's reset sits with its blockFlagCounter reset, which cannot be tested here. Test Plan New tests/python/ops/dispatch_combine_v2/test_routing_snapshot.py (both backends, wired into ci_cco.yml at EP8): two snapshot handles from back-to-back dispatches; combine with the older one, the newer one, then the older one again; counts survive combine; flydsl replay of the older handle with a new payload; snapshot needs return_routing; the default handle still aliases the op's buffers. ``` torchrun --standalone --nproc_per_node=2 test_routing_snapshot.py # also 4 MORI_V2_KERNEL_BACKEND={flydsl,hip} REPLAY=<1 on flydsl> SWEEP=8,128,512 torchrun --standalone --nproc_per_node={2,4} test_op.py MORI_V2_KERNEL_BACKEND=flydsl {STDMOE=1 | COMBINE=scatter | QUANT=fp8_direct_cast} torchrun --standalone --nproc_per_node=2 test_op.py MORI_V2_KERNEL_BACKEND=hip RESET=1 torchrun --standalone --nproc_per_node=2 test_op.py MORI_V2_KERNEL_BACKEND={flydsl,hip} torchrun --standalone --nproc_per_node=4 test_graph_capture.py MORI_V2_KERNEL_BACKEND={flydsl,hip} torchrun --standalone --nproc_per_node=2 test_asym_dtype.py torchrun --standalone --nproc_per_node={2,4} test_ep_backend_parity.py torchrun --standalone --nproc_per_node=2 test_op_lifecycle.py ``` On gfx950: the new test passes 18/18 checks at EP2 and EP4. The existing tests above give the same 87 PASS / 0 FAIL lines on main and on this branch. On main, emulating snapshot with clones (the issue's workaround) fails the HIP second combine and the count-survives check on both backends. Latency is unchanged at EP2, hidden 7168 bf16, top-k 8, 4096 tokens/rank (A/B/A/B medians); at 128 tokens HIP dispatch gets about 4 us faster without the host memset, and snapshot=True adds about 2-4 us. Authored with Claude. * style: clang-format the arch-specific intranode body Whitespace and line breaks only, from clang-format 20.1.8 with the repo's .clang-format. #723 left this file out of format, so the pre-commit check fails on any PR that touches it (the check runs on every changed file); this change touches it. Stripping whitespace, the file is identical before and after. Authored with Claude. * Document the weight-fold contract for routing handles and test it combine(..., weights=...) reads the forwarded weights from the arena, not from the handle, so snapshot=True does not make a weighted combine with an older handle correct. State that the caller is responsible: a weighted combine is valid with the handle of the latest dispatch, or after a replay dispatch with the handle, which rewrites the weights at its slots. StdMoE's convert also reads the op's slot map and forwarded weights, so snapshot=True now rejects enable_std_moe, as it already rejects the internode and scatter modes. test_routing_snapshot.py dispatches distinct weights per call and checks the fold for the newest handle and, on backends with replay, for the older handle after replaying it. Authored with Claude.
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
Test
c3-2, single-host EP4, fp4 dispatch + fp4 push combine, topk 6, 96 experts/rank, HIP graph, ITERS=50, 3 alternating rounds, medians in us, all 66 points verified (dispatch bytes + fp4 combine output).