Skip to content

Commit 02cd3b1

Browse files
committed
fix: Keep Rubin gather buffer reset within its owned kernel
Signed-off-by: Dongfeng Yu <dongfengy@nvidia.com>
1 parent 5e385f9 commit 02cd3b1

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎cpp/tensorrt_llm/kernels/glmMoeDsaRubin/highThroughput/glmMtpHeadGather.cu‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ __global__ void __launch_bounds__(kAllGatherBlockSize) oneshotAllGatherKernel(Al
102102
#endif
103103

104104
LamportFlags<float4> flag(params.bufferFlags, 1);
105+
// This workspace has one stage and uses all-ones words as its empty
106+
// sentinel. Snapshot the dirty range before ctaArrive permits flag rotation.
107+
uint4 const dirtyState = reinterpret_cast<uint4 const*>(params.bufferFlags)[0];
108+
uint32_t const dirtyBytes = params.bufferFlags[4];
105109
auto* stageMcast = reinterpret_cast<float4*>(flag.getCurLamportBuf(params.bufferMcast, 0));
106110
auto const* stageLocal = reinterpret_cast<float4 const*>(flag.getCurLamportBuf(params.bufferLocal, 0));
107111

@@ -131,13 +135,18 @@ __global__ void __launch_bounds__(kAllGatherBlockSize) oneshotAllGatherKernel(Al
131135

132136
flag.ctaArrive();
133137
// Empty the buffer of the previous call; it is written again two calls later.
134-
AllGatherPacket empty;
135-
#pragma unroll
136-
for (int i = 0; i < 4; ++i)
138+
if (dirtyState.w > 0)
137139
{
138-
empty.words[i] = kAllGatherEmptyWord;
140+
auto* dirty = reinterpret_cast<uint4*>(
141+
static_cast<char*>(params.bufferLocal) + static_cast<size_t>(dirtyState.y) * dirtyState.z);
142+
uint32_t const dirtyPackets = (dirtyBytes + sizeof(uint4) - 1) / sizeof(uint4);
143+
uint4 const empty
144+
= make_uint4(kAllGatherEmptyWord, kAllGatherEmptyWord, kAllGatherEmptyWord, kAllGatherEmptyWord);
145+
for (uint32_t idx = static_cast<uint32_t>(tid); idx < dirtyPackets; idx += numThreads)
146+
{
147+
dirty[idx] = empty;
148+
}
139149
}
140-
flag.fillDirtyLamportBuf(params.bufferLocal, empty.packed);
141150

142151
// Copy the gathered rows out of the local buffer as the packets of every rank land.
143152
for (int base = tid; base < gatherTotal; base += numThreads * kAllGatherPacketsInFlight)

0 commit comments

Comments
 (0)