Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions aiter/ops/triton/_triton_kernels/moe/moe_routing/expt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,25 @@ def _expt_data_compute_stage1(
token_acc = tl.zeros([BLOCK], dtype=TokenStart.dtype.element_ty)
tile_acc = tl.zeros([BLOCK], dtype=TileStart.dtype.element_ty)
offs_n = tl.arange(0, BLOCK)
# pid==0 must run the full loop: it reads TileStart[n_expts_tot-1]
# below for the sentinel, so it must have written it first.
# All other blocks can stop once they've written their own chunk.
done = False
for i in range(0, n_expts_tot, BLOCK):
mask_n = offs_n < n_expts_tot
hist_token = tl.load(Hist + offs_n, mask=mask_n, other=0)
hist_tile = _cdiv_pow2(hist_token, tile_dim_log2)
token_starts = tl.cumsum(hist_token, 0) - hist_token + token_acc
tile_starts = tl.cumsum(hist_tile, 0) - hist_tile + tile_acc
token_acc += tl.sum(hist_token, 0)
tile_acc += tl.sum(hist_tile, 0)
tl.store(TokenStart + offs_n, token_starts)
tl.store(TileStart + offs_n, tile_starts)
offs_n += BLOCK
if not done:
mask_n = offs_n < n_expts_tot
hist_token = tl.load(Hist + offs_n, mask=mask_n, other=0)
hist_tile = _cdiv_pow2(hist_token, tile_dim_log2)
token_starts = tl.cumsum(hist_token, 0) - hist_token + token_acc
tile_starts = tl.cumsum(hist_tile, 0) - hist_tile + tile_acc
token_acc += tl.sum(hist_token, 0)
tile_acc += tl.sum(hist_tile, 0)
if pid == 0 or pid < i + BLOCK:
tl.store(TokenStart + offs_n, token_starts, mask=mask_n)
tl.store(TileStart + offs_n, tile_starts, mask=mask_n)
if pid != 0 and pid < i + BLOCK:
done = True
Comment thread
amd-hhashemi marked this conversation as resolved.
Outdated
offs_n += BLOCK

if pid == 0:
tl.store(TokenStart + n_expts_tot, n_gates)
Expand Down
Loading