From 034399e2aeae8ecbf069dcc6095945cde0042aea Mon Sep 17 00:00:00 2001 From: Shogo Okada <33060490+okada-shogo@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:47:05 +0900 Subject: [PATCH] poly: the cached experts' offsets (expert tiles) handed to the card by a kernel, not a copy With --prompt-int8 on Turing (expert_tiles_), moe_rows() copied each call's cached-expert offsets (about 1 KB) to the card on the compute stream. A card with one copy engine for uploads ran that copy after the experts already queued for the card (a layer's uncached ones, or with STRATA_INK_PRESTAGE=1 the next layer run's, about 390 MB of IQ4_NL's on an RTX 2070 Super), and the call's launches waited for it, the cached experts' too. copy2() reads the offsets from pinned memory instead, as the row tables already are. Same bits: the same offsets reach the same launches. Co-Authored-By: Claude Opus 5.5 --- engine/src/poly/engine.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/engine/src/poly/engine.cpp b/engine/src/poly/engine.cpp index 85d5cd9ea..270706eab 100644 --- a/engine/src/poly/engine.cpp +++ b/engine/src/poly/engine.cpp @@ -6486,10 +6486,9 @@ void Engine::moe_rows(Layer& L, int il, int n) { h_slot_at_[g] = L.slot[(size_t) group_[(size_t) g]] - slot0; by_at = by_at && h_slot_at_[g] % 16 == 0; } - if (by_at) - ck(cudaMemcpyAsync(d_slot_at_, h_slot_at_, (size_t) n_cached * sizeof(int64_t), cudaMemcpyHostToDevice, - cs(st_)), - "expert offsets"); + // by a kernel that reads them from pinned memory, as the tables: a copy would wait behind the experts the + // copy engine is taking to the card, and the cached experts' launches behind it + if (by_at) copy2(h_slot_at_, d_slot_at_, 2 * n_cached, nullptr, nullptr, 0, st_); } // the cached experts lie class after class in group_: a launch for each class with rows, over all of its experts // (Metal's Mmq has no mul_at(): by_at is never set there)