Prefill fused IQ experts: opt-in 256-thread kernels STRATA_PF_FUSED_NT=256 and whole-layer launches STRATA_PF_BATCH=N (#3779, #3712)
Problem: on a GA100 card (70 SMs) the 512-thread fused prompt-expert kernels leave the card idle at every barrier and at every grid tail. Change, all opt-in: - STRATA_PF_FUSED_NT=256 sets up a second set of native_kernel instances with 256 threads and two blocks a multiprocessor (WW 2 only), with two-pass weight loads (the loads of the next k step are issued before the current step's decode; load_unit_l gives the same words as load_unit). Every output is the same thread's sum in the same order. - STRATA_PF_BATCH=N launches up to N experts at once (WideBatch holds 512 blob pointers, 4 KB of kernel parameters: CUDA 12.1+, Volta and newer; HIP, gfx906 and the Pascal build keep kMaxBatch). Above 128 it needs the NT = 256 kernels. Below 128 it only changes the launch grouping. - With neither variable set the 512-thread kernels, their launches and their load sequence are unchanged: tile_rows(ww, 512) equals the old 256 / ww, the two-pass code is behind a constant-false TWO_PASS, and the one added test in experts_native is occ_nt > 0, which only STRATA_PF_FUSED_NT=256 sets. - If the 256-thread instances cannot be set up (shared memory, occupancy) the engine prints one line and keeps the 512-thread kernels. Cost: the NT = 256 instances are new device code in every CUDA build (the reporter measured 365,632 bytes for sm_80). Tests: new ctest entry prefill_fused_iq_test_nt256 runs prefill_fused_iq_test (the fused kernels against the double-precision reference and the MMQ path) with STRATA_PF_FUSED_NT=256; it exits 77 below sm_80. Reporter's numbers (linxuhao, CMP 170HX): one MoE layer of 3,256 tokens 8.27 ms with NT = 256; prompts +7.6 % (4K), +4.9 % (16K), +4.3 % (52K) for NT=256 with BATCH=512 on the PR's own build. Greedy answers identical on their 11 prompts. These are theirs. Original change by linxuhao (PR #3779, commit 056d36a9). Merged onto the Q2_0 fused path of #3809 (STRATA_PF_FUSED_Q2N=1) without textual conflicts; the PR predates it, so one line is mine: the NT = 256 setup also sets up the Q2_0 gate/up instance when Q2N is on (without it that instance would have launched without its shared-memory attribute).
This commit is contained in:
1 parent
91aebae636
commit
bdcc34dfa8
5 files changed
+207
-25
No files matched your search
@@ -24,6 +24,14 @@ namespace strata::prefill::fused {
|
||||
constexpr int kTileRows = 64;
|
||||
/// Experts per launch: their blob pointers travel in the launch's parameters (1 KB).
|
||||
constexpr int kMaxBatch = 128;
|
||||
/// The room of WideBatch::blob (below): a whole layer of 512 experts, which STRATA_PF_BATCH=512 (opt-in) launches at
|
||||
/// once on the native kernels' NT = 256 instances when all of them are resident (4 KB of kernel parameters: CUDA 12.1+,
|
||||
/// Volta and newer). HIP, gfx906 and the Pascal / Volta build (STRATA_EXPERIMENTAL_SM60): kMaxBatch.
|
||||
#if defined(__HIPCC__) || defined(STRATA_USE_HIP) || defined(STRATA_HIP_GFX906) || defined(STRATA_EXPERIMENTAL_SM60)
|
||||
constexpr int kBatchRoom = kMaxBatch;
|
||||
#else
|
||||
constexpr int kBatchRoom = 512;
|
||||
#endif
|
||||
|
||||
/// This build has the kernels (a CUDA build; HIP and builds without MMQ do not).
|
||||
bool built();
|
||||
@@ -57,6 +65,12 @@ struct Batch {
|
||||
int e0 = 0, e1 = 0;
|
||||
const uint8_t* blob[kMaxBatch] = {};
|
||||
};
|
||||
/// Batch with room for kBatchRoom experts (e1 - e0 <= kBatchRoom): only the opt-in launches of STRATA_PF_BATCH above
|
||||
/// kMaxBatch on the native NT = 256 kernels (moe_fused_iq.hpp, native_wide()) take it; every other launch takes Batch.
|
||||
struct WideBatch {
|
||||
int e0 = 0, e1 = 0;
|
||||
const uint8_t* blob[kBatchRoom] = {};
|
||||
};
|
||||
/// The batch's products: gate/up from `xa` (quantize_act of the layer's input, [tokens][2560]) through the rows
|
||||
/// `src` of `group`, SwiGLU, H as int8 into `ha` (act_bytes(n, 640)), down into `dm` [n][2560] FP32 at the rows of
|
||||
/// `group`. `n`: the layer's routed rows (tokens * k), which bounds the launch grid.
|
||||
|
||||
@@ -38,5 +38,11 @@ void quantize_act_native(const float* x, int64_t rows, int64_t cols, void* xa, v
|
||||
/// through Alloc's 256-byte takes from a 256-aligned cache slot or cudaMalloc).
|
||||
void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n, const void* scratch, const void* xa,
|
||||
const int32_t* src, void* ha, float* dm, void* stream);
|
||||
/// The NT = 256 kernels (STRATA_PF_FUSED_NT=256) are set up on the current device: experts_native takes a WideBatch
|
||||
/// (STRATA_PF_BATCH up to kBatchRoom experts a launch).
|
||||
bool native_wide();
|
||||
/// experts_native() of a WideBatch, on the NT = 256 kernels; only when native_wide().
|
||||
void experts_native(const WideBatch& b, const NativeGeom& g, int n_expert, int64_t n, const void* scratch, const void* xa,
|
||||
const int32_t* src, void* ha, float* dm, void* stream);
|
||||
|
||||
} // namespace strata::prefill::fused
|
||||
Reference in new issue
Block a user