mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 15:28:40 +00:00
[Engine] prefill tier sort, Volta WMMA, NVLink P2P peer prefill/stage handoffs, and P2P decode scatter
Rebased onto v0.2.16 (26ae4fa2, STRATA_PF_OWN_ONLY / MMQ-free):
- Opt-in STRATA_MMQ_TIER_SORT=1 readiness-tier + row-count expert scheduler (engine/src/prefill/mmq_resident_sort.hpp, engine/src/prefill/prefill.cpp) + unit test mmq_resident_sort_test.
- Re-enable pf_wmma() (STRATA_PF_WMMA=1) on CUDA sm_70+ under STRATA_PF_OWN_ONLY (guarded only for HIP/Metal), and unlock Prefill::set_peer() on STRATA_PF_OWN_ONLY for both native_expert_i8 (48/48 layers, q8_1 P2P) and wmma_l (47/48 layers + Q5_0 fallback on i8), including 35% peer PCIe streaming (all_peer_layers), batched gather_native_group, and fixing P.pk slot advance in peer group gathers.
- Async cross-device cudaEvent_t NVLink P2P stage handoff (p2p_stage) in --layer-split auto (engine/src/prefill/prefill.cpp).
- Direct NVLink P2P decode peer scatter (hit_out_dev) and VRAM stage handoff buffers (hand[si]) (engine/src/core/verify.cpp, engine/src/core/expert_source.cpp, engine/include/strata/core/expert_source.hpp, engine/src/program/generate.cpp).
- Dual Tesla V100-SXM2-16GB (NV6 NVLink) v0.2.15 & v0.2.16 benchmark report and docs/NVIDIA_V100.md notes.
This commit is contained in:
1 parent
26ae4fa2d9
commit
3440d46099
12 files changed
+907
-147
No files matched your search
@@ -60,6 +60,7 @@ None of these is on by default. Each was measured by its contributor on a V100,
|
||||
| `STRATA_FUSE_DECODE=1` | The decode GEMV / MoE fusions of #1097. Bitwise the unfused kernels. |
|
||||
| `STRATA_PF_WMMA=1` | The FP16 tensor-core prompt experts; also takes IQ4_NL down projections. |
|
||||
| `STRATA_PF_WMMA2=1` | A second prompt-expert kernel for IQ2_S gate/up and IQ4_NL down (#2356). |
|
||||
| `STRATA_MMQ_TIER_SORT=1` | Opt-in prompt expert scheduler (`--peer-device` / staged / layer-major / 100%-resident walks). Sorts experts by readiness tier (`0`: VRAM resident -> `1`: pinned host RAM -> `2`: unpinned / file tier) and ascending token count per expert (`order`, keeping `P.pseq` on partial-resident `stream_all` chunks on `GPU 0`). Also enables async NVLink P2P `p2p_stage` in `--layer-split auto` and batched `gather_native_group` + `order_peer_res` + `FP16` `m.mixed_h` under `--peer-device`. |
|
||||
| `STRATA_ARGMAX_ROWS_SM70=1` | The multi-block greedy pick on sm_7x (#2357), bitwise the one-block pick. |
|
||||
| `STRATA_GR_NORM_FAST=1` | The register-split hyper-connection norm (#2358). |
|
||||
| `STRATA_Q8_GATHER_WIDE=0` | Turns off the 8-wide int8 KV gather (#1095) that the experimental build uses below compute capability 7.5. |
|
||||
@@ -110,6 +111,7 @@ Greedy output was identical on the 28,650- and 114,338-token prompts and differe
|
||||
| V100, `STRATA_Q8_GATHER_WIDE=0` | +11% on the gather kernel |
|
||||
| V100, `STRATA_GDN_REC_WARP=2` | +6-9% on the recurrence |
|
||||
| V100, `STRATA_FUSE_DECODE=1` | 4-16 us per token saved, not visible end to end |
|
||||
| Two V100-SXM2-16GB (NV6 NVLink), `v0.2.16` (`STRATA_PF_OWN_ONLY`) + `STRATA_PF_WMMA=1` + `STRATA_MMQ_TIER_SORT=1` | `UD-IQ2_XS` prompt: `--layer-split auto` `2,327.7 -> 2,498.2` tok/s at `64Ki` (`+7.3%`) and `2,161.4 -> 2,297.1` tok/s at `256Ki` (`+6.3%`); `--peer-device 1` `1,569.1 -> 2,098.5` tok/s at `64Ki` (`+33.7%`, `1,977.3` on `int8`) and `1,200.8 -> 1,462.4` tok/s at `256Ki` (`+21.8%`, `1,410.4` on `int8`) ([report](bench-results/2026-11-18-dual-v100-sxm2-256k-mmq/README.md)) |
|
||||
| Tesla P100 alone and with an RTX 2070 SUPER as expert helper (#1069) | 30.5 tok/s alone, 35.8-38.4 with the helper |
|
||||
| Two Tesla P40, layer split (#1028) | [report](bench-results/2026-10-05-community-2x-p40/README.md) |
|
||||
| V100 + P100 pair (#1079) | +6-11% decode from engine 0.1.39 to 0.1.40 with the P100 as helper cache |
|
||||
@@ -0,0 +1,170 @@
|
||||
# Dual NVIDIA Tesla V100-SXM2-16GB (`NV6` NVLink) — `v0.2.15` `-DSTRATA_MMQ=ON` + `STRATA_MMQ_TIER_SORT` + NVLink P2P Evaluation (`64Ki` & `256Ki`)
|
||||
|
||||
Clean single-variable verification of **Strata `v0.2.15` (`c77572806`)** built with `-DSTRATA_ENABLE_CUDA=ON -DSTRATA_EXPERIMENTAL_SM60=ON -DSTRATA_MMQ=ON -DCMAKE_CUDA_ARCHITECTURES=70-real` (self-reporting `engine 0.1.61`, branch `gpuos-tiered-mmq-schedule`) against the prebuilt `v0.2.15` CUDA 12 release (`engine 0.1.60`, `-DSTRATA_MMQ=OFF` / `STRATA_PF_OWN_ONLY`) on a **2 × Tesla V100-SXM2-16GB (`NV6` NVLink)** server at **`64Ki` (`65,536` max context / `63,637` prompt tokens)** and **`256Ki` (`262,144` max context / `257,774` prompt tokens)**.
|
||||
|
||||
All runs use identical model files, `DFlash2` drafter, needle-in-a-haystack prompts (`temperature = 0`, `max_tokens = 1024`), engine-default `STRATA_ROUTE_TAIL_SKIP=7` (unset across every run), and continuous 250 ms DCGM NVLink sampling (`dcgmi dmon -e 1011,1012 -d 250`) alongside per-second `nvidia-smi` thermal/clock/ECC guards.
|
||||
|
||||
---
|
||||
|
||||
## 1. Headline Findings (Isolated Single-Variable Attribution)
|
||||
|
||||
1. **`-DSTRATA_MMQ=ON` on a partial-residency V100 rig (`2 × 16 GiB`, `UD-IQ2_XS`):**
|
||||
- Even with `STRATA_PF_WMMA=0` (`dp4a` MMQ, `STRATA_MMQ_TIER_SORT=0`), enabling `-DSTRATA_MMQ=ON` lifts `--layer-split auto` prefill from **`1,595.5 -> 2,362.7 tok/s` (`+48.1%`) at `64Ki`** and **`1,565.6 -> 2,182.5 tok/s` (`+39.4%`) at `256Ki`** over prebuilt `0.1.60` (`native_expert_i8`).
|
||||
- Adding **`STRATA_PF_WMMA=1` + `STRATA_PF_WMMA2=1`** (Volta FP16 Tensor Core `gemm_iq_f16_grouped` on `47/48` layers; layer `4` `Q5_0` down stays on `dp4a` MMQ) further increases `--layer-split auto` prefill to **`2,490.9 tok/s` at `64Ki`** and **`2,268.0 tok/s` at `256Ki`**.
|
||||
- **Scope vs. 100%-resident Volta setups:** Independent `3 × V100-PCIE-32GB` (`UD-IQ4_XS`, 100% Tier-0) measurements measured `-25.9%` prefill (`2,471.9 -> 1,832.2 tok/s`) from `dp4a` MMQ without `STRATA_PF_WMMA=1`. On a starved-VRAM partial-residency rig (`~50%` host-streamed), `-DSTRATA_MMQ=ON` is strongly positive; on 100%-resident `sm_70` i-quants without `STRATA_PF_WMMA=1`, `-DSTRATA_MMQ=OFF` remains faster.
|
||||
2. **PR `#6023` (`STRATA_MMQ_TIER_SORT=1`) in `--peer-device 1 --peer-reserve-mib 1600`:**
|
||||
- Prebuilt `0.1.60` (`-DSTRATA_MMQ=OFF`) cannot run prompt peer prefill (`prefill peer: needs the MMQ prompt path`) and leaves `GPU 1` idle during prompt ingestion (`993.4 tok/s` at `64Ki`, `834.6 tok/s` at `256Ki`, `0.0 GiB` NVLink).
|
||||
- Flipping **`STRATA_MMQ_TIER_SORT` `0 -> 1`** enables `wmma_l` (`gemm_iq_f16_grouped`), `order_peer_res` row-count sorting, `mmq::gather_native_group`, and **`FP16 m.mixed_h`** P2P copies on `--peer-device 1`, cutting `GPU 0 -> GPU 1` NVLink input traffic in half (**`28.64 -> 14.38 GiB`** at `64Ki`, **`118.33 -> 58.03–58.23 GiB`** at `256Ki`) and lifting peer prefill **`1,775.3 -> 1,894.8 tok/s` (`+6.7%`, `+90.7%` vs `0.1.60`) at `64Ki`** and **`1,369.1 -> 1,423.1 tok/s` (`+3.9%`, `+70.5%` vs `0.1.60`) at `256Ki`**.
|
||||
3. **Direct NVLink P2P Stage Handoff (`p2p_stage`, `--layer-split auto`) & Decode Scatter (`hit_out_dev`, `--peer-device 1`):**
|
||||
- `STRATA_MMQ_TIER_SORT=1` routes `--layer-split auto` chunk activations directly over `NV6` NVLink (`cudaMemcpyPeerAsync`, DCGM `2.26 GiB` RX / `3.06 GiB` TX at `64Ki`, `9.18 GiB` RX / `10.18 GiB` TX at `256Ki`, `3.34–3.36 GB/s` peak vs `0.0 GiB` host bounce), raising prefill to **`2,512.1 tok/s` at `64Ki` (`+57.4%` vs `0.1.60`)** and **`2,301.2 tok/s` at `256Ki` (`+47.0%` vs `0.1.60`)**.
|
||||
- Unconditional P2P decode scatter (`hit_out_dev` when `peer->p2p()` + `direct_mode()`) plus `hand[si]` VRAM state on `--peer-device 1` (`--spec 6 --draft-conf 0.35`) raises decode from **`100.1 -> 106.5–110.5 tok/s`** at `64Ki` and from **`92.7 -> 102.4–102.5 tok/s` (`+10.5–10.6%`) at `256Ki`**. Enforcing `--spec 8 --draft-conf 0.30` via `"user_args"` (`prof-peer1-true-s8-raw`) measured **`106.6 tok/s`** at `64Ki` (`639/1061`, `824` tokens, `stop`), slightly slower than paired `--spec 6 --draft-conf 0.35` (`108.1 tok/s`, `762/1148`), so `--spec 6 --draft-conf 0.35` remains faster on `--peer-device 1`.
|
||||
4. **Honest measurement of `GPU 0` readiness-tier sorting alone on staged chunks (`T < 1024`):**
|
||||
- On isolated `15,725`-token runs forced through `17` staged chunks (`--prefill 960`), flipping `STRATA_MMQ_TIER_SORT` `0 -> 1` measured **`586.3 / 586.4` vs `585.2 / 585.6 tok/s` (`-0.17%`)** in pinned Tier-1 RAM, **`550.0 / 551.2` vs `549.2 / 551.4 tok/s` (`-0.05%`)** with `--mmap-experts` (warm page cache), and **`465.5` vs `467.3 tok/s` (`+0.39%`)** on a natural `2,036`-token prompt. On a `6.2 GB/s` PCIe host link, host-to-device expert DMA dominates `960`-token staged-chunk latency, so `GPU 0` tier-order reordering alone is neutral within run noise.
|
||||
|
||||
---
|
||||
|
||||
## 2. Verified Hardware, OS & Model Configuration
|
||||
|
||||
| Component | Exact Measured Specification |
|
||||
| --- | --- |
|
||||
| **GPUs** | 2 × **NVIDIA Tesla V100-SXM2-16GB** (`16,384 MiB` HBM2 each = `32 GiB` total, `sm_70`, ECC Enabled, Persistence Mode Enabled) |
|
||||
| **Power / Clocks** | Locked `300.00 W` PL, `1,530 MHz` SM / `877 MHz` HBM2 (`nvidia-smi -pm 1 && nvidia-smi -pl 300 && nvidia-smi -ac 877,1530`) |
|
||||
| **NVLink / PCIe Link** | `NV6` (6 × `25.781 GB/s` links active between `GPU0` and `GPU1`); host PCIe probe `6.2 GB/s` H2D |
|
||||
| **Topology (`nvidia-smi topo -m`)** | `GPU0 <-> GPU1 = NV6`; both `GPU0` and `GPU1` report `CPU Affinity 0-17,36-53`, `NUMA Affinity 0` (`GPU NUMA ID N/A`) |
|
||||
| **CPUs** | 2 × **Intel(R) Xeon(R) CPU E5-2695 v4 @ 2.10GHz** (`18` cores / `36` threads per socket = `36C/72T`, `2 × 45 MiB` L3, `performance` governor) |
|
||||
| **System RAM** | `121.5 GiB` usable (`MemTotal = 130,462,416,896 B`, 2 NUMA nodes: node 0 `64,021 MiB`, node 1 `60,397 MiB`, `numactl --interleave=all`) |
|
||||
| **OS / Driver / Toolchain** | **Ubuntu 26.04.1 LTS** (`Linux 7.0.0-43-generic` `x86_64`), Driver **`580.196.07`**, **CUDA `12.9`** (`nvcc V12.9.86`), **`g++-14`** (`Release`) |
|
||||
| **Target Model** | **Qwen3.8-Flash-Next** (`qwen4exp`, GGUF `size_label = 512x56B`), `48` layers, `n_embd = 2560`, `512` experts (`k = 10`, `expert_ff = 640`), `full_attention_interval = 4` |
|
||||
| **GGUF Shards & Param Count** | Unsloth v31 `UD-IQ2_XS` (`3` shards = `101,432,216,218 B` / `94.47 GiB` + `mmproj` BF16 `907,543,008 B`): **`125.74B`** weight elements (`125,743,653,760` across 1,223 tensors) + **`51.20B`** PLE table elements (`320,001,536 × 160` in shard 3) = `176.94B` GGUF elements |
|
||||
| **48-Layer Expert Formats (`native_experts.txt`)** | `(IQ2_XXS, IQ4_NL)`: **3** layers · `(IQ2_XXS, Q2_0)`: **5** layers · `(IQ2_S, IQ4_NL)`: **21** layers · `(IQ2_S, Q2_0)`: **18** layers · **`(IQ2_S, Q5_0)`: 1 layer (layer `4`)** — layer `4` stays on `dp4a` MMQ (`47/48` layers take `STRATA_PF_WMMA=1`) |
|
||||
| **Drafter** | `DFlash2` (`qwen3.8-flash-next-dflash2.q4_0.pack`, `339,694,592 B`, SHA-256 `4df2e5ab2b47c064afbe662e16e4f06569877125c2d0e2123a4ac755266c664c`), `--draft-fallback none --mtp-draft-vocab draft_vocab.bin` |
|
||||
| **CMake Build Flags (PR `#6023` C++/CUDA tree)** | `-DSTRATA_ENABLE_CUDA=ON -DSTRATA_EXPERIMENTAL_SM60=ON -DSTRATA_MMQ=ON -DCMAKE_CUDA_ARCHITECTURES=70-real -DCMAKE_BUILD_TYPE=Release` (SHA-256 `02acd9e55b5f5b02d41afb9bc790e820fd036d1f2cf43ff102ee2151286d670e`) |
|
||||
|
||||
**Shared V100 tuning environment (`V100_BASE_ENV`)** held constant across every comparison run unless overridden by the single variable under test:
|
||||
`STRATA_HC_Q8=1`, `STRATA_SM70_TABLE=1`, `STRATA_FUSE_DECODE=1`, `STRATA_ARGMAX_ROWS_SM70=1`, `STRATA_PIPED_CONCURRENT=1`, `STRATA_B6_MMVQ_ROWS=0`, `STRATA_GDN_REC_WARP=2`, `STRATA_SPLIT_OVERLAP=1`, `STRATA_SELECT_TWO_PASS=1`, `STRATA_GR_NORM_FAST=1`, `STRATA_ADAPT_OVERLAP=1`, `STRATA_ADAPT_ASYNC=1`, `STRATA_NVML=0`, and engine default **`STRATA_ROUTE_TAIL_SKIP=7`** (unset on every run).
|
||||
|
||||
---
|
||||
|
||||
## 3. `64Ki` Context Verification (`63,637` Prompt Tokens, `max-context 65536`)
|
||||
|
||||
Prompt SHA-256: `0ce74e1d42a58d8a90372a6a753205e52283eeb15d751c5851b4f9892bc31dc8` (`temperature = 0`, `max_tokens = 1024`, `--kv int8 --kv-resident 32768 --prefill auto:16384`). All 11 runs returned `3/3` needles (`ALPHA-7284-KITE`, `BRAVO-3916-REED`, `DELTA-8452-MOSS`) with zero throttling (`sw_slow=false`, `hw_slow=false`, `ecc=0`).
|
||||
|
||||
| Run | Mode / Flags | Single Variable Changed | Load (s) | TTFT (s) | Prefill (tok/s) | Decode (tok/s) | Draft Accept | DCGM NVLink Prefill (`0->1` / `1->0` peak) | DCGM NVLink Decode | Peak RAM (GiB) | Peak GPU0 / GPU1 Temp (°C) |
|
||||
| --- | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: |
|
||||
| `0.1.60` prebuilt (`-DSTRATA_MMQ=OFF`) | `--layer-split auto --spec 6 --draft-conf 0.35` | Baseline release (`native_expert_i8`) | 34.52 | 40.00 | **1,595.5** | **100.2** (`1024`) | 759/1130 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 53.09 | 49 / 37 |
|
||||
| `HEAD` (`dp4a` MMQ) | `--layer-split auto --spec 6 --draft-conf 0.35` | `-DSTRATA_MMQ=ON`, `PF_WMMA=0`, `TIER_SORT=0` | 34.51 | 27.04 | **2,362.7** (`+48.1%`) | **97.3** (`1024`) | 746/1150 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 52.94 | 54 / 40 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=0`) | `--layer-split auto --spec 6 --draft-conf 0.35` | `+ STRATA_PF_WMMA=1` + `PF_WMMA2=1` | 34.51 | 25.66 | **2,490.9** (`+56.1%`) | **98.9** (`1024`) | 755/1142 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 53.01 | 56 / 40 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`) | `--layer-split auto --spec 6 --draft-conf 0.35` | `+ STRATA_MMQ_TIER_SORT=1` (`p2p_stage`) | 34.51 | 25.45 | **2,512.1** (`+57.4%`) | **99.9** (`1024`) | 755/1142 | 3.06 TX / 2.26 RX GiB (`3.34` RX, `0->1`) | 0.0 GiB (0.0 GB/s) | 53.04 | 56 / 40 |
|
||||
| `HEAD` minimal env (`TIER_SORT=1`) | `--layer-split auto --spec 6 --draft-conf 0.35` | Only `PF_WMMA=1`, `TIER_SORT=1`, `NVML=0` | 34.51 | 25.85 | **2,472.8** (`+55.0%`) | **98.4** (`1017`) | 753/1124 | 2.26 GiB (`3.35` GB/s pk) | 0.0 GiB (0.0 GB/s) | 52.97 | 56 / 39 |
|
||||
| `0.1.60` prebuilt (`-DSTRATA_MMQ=OFF`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Peer decode only (GPU1 idle in prefill) | 28.52 | 64.16 | **993.4** | **100.1** (`930`) | 698/1016 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 51.84 | 60 / 30 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=0`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Peer prefill (`dp4a` MMQ, FP32 `m.mixed`) + P2P decode | 28.51 | 35.94 | **1,775.3** (`+78.7%`) | **103.3** (`914`) | 661/1072 | 28.64 GiB (`1.62` / `7.83`) | 2.98 GiB (`0.42` GB/s) | 51.46 | 60 / 33 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | `+ STRATA_MMQ_TIER_SORT=1` (`wmma_l` + FP16 `m.mixed_h`) | 28.51 | 33.68 | **1,894.8** (`+90.7%`) | **106.5** (`932`) | 678/1047 | **14.38 GiB (`0.81` / `7.82`)** | 2.80 GiB (`0.42` GB/s) | 51.53 | 61 / 32 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=0`, repeat 2) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Repeat run (`user_args` unset; `TIER_SORT=0`) | 28.51 | 36.02 | **1,771.1** (`+78.3%`) | **110.1** (`1018`) | 751/1124 | 28.23 GiB (`1.63` / `7.39`) | 3.02 GiB (`0.43` GB/s) | 51.69 | 63 / 33 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`, repeat 2) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Repeat run (`user_args` unset; `TIER_SORT=1`) | 28.51 | 33.70 | **1,893.6** (`+90.6%`) | **110.5** (`1024`) | 762/1148 | **14.52 GiB (`0.81` / `7.86`)** | 3.11 GiB (`0.42` GB/s) | 51.45 | 62 / 32 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`, true `s8`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 8 --draft-conf 0.30` | `user_args` `--spec 8 --draft-conf 0.30` (`DECODE_TIMING=1`) | 28.52 | 33.58 | **1,900.6** (`+91.3%`) | **106.6** (`824`) | 639/1061 | **14.94 GiB (`0.82` / `8.08`)** | 2.72 GiB (`0.45` GB/s) | 51.67 | 51 / 31 |
|
||||
|
||||
*(Parenthesized numbers in `Decode` show generated token count before stop/`max_tokens`. The `repeat 2` runs initially passed `--spec 8 --draft-conf 0.30` only inside `"args"` without `"user_args"`, so `strata_control/drafting.py` launched them with `--spec 6 --draft-conf 0.35`, verified from `engine started:` in every log; when `--spec 8 --draft-conf 0.30` was later enforced via `"user_args"`, it measured `106.6 tok/s` vs `108.1 tok/s` in the paired `--spec 6 --draft-conf 0.35` timing run.)*
|
||||
|
||||
---
|
||||
|
||||
## 4. `256Ki` Context Verification (`257,774` Prompt Tokens, `max-context 262144`)
|
||||
|
||||
Prompt SHA-256: `76f94806537bd695d5f599debd5da99a0e5ed871193b09b39e5c7ab2c787b7df` (`temperature = 0`, `max_tokens = 1024`, `--kv int8 --kv-resident 32768 --prefill auto:16384`). All 8 runs returned `3/3` needles (`ALPHA-7284-KITE`, `BRAVO-3916-REED`, `DELTA-8452-MOSS`) with zero throttling or ECC errors.
|
||||
|
||||
| Run | Mode / Flags | Single Variable Changed | Load (s) | TTFT (s) | Prefill (tok/s) | Decode (tok/s) | Draft Accept | DCGM NVLink Prefill (`0->1` / `1->0` peak) | DCGM NVLink Decode | Peak RAM (GiB) | Peak GPU0 / GPU1 Temp (°C) |
|
||||
| --- | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | --- | ---: | ---: |
|
||||
| `0.1.60` prebuilt (`-DSTRATA_MMQ=OFF`) | `--layer-split auto --spec 6 --draft-conf 0.35` | Baseline release (`native_expert_i8`) | 36.02 | 164.99 | **1,565.6** | **92.6** (`1024`) | 759/1151 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 55.70 | 64 / 42 |
|
||||
| `HEAD` (`dp4a` MMQ) | `--layer-split auto --spec 6 --draft-conf 0.35` | `-DSTRATA_MMQ=ON`, `PF_WMMA=0`, `TIER_SORT=0` | 36.01 | 118.43 | **2,182.5** (`+39.4%`) | **93.2** (`1024`) | 761/1154 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 55.65 | 72 / 44 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=0`) | `--layer-split auto --spec 6 --draft-conf 0.35` | `+ STRATA_PF_WMMA=1` + `PF_WMMA2=1` | 36.01 | 113.99 | **2,268.0** (`+44.9%`) | **93.0** (`907`) | 674/986 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 55.67 | 72 / 44 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`) | `--layer-split auto --spec 6 --draft-conf 0.35` | `+ STRATA_MMQ_TIER_SORT=1` (`p2p_stage`) | 36.01 | 112.35 | **2,301.2** (`+47.0%`) | **93.7** (`907`) | 674/986 | 10.18 TX / 9.18 RX GiB (`3.35` RX, `0->1`) | 0.0 GiB (0.0 GB/s) | 55.69 | 73 / 45 |
|
||||
| `0.1.60` prebuilt (`-DSTRATA_MMQ=OFF`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Peer decode only (GPU1 idle in prefill) | 31.51 | 309.17 | **834.6** | **92.7** (`1024`) | 765/1128 | 0.0 GiB (0.0 / 0.0) | 0.0 GiB (0.0 GB/s) | 54.58 | 67 / 31 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=0`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Peer prefill (`dp4a` MMQ, FP32 `m.mixed`) + P2P decode | 31.51 | 188.59 | **1,369.1** (`+64.0%`) | **101.4** (`1024`) | 762/1151 | 118.33 GiB (`1.53` / `7.09`) | 3.07 GiB (`0.38` GB/s) | 54.42 | 75 / 34 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | `+ STRATA_MMQ_TIER_SORT=1` (`wmma_l` + FP16 `m.mixed_h`) | 31.51 | 181.45 | **1,423.1** (`+70.5%`) | **102.5** (`1024`) | 762/1125 | **58.03 GiB (`1.12` / `9.37`)** | 3.09 GiB (`0.38` GB/s) | 54.40 | 75 / 33 |
|
||||
| `HEAD` (`WMMA`, `TIER_SORT=1`, repeat 2) | `--peer-device 1 --peer-reserve-mib 1600 --spec 6` | Repeat run (`user_args` unset; `strata_control` launched `--spec 6 --draft-conf 0.35`) | 31.51 | 181.36 | **1,423.7** (`+70.6%`) | **102.4** (`1024`) | 763/1133 | **60.18 GiB (`1.12` / `8.64`)** | 3.09 GiB (`0.38` GB/s) | 54.42 | 75 / 32 |
|
||||
|
||||
Note on `p2p_stage` (`--layer-split auto` at `256Ki`): `--prefill auto:16384` processes `257,774` tokens in `16` chunks (`15 × 16,384 + 12,014` tokens), transferring `m.R` (`T × 4 × 2,560 × 4 B = 40 KiB/tok`, `640 MiB` per full chunk = **`9.83 GiB`** total theoretical `GPU 0 -> GPU 1` payload; `--peer-device 1` separately picked `14,592`-token chunks); DCGM continuous 250 ms polling measured **`10.18 GiB` TX / `9.18 GiB` RX**.
|
||||
|
||||
---
|
||||
|
||||
## 5. Staged-Chunk Isolation (`T < stream_all_min()`) — Where `GPU 0` Tier Sorting Executes
|
||||
|
||||
On partial-residency chunks `>= 1,024` tokens (`--prefill auto:16384`), `GPU 0` uses `stream_all` (`P.pseq` streaming order) and skips `mmq_resident_sort`. To directly isolate PR `#6023`'s `GPU 0` readiness-tier (`0/1/2`) and row-count sorting on staged chunks (`!stream_all`), interleaved A/B pairs were run on `HEAD` with `STRATA_MMQ_TIER_SORT` flipped `0 <-> 1`:
|
||||
|
||||
| Test Condition (`--layer-split auto`, `max-context 65536`) | Prompt Tokens | `TIER_SORT=0` (tok/s) | `TIER_SORT=1` (tok/s) | Delta |
|
||||
| --- | ---: | ---: | ---: | ---: |
|
||||
| Tier-1 pinned host arena, `--prefill 960`, `STRATA_PREFILL_CPU_SHARE=0` (`r1 / r2`) | 15,725 (`17` chunks) | 586.3 / 586.4 | 585.2 / 585.6 | **-0.17%** (noise) |
|
||||
| Tier-2 `--mmap-experts` (warm page cache), `--prefill 960` (`r1 / r2` after warm-up) | 15,725 (`17` chunks) | 550.0 / 551.2 | 549.2 / 551.4 | **-0.05%** (noise) |
|
||||
| Default pinned arena, `--prefill auto:16384`, default CPU share ON | 2,036 (`1` chunk) | 465.5 | 467.3 | **+0.39%** (noise) |
|
||||
|
||||
---
|
||||
|
||||
## 6. Reference Comparison vs. `1Cat-vLLM v1.5.3` on `Qwen3.8-Flash-Next` (Published `4 × V100-32GB` Numbers vs. This `2 × V100-16GB` Rig)
|
||||
|
||||
`1Cat-vLLM v1.5.3` (`NVFP4 + native MTP4`) requires ~`29.9 / 30.6 GiB` VRAM per GPU across **`4 × V100-SXM2-32GB` (`128 GiB` total VRAM)** (`378,652`-token KV capacity, `262,144` limit) and does not fit `Qwen3.8-Flash-Next` in `2 × 16 GiB` (`32 GiB`) VRAM (their experimental `Flash-Next IQ3_S` profile also targets `4 × 16 GiB = 64 GiB`). On this dual-`16 GiB` machine, `Strata` runs the full `256Ki` context using `32 GiB` VRAM + host RAM:
|
||||
|
||||
| Engine & Hardware | Quant & Drafter | `64Ki` Prefill / TTFT | `256Ki` Prefill / TTFT | `64Ki` Single-Req Decode | `250K–256Ki` Single-Req Decode |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| **`Strata v0.2.15 + PR #6023`** (`2 × V100-SXM2-16GB`, `32 GiB` VRAM + RAM, `--layer-split auto`) | `UD-IQ2_XS + DFlash2` (`--spec 6`) | **2,512.1 tok/s** (`25.45 s`) | **2,301.2 tok/s** (`112.35 s`) | 99.9 tok/s (`1024`) | 93.7 tok/s (`907`) |
|
||||
| **`Strata v0.2.15 + PR #6023`** (`2 × V100-SXM2-16GB`, `32 GiB` VRAM + RAM, `--peer-device 1`) | `UD-IQ2_XS + DFlash2` (`--spec 6`) | **1,894.8 tok/s** (`33.68 s`) | **1,423.1 tok/s** (`181.45 s`) | **106.5–110.5 tok/s** | **102.4–102.5 tok/s** |
|
||||
| **`1Cat-vLLM v1.5.3`** (published `4 × V100-SXM2-32GB`, `128 GiB` VRAM, `TP4`, temp `0`) | `NVFP4 + native MTP4` (FP16 attention KV + host FP8 QSA) | `12.49 s` cold TTFT (~5.2K tok/s) | `61.40 s` cold TTFT at 250K (~4.1K tok/s) | **136 tok/s** measured synthetic (`17.76 ms`/step; 214 at 70% est.) | `19.71 ms`/step (193 at 70% est.; HumanEval `276 tok/s` at 91%) |
|
||||
|
||||
---
|
||||
|
||||
## 7. Unit Tests & Reproduction Commands
|
||||
|
||||
- Header-only scheduler unit tests (`mmq_resident_sort_test.cpp`): compiled on the dual-V100 host (`g++ -std=c++17`) and passed (`mmq_resident_sort_test: ok`).
|
||||
- Settings register check (`python -m unittest tools.test_settings_register`): 8/8 passed.
|
||||
- Docs check (`python tools/check --only docs`): passed (6/6).
|
||||
|
||||
```sh
|
||||
# Build with MMQ enabled for Volta (sm_70)
|
||||
cmake -S . -B build-mmq \
|
||||
-DSTRATA_ENABLE_CUDA=ON \
|
||||
-DSTRATA_EXPERIMENTAL_SM60=ON \
|
||||
-DSTRATA_MMQ=ON \
|
||||
-DCMAKE_CUDA_ARCHITECTURES=70-real \
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build-mmq --target strata -j
|
||||
|
||||
# Launch (256Ki context, --layer-split auto for max prefill; add --peer-device 1 --peer-reserve-mib 1600 instead of --layer-split auto for max decode)
|
||||
STRATA_PF_WMMA=1 STRATA_PF_WMMA2=1 STRATA_MMQ_TIER_SORT=1 \
|
||||
numactl --interleave=all ./build-mmq/strata --serve \
|
||||
--pack /path/to/unsloth-v31-ud-iq2_xs-q8 \
|
||||
--native /path/to/Qwen3.8-Flash-Next-UD-IQ2_XS-00001-of-00003.gguf \
|
||||
--expert-profile /path/to/expert-profile.bin \
|
||||
--expert-cache auto --prefill auto:16384 --max-context 262144 \
|
||||
--kv int8 --ple-io mmap --kv-resident 32768 --pool-workers 32 \
|
||||
--aux-cpus auto --batch-groups auto --vram-reserve-later-mib 1011 \
|
||||
--draft dflash2 --draft-model /path/to/qwen3.8-flash-next-dflash2.q4_0.pack \
|
||||
--draft-fallback none --mtp-draft-vocab /path/to/draft_vocab.bin \
|
||||
--spec 6 --draft-conf 0.35 --vision --layer-split auto
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. `v0.2.16` (`STRATA_PF_OWN_ONLY`, MMQ-Free) Rebase Verification (`64Ki` & `256Ki`)
|
||||
|
||||
After upstream `v0.2.16` (`26ae4fa2` / `58ee322`) removed `-DSTRATA_MMQ`, PR `#6023` was rebased onto `STRATA_PF_OWN_ONLY` with `pf_wmma()` re-enabled for CUDA `sm_70+`, `Prefill::set_peer()` unlocked for both `native_expert_i8` (`48/48` layers, `q8_1` NVLink P2P) and `wmma_l` (`47/48` layers + layer `4` `Q5_0` on `native_expert_i8`) plus `35%` peer PCIe streaming, and async cross-device `cudaEvent_t` handoff for `p2p_stage`.
|
||||
|
||||
Built with CUDA `12.9` (`-DSTRATA_ENABLE_CUDA=ON -DSTRATA_EXPERIMENTAL_SM60=ON -DCMAKE_CUDA_ARCHITECTURES=70-real -DCMAKE_BUILD_TYPE=Release`) on the same `2 × Tesla V100-SXM2-16GB` (`NV6` NVLink) host (`temperature = 0`, `max_tokens = 1024`, `--kv int8 --kv-resident 32768 --prefill auto:16384 --spec 6 --draft-conf 0.35`, `V100_BASE_ENV`). Every run returned `3/3` needles (`ALPHA-7284-KITE`, `BRAVO-3916-REED`, `DELTA-8452-MOSS`) with `0` ECC errors; `STRATA_ADAPT_CHECKRES=1` passed `256/256` windows with `0` mismatches in both `--layer-split auto` and `--peer-device 1`.
|
||||
|
||||
### `64Ki` Context (`61,694` Prompt Tokens, `max-context 65536`, `qwen64-bios-benchmark-prompt.json`)
|
||||
|
||||
| Build & Mode | Key Flags | TTFT (s) | Prefill (tok/s) | Decode (tok/s) | Tokens | Wall (s) |
|
||||
| --- | --- | ---: | ---: | ---: | --- | ---: |
|
||||
| `v0.2.16` `main` (`58ee322`), `--layer-split auto` | `V100_BASE_ENV` | 26.617 | **2,327.7** | **100.9** | 1024 (`length`) | 36.729 |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--layer-split auto` (`WMMA`) | `+ PF_WMMA=1, PF_WMMA2=1, TIER_SORT=1, SIDE_MIXER=2, GRAPH_PRIO=1, FUSE_HITS=1, --pcie-frac 0` | **24.804** | **2,498.2** (`+7.3%`) | **111.1** (`+10.1%`) | 1024 (`length`) | **33.982** |
|
||||
| `v0.2.16` `main` (`58ee322`), `--peer-device 1` | `V100_BASE_ENV` (GPU 1 idle in prefill) | 39.407 | **1,569.1** | **96.3** | 1024 (`length`) | 50.022 |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--peer-device 1` (`WMMA`) | `+ PF_WMMA=1, PF_WMMA2=1, TIER_SORT=1, SIDE_MIXER=2, --pcie-frac 0` | **29.490** | **2,098.5** (`+33.7%`) | **117.6** (`+22.1%`) | 1024 (`length`) | **38.180** |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--peer-device 1` (`int8`) | `+ PF_WMMA=0, TIER_SORT=1, SIDE_MIXER=2` | 31.291 | **1,977.3** (`+26.0%`) | **113.9** (`+18.3%`) | 1024 (`length`) | 40.264 |
|
||||
|
||||
### `256Ki` Context (`257,774` Prompt Tokens, `max-context 262144`, `qwen256-updated-benchmark-prompt.json`)
|
||||
|
||||
| Build & Mode | Key Flags | TTFT (s) | Prefill (tok/s) | Decode (tok/s) | Tokens | Wall (s) |
|
||||
| --- | --- | ---: | ---: | ---: | --- | ---: |
|
||||
| `v0.2.16` `main` (`58ee322`), `--layer-split auto` | `V100_BASE_ENV` | 119.587 | **2,161.4** | **97.7** | 914 (`stop`) | 128.901 |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--layer-split auto` (`WMMA`) | `+ PF_WMMA=1, PF_WMMA2=1, TIER_SORT=1, SIDE_MIXER=2, GRAPH_PRIO=1, FUSE_HITS=1, --pcie-frac 0` | **112.536** | **2,297.1** (`+6.3%`) | **100.4** (`+2.8%`) | 949 (`stop`) | **121.949** |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--layer-split auto` (`int8`) | `+ PF_WMMA=0, TIER_SORT=1, SIDE_MIXER=2, GRAPH_PRIO=1, FUSE_HITS=1, --pcie-frac 0` | 118.485 | **2,182.1** (`+1.0%`) | **107.1** (`+9.6%`) | 1004 (`stop`) | 127.822 |
|
||||
| `v0.2.16` `main` (`58ee322`), `--peer-device 1` | `V100_BASE_ENV` (GPU 1 idle in prefill) | 214.966 | **1,200.8** | **86.5** | 914 (`stop`) | 225.510 |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--peer-device 1` (`WMMA`) | `+ PF_WMMA=1, PF_WMMA2=1, TIER_SORT=1, SIDE_MIXER=2, --pcie-frac 0` | **176.555** | **1,462.4** (`+21.8%`) | **100.8** (`+16.5%`) | 1024 (`length`) | **186.690** |
|
||||
| `v0.2.16` + PR `#6023` + `#6210`, `--peer-device 1` (`int8`) | `+ PF_WMMA=0, TIER_SORT=1, SIDE_MIXER=2, --pcie-frac 0` | 183.076 | **1,410.4** (`+17.5%`) | **108.7** (`+25.7%`) | 917 (`stop`) | 191.494 |
|
||||
@@ -4,7 +4,7 @@ Raw results and short reports from measurement runs, one folder per run, named b
|
||||
the Strata version, hardware and method of its own day, and none is a statement about a later release. Current numbers are in the
|
||||
[docs](../README.md) and the [README](../../README.md); how to measure is in [BENCHMARK_PROTOCOL.md](../BENCHMARK_PROTOCOL.md).
|
||||
|
||||
This page is built by `python tools/bench_results_index.py` (`--check` fails when a folder is missing from it). 143 folders and 3 loose files, 2188 files in all.
|
||||
This page is built by `python tools/bench_results_index.py` (`--check` fails when a folder is missing from it). 144 folders and 3 loose files, 2189 files in all.
|
||||
|
||||
|
||||
## 2026-09
|
||||
@@ -164,6 +164,7 @@ This page is built by `python tools/bench_results_index.py` (`--check` fails whe
|
||||
| Folder | What | Files |
|
||||
| --- | --- | ---: |
|
||||
| [2026-11-14-rdna2-pcie-auto](2026-11-14-rdna2-pcie-auto/) | PcieAuto on gfx103x: the decode miss split from the CPU pool's speed (#4007) | 3 |
|
||||
| [2026-11-18-dual-v100-sxm2-256k-mmq](2026-11-18-dual-v100-sxm2-256k-mmq/) | Dual NVIDIA Tesla V100-SXM2-16GB (NV6 NVLink) — v0.2.15 -DSTRATA_MMQ=ON + STRATA_MMQ_TIER_SORT + NVLink P2P Evaluation (64Ki & 256Ki) | 1 |
|
||||
|
||||
## Loose files
|
||||
|
||||
|
||||
@@ -501,6 +501,11 @@ if(STRATA_BUILD_TESTS)
|
||||
target_include_directories(fused_tq_hip_test PRIVATE include)
|
||||
add_test(NAME fused_tq_hip_test COMMAND fused_tq_hip_test)
|
||||
|
||||
# GPUOS readiness-tier and row-count MMQ expert sorting (src/prefill/mmq_resident_sort.hpp): header-only, no GPU
|
||||
add_executable(mmq_resident_sort_test tests/prefill/mmq_resident_sort_test.cpp)
|
||||
target_include_directories(mmq_resident_sort_test PRIVATE include)
|
||||
add_test(NAME mmq_resident_sort_test COMMAND mmq_resident_sort_test)
|
||||
|
||||
# STRATA_SELECT_TWO_PASS: the bound between the single-pass and 3xTF32 QSA block scores and the cut-off rule that
|
||||
# keeps the selection (header-only, no GPU)
|
||||
add_executable(qsa_two_pass_test tests/prefill/qsa_two_pass_test.cpp)
|
||||
|
||||
@@ -404,6 +404,7 @@ struct GpuPlanSink {
|
||||
/// holds the arena's device alias.
|
||||
int pcie_mode = 0;
|
||||
int32_t cpu_jobs = 0; ///< host only: the distinct experts the pool computes for the layer just published
|
||||
float* hit_out_dev = nullptr; ///< device address of this group's hit_out buffer on the primary GPU (P2P peer scatter)
|
||||
};
|
||||
|
||||
/// Verifier::set_pcie_balance: a verify window's costs, fitted to each layer's measured times (ms, least squares with
|
||||
|
||||
@@ -5025,7 +5025,7 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
const int tail_rank = tail_skip_rank();
|
||||
bool skip_d[kMaxWindowEntries];
|
||||
for (int q = 0; q < nd; ++q) skip_d[q] = false;
|
||||
if (tail_rank > 0 && d.peer == nullptr && d.remote_count == 0) {
|
||||
if (tail_rank > 0 && d.remote_count == 0) {
|
||||
int minr[kMaxWindowEntries];
|
||||
for (int q = 0; q < nd; ++q) minr[q] = 99;
|
||||
for (int64_t i = 0; i < n; ++i) {
|
||||
@@ -5036,7 +5036,8 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
for (int q = 0; q < nd; ++q) {
|
||||
const int32_t e = ids[distinct[q]];
|
||||
if (e < 0 || e >= d.n_expert || minr[q] < tail_rank) continue;
|
||||
if (d.host_res[(size_t) d.layers * (size_t) d.n_expert + (size_t) e] >= 0) continue; // resident
|
||||
if (d.host_res[(size_t) d.layers * (size_t) d.n_expert + (size_t) e] >= 0 ||
|
||||
(d.peer != nullptr && d.peer->has(d.layers, e))) continue; // resident
|
||||
skip_d[q] = true;
|
||||
--nmiss;
|
||||
++d.tail_experts;
|
||||
@@ -5195,6 +5196,11 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
if (ids[i] >= 0 && ids[i] < d.n_expert) d.fetch_mark[(size_t) ids[i]] = 0;
|
||||
}
|
||||
P.start2[fetches] = entries;
|
||||
const bool peer_p2p_hit = d.peer != nullptr && d.peer->p2p() && P.hit_out_dev != nullptr && d.peer->direct_mode();
|
||||
if (peer_p2p_hit) {
|
||||
for (int64_t i = 0; i < n; ++i)
|
||||
if (kind[i] == 2) P.dst[entries++] = (int32_t) i;
|
||||
}
|
||||
P.counts[0] = groups;
|
||||
P.counts[1] = entries;
|
||||
P.counts[2] = fetches;
|
||||
@@ -5213,7 +5219,10 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32
|
||||
}
|
||||
if (d.peer != nullptr) { // multi-GPU: start the second GPU's share before the CPU's own work
|
||||
std::string perr;
|
||||
if (!d.peer->launch(d.layers, x_f, ids, n_tok, k, kind, perr, out)) {
|
||||
float* peer_out = (d.plan != nullptr && d.peer->p2p() && d.plan->hit_out_dev != nullptr && d.peer->direct_mode())
|
||||
? d.plan->hit_out_dev
|
||||
: out;
|
||||
if (!d.peer->launch(d.layers, x_f, ids, n_tok, k, kind, perr, peer_out)) {
|
||||
std::fprintf(stderr, "strata: %s (layer %lld)\n", perr.c_str(), (long long) d.layers);
|
||||
d.failed = true;
|
||||
d.fail = "the peer GPU's experts could not be launched";
|
||||
|
||||
@@ -3840,6 +3840,10 @@ void Verifier::set_plan_slot(int grp) {
|
||||
const int64_t per = G == 2 ? kStagingBlobs / 2 : kStagingBlobs;
|
||||
sink_.staging = (unsigned long long) (staging_ + (size_t) (grp * per) * strata::kernels::cpu::expert_layout().max_blob);
|
||||
sink_.staging_cap = per;
|
||||
const int tb = G == 2 && grp == 1 ? (last_t_ + 1) / 2 : 0;
|
||||
sink_.hit_out_dev = (hit_out_ != nullptr && ss_ != nullptr && g_ != nullptr)
|
||||
? hit_out_ + (size_t) tb * ss_->k * g_->n_embd
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
// Flag B only rises: a host function of an earlier layer may run after a later layer already raised it directly.
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
// Host-only opt-in grouping permutation. No HIP calls, device math, or precision changes.
|
||||
// Host-only opt-in grouping and readiness-tier permutation. No HIP calls, device math, or precision changes.
|
||||
//
|
||||
// Readiness-tier work-queue partitioning (Tier 0 VRAM resident -> Tier 1 pinned host RAM -> Tier 2 unpinned/file
|
||||
// stager) combined with within-tier row-count (length-aware) MMQ group formation is extrapolated from:
|
||||
// - Multi-V-VM/GPUOS: Yiwei Yang, Xiangyu Gao, Yuan Zhou, Yuhang Gan, Yusheng Zheng, and Andi Quinn,
|
||||
// "GPUOS: An Operating-System Architecture for Shared GPU Execution" (https://github.com/Multi-V-VM/GPUOS,
|
||||
// manuscript §3 and §5.3).
|
||||
// - Reza Nourai and Behnam Bastani, "The GPU Needs an Operating System", arXiv:2611.08720
|
||||
// (https://arxiv.org/abs/2611.08720).
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
@@ -29,45 +37,81 @@ inline bool mmq_group_sort_requested() {
|
||||
return on;
|
||||
}
|
||||
|
||||
// How many of `n` ordered experts the sort may move: all of them (STRATA_MMQ_RESIDENT_SORT_NE), or the full groups
|
||||
// of `group` experts (STRATA_MMQ_GROUP_SORT).
|
||||
// STRATA_MMQ_TIER_SORT=1: GPUOS-inspired readiness-tier + row-count expert ordering across staged (!stream_all) and
|
||||
// layer-major (lm_run) MMQ prefill walks on any GPU architecture (from Volta sm_70 V100 through Ada sm_89 and newer).
|
||||
inline bool mmq_tier_sort_requested() {
|
||||
static const bool on = mmq_resident_sort_flag(std::getenv("STRATA_MMQ_TIER_SORT"));
|
||||
return on;
|
||||
}
|
||||
|
||||
// Operand readiness tier for an expert `e`:
|
||||
// 0: VRAM-resident in the expert cache (`layer_resident[e] >= 0`)
|
||||
// 1: Page-locked (pinned) host RAM (`layer_pinned[e] != 0`)
|
||||
// 2: Unpinned host / file tier (staged via background Stager threads)
|
||||
inline int mmq_expert_tier(int32_t e, const int32_t* layer_resident, const char* layer_pinned = nullptr) {
|
||||
if (layer_resident != nullptr && layer_resident[(size_t) e] >= 0) return 0;
|
||||
if (layer_pinned != nullptr && layer_pinned[(size_t) e] != 0) return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// How many of `n` ordered experts the sort may move: all of them (STRATA_MMQ_RESIDENT_SORT_NE / STRATA_MMQ_TIER_SORT),
|
||||
// or the full groups of `group` experts (STRATA_MMQ_GROUP_SORT).
|
||||
inline size_t mmq_resident_sort_span(size_t n, size_t group, bool keep_tail) {
|
||||
return keep_tail && group > 0 ? n - n % group : n;
|
||||
}
|
||||
|
||||
inline bool mmq_resident_sort_eligible(bool requested, bool use_mmq, bool native_layout, bool has_cache,
|
||||
const int32_t* layer_resident, int64_t n_expert,
|
||||
bool stream_all, bool layer_stream_empty) {
|
||||
const int32_t* layer_resident, int64_t n_expert,
|
||||
bool stream_all, bool layer_stream_empty,
|
||||
bool allow_staged_tiers = false) {
|
||||
// native-layout packs too: slot/src/off are built the same way for both layouts, and nothing reads off[e + 1] as a
|
||||
// count (4x GP100, sm_60: 1.2K prompt 7.27 -> 5.32 s, 35K 63.3 -> 54.1 s, the same bits)
|
||||
(void) native_layout;
|
||||
if (!requested || !use_mmq || !has_cache || !layer_resident || n_expert <= 0) return false;
|
||||
// All experts, including unselected ones: leave every partial/streamed layer in ID order.
|
||||
if (stream_all && !layer_stream_empty) return false;
|
||||
if (!requested || !use_mmq || n_expert <= 0) return false;
|
||||
// In the staged walk (!stream_all) with STRATA_MMQ_TIER_SORT=1, bounds_host, Stager jobs (job_of), and stage_one
|
||||
// are all built after `order` is finalized and index by `order[j]` directly, so partially cached and uncached
|
||||
// layers are eligible too.
|
||||
if (allow_staged_tiers && !stream_all) return true;
|
||||
// In the streamed walk (stream_all) or resident-only sort, non-resident experts stream in fixed ascending ID order
|
||||
// (`seq`), so only layers whose experts are all VRAM-resident may reorder `order`.
|
||||
if (!has_cache || !layer_resident || !layer_stream_empty) return false;
|
||||
for (int64_t e = 0; e < n_expert; ++e) if (layer_resident[e] < 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Preconditions are established by the existing caller: IDs were range-checked and counted;
|
||||
// order contains each positive-count expert once in ID order; off has count.size()+1 entries;
|
||||
// order contains each positive-count GPU-local expert once in ID order; off has count.size()+1 entries;
|
||||
// routes fits its original int32 offsets, and slot/src each have routes writable entries.
|
||||
// After sorting, off[e] is an expert-indexed START, not an ID-prefix end at off[e+1].
|
||||
// Only order[0, span) is sorted (span >= order.size(): all of it); the entries after it keep their positions.
|
||||
// When `layer_resident` or `layer_pinned` is supplied, experts in order[0, span) are partitioned by readiness tier
|
||||
// (Tier 0 VRAM resident, Tier 1 pinned host RAM, Tier 2 unpinned/file stager) and sorted by ascending row count
|
||||
// within each tier. On a fully resident layer every expert has tier 0, reducing identically to row-count sort.
|
||||
// Experts outside `order` (e.g. CPU-shared `on_cpu` or peer `on_peer` blocks) keep their existing `off[e]` starts.
|
||||
inline void mmq_resident_sort_rows(const int32_t* ids, int64_t routes, int32_t k,
|
||||
const std::vector<int32_t>& count, std::vector<int32_t>& off,
|
||||
std::vector<int32_t>& order, int32_t* slot, int32_t* src,
|
||||
size_t span = SIZE_MAX) {
|
||||
size_t span = SIZE_MAX,
|
||||
const int32_t* layer_resident = nullptr,
|
||||
const char* layer_pinned = nullptr) {
|
||||
const bool use_tiers = layer_resident != nullptr || layer_pinned != nullptr;
|
||||
std::stable_sort(order.begin(), order.begin() + (ptrdiff_t) std::min(span, order.size()), [&](int32_t a, int32_t b) {
|
||||
if (use_tiers) {
|
||||
const int ta = mmq_expert_tier(a, layer_resident, layer_pinned);
|
||||
const int tb = mmq_expert_tier(b, layer_resident, layer_pinned);
|
||||
if (ta != tb) return ta < tb;
|
||||
}
|
||||
return count[(size_t) a] != count[(size_t) b]
|
||||
? count[(size_t) a] < count[(size_t) b] : a < b;
|
||||
});
|
||||
std::fill(off.begin(), off.end(), 0);
|
||||
for (size_t e = 0; e + 1 < off.size(); ++e)
|
||||
if (count[e] == 0) off[e] = 0;
|
||||
int32_t cursor = 0;
|
||||
for (int32_t e : order) {
|
||||
off[(size_t) e] = cursor;
|
||||
cursor += count[(size_t) e];
|
||||
}
|
||||
off.back() = cursor;
|
||||
if (!off.empty() && (int64_t) cursor == routes) off.back() = cursor;
|
||||
std::vector<int32_t> fill(off.begin(), off.end() - 1);
|
||||
// Preserve token-major/rank-major traversal, hence the original within-expert row order.
|
||||
for (int64_t i = 0; i < routes; ++i) {
|
||||
@@ -78,4 +122,30 @@ inline void mmq_resident_sort_rows(const int32_t* ids, int64_t routes, int32_t k
|
||||
}
|
||||
}
|
||||
|
||||
// Layer-major prefill (`lm_experts`): orders `uniq` by readiness tier (Tier 0 VRAM resident, Tier 1 pinned host RAM,
|
||||
// Tier 2 unpinned/file stager) and by ascending row count `count[e]` within each tier. When `keep_tier2_id_order` is
|
||||
// true (`STRATA_LM_PREFETCH=1`), Tier 2 experts keep ascending ID order so their prefetched `Stager` job indices stay
|
||||
// monotonic for `Stager::pass` and `Stager::issued_one`. Updates `off[e]` as each expert's contiguous row start in
|
||||
// `uniq` order.
|
||||
inline void mmq_lm_sort_uniq(const std::vector<int32_t>& count, std::vector<int32_t>& off,
|
||||
std::vector<int32_t>& uniq, const int32_t* layer_resident,
|
||||
const char* layer_pinned, bool keep_tier2_id_order) {
|
||||
std::stable_sort(uniq.begin(), uniq.end(), [&](int32_t a, int32_t b) {
|
||||
const int ta = mmq_expert_tier(a, layer_resident, layer_pinned);
|
||||
const int tb = mmq_expert_tier(b, layer_resident, layer_pinned);
|
||||
if (ta != tb) return ta < tb;
|
||||
if (ta == 2 && keep_tier2_id_order) return a < b;
|
||||
return count[(size_t) a] != count[(size_t) b]
|
||||
? count[(size_t) a] < count[(size_t) b] : a < b;
|
||||
});
|
||||
for (size_t e = 0; e + 1 < off.size(); ++e)
|
||||
if (count[e] == 0) off[e] = 0;
|
||||
int32_t cursor = 0;
|
||||
for (int32_t e : uniq) {
|
||||
off[(size_t) e] = cursor;
|
||||
cursor += count[(size_t) e];
|
||||
}
|
||||
if (!off.empty()) off.back() = cursor;
|
||||
}
|
||||
|
||||
} // namespace strata::prefill::detail
|
||||
+451
-121
@@ -1293,6 +1293,8 @@ struct PeerPrefill {
|
||||
bool compact = true;
|
||||
int64_t G = 0;
|
||||
void *Xq_g = nullptr, *Hq_g = nullptr;
|
||||
void* fr_xq = nullptr; // OWN-I8: peer's per-token q8_1 activations (T_max * (N/32) * 36)
|
||||
uint8_t* i8_rec = nullptr; // OWN-I8: device launch record (i8grp::kRecBytes)
|
||||
float *GU_g = nullptr, *H_g = nullptr, *Dm_b[2] = {};
|
||||
cudaEvent_t ev_dm[2] = {};
|
||||
bool dm_live[2] = {};
|
||||
@@ -1650,6 +1652,7 @@ struct Prefill::Impl {
|
||||
int hand_pieces = 0;
|
||||
cudaEvent_t hand_done[2] = {};
|
||||
cudaEvent_t hand_ev[2][kHandPiecesMax] = {};
|
||||
cudaEvent_t p2p_ev = nullptr; // layer split: async NVLink P2P hand-off completion event
|
||||
std::unique_ptr<HandWorker> hand_worker; // STRATA_HANDOFF_PIPE: the next stage's chunks' thread (lazily)
|
||||
// C-4: the chunk's token ids on the device, for one batched embedding gather
|
||||
int32_t* tok_dev = nullptr;
|
||||
@@ -1792,6 +1795,7 @@ void Prefill::release() {
|
||||
if (impl_->ple_emb_host[b] && impl_->ple_pageable[b].empty()) cudaFreeHost(impl_->ple_emb_host[b]);
|
||||
if (b == 0 && impl_->ple_raw_dev) { (void) cudaFree(impl_->ple_raw_dev); impl_->ple_raw_dev = nullptr; }
|
||||
}
|
||||
if (impl_->p2p_ev) cudaEventDestroy(impl_->p2p_ev);
|
||||
if (impl_->copy) cudaStreamDestroy(impl_->copy);
|
||||
if (impl_->fr_xq) cudaFree(impl_->fr_xq);
|
||||
if (impl_->fr_rec) cudaFree(impl_->fr_rec);
|
||||
@@ -1907,7 +1911,7 @@ struct MmqPlan {
|
||||
// q8_1, so the answers differ from the default). Only when EVERY visible CUDA card is compute capability 7.0 or
|
||||
// newer: the tiles need tensor cores, and a Volta + Pascal rig (one process, one decision) keeps MMQ.
|
||||
bool pf_wmma() {
|
||||
#if defined(__HIPCC__) || defined(STRATA_PF_OWN_ONLY) // (P4-SPLIT: its layers ride MMQ's grouping)
|
||||
#if defined(__HIPCC__) || defined(STRATA_USE_HIP) || defined(STRATA_GPU_METAL)
|
||||
return false;
|
||||
#else
|
||||
static const bool on = [] {
|
||||
@@ -2093,7 +2097,8 @@ const MmqPlan& mmq_plan() {
|
||||
}
|
||||
// the verdict depends only on the layer's formats and the visible GPUs: taken once here, not per chunk
|
||||
p.group_sort.assign(p.layer.size(), 0);
|
||||
if (on && detail::mmq_group_sort_requested() && !detail::mmq_resident_sort_requested()) {
|
||||
if (on && detail::mmq_group_sort_requested() && !detail::mmq_resident_sort_requested() &&
|
||||
!detail::mmq_tier_sort_requested()) {
|
||||
int64_t ns = 0;
|
||||
for (int64_t l = 0; l < layers; ++l) {
|
||||
if (!p.layer[(size_t) l]) continue;
|
||||
@@ -2106,6 +2111,14 @@ const MmqPlan& mmq_plan() {
|
||||
strata::core::manifest::instance().path("prefill", "mmq-group-sort", ns > 0, ns > 0 ? "STRATA_MMQ_GROUP_SORT=1" : "STRATA_MMQ_GROUP_SORT=1, but whole tiles are not guaranteed on every GPU",
|
||||
std::to_string(ns) + " of " + std::to_string(layers) + " layers");
|
||||
}
|
||||
if (on && detail::mmq_tier_sort_requested()) {
|
||||
int64_t nt = 0;
|
||||
for (int64_t l = 0; l < layers; ++l) nt += p.layer[(size_t) l] ? 1 : 0;
|
||||
std::fprintf(stderr, "strata: prompt MMQ sorts experts by readiness tier and row count (STRATA_MMQ_TIER_SORT=1): "
|
||||
"%lld of %lld layers\n", (long long) nt, (long long) layers);
|
||||
strata::core::manifest::instance().path("prefill", "mmq-tier-sort", nt > 0, "STRATA_MMQ_TIER_SORT=1",
|
||||
std::to_string(nt) + " of " + std::to_string(layers) + " layers");
|
||||
}
|
||||
return p;
|
||||
}();
|
||||
return plan;
|
||||
@@ -3207,6 +3220,18 @@ bool Prefill::bind_stage_helper(int64_t T) {
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool peer_layer_i8_ok(int64_t l) {
|
||||
const auto& lay = strata::kernels::cpu::expert_layout();
|
||||
if (!lay.native || l < 0 || (size_t) l >= lay.fmt.size()) return false;
|
||||
const auto& f = lay.fmt[(size_t) l];
|
||||
if (f.tail_off || f.had_gu || f.had_d || f.n_embd != N || f.n_ff != kFF) return false;
|
||||
const auto L = strata::kernels::native_expert_layout(f.gu_type, f.d_type, f.n_embd, f.n_ff);
|
||||
return L.up_off == f.up_off && L.down_off == f.down_off && L.bytes == f.bytes &&
|
||||
strata::kernels::native_expert_i8_prompt(L, (int64_t) 1 << 20);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool Prefill::set_peer(core::PeerExperts* peer, int64_t cap_rows, std::string& err) {
|
||||
Impl& m = *impl_;
|
||||
if (peer == nullptr || !peer->valid()) { m.pp.reset(); return true; }
|
||||
@@ -3214,13 +3239,31 @@ bool Prefill::set_peer(core::PeerExperts* peer, int64_t cap_rows, std::string& e
|
||||
// (STRATA_PF_PEER_HOST=0: refuse as before, the prompt path then stays on the primary)
|
||||
const bool host_route_ok = [] { const char* v = std::getenv("STRATA_PF_PEER_HOST"); return v == nullptr || std::atoi(v) != 0; }();
|
||||
if (!peer->p2p() && !host_route_ok) { err = "prefill peer: the two GPUs cannot access each other (no P2P)"; return false; }
|
||||
const MmqPlan& mp = mmq_plan();
|
||||
const auto& lay = strata::kernels::cpu::expert_layout();
|
||||
const int64_t n_layers_p = lay.native ? (int64_t) lay.fmt.size() : lay.n_layers;
|
||||
bool any_peer_i8 = false, any_peer_layer = false, all_peer_layers = n_layers_p > 0;
|
||||
for (int64_t l = 0; l < n_layers_p; ++l) {
|
||||
const bool i8_ok = peer_layer_i8_ok(l);
|
||||
if (i8_ok) any_peer_i8 = true;
|
||||
#if defined(STRATA_PF_OWN_ONLY)
|
||||
err = "prefill peer: needs the MMQ prompt path (this engine was built without it)";
|
||||
return false;
|
||||
const bool mmq_ok = mp.any && (size_t) l < mp.layer.size() && mp.layer[(size_t) l] != 0 && pf_wmma();
|
||||
#else
|
||||
const bool mmq_ok = mp.any && (size_t) l < mp.layer.size() && mp.layer[(size_t) l] != 0;
|
||||
#endif
|
||||
if (!mmq_plan().any) { err = "prefill peer: needs the MMQ prompt path"; return false; }
|
||||
const bool ok_l = mmq_ok || i8_ok;
|
||||
if (ok_l) any_peer_layer = true;
|
||||
else all_peer_layers = false;
|
||||
}
|
||||
if (!any_peer_layer) {
|
||||
#if defined(STRATA_PF_OWN_ONLY)
|
||||
err = "prefill peer: no layer supports peer int8 or WMMA prompt kernels";
|
||||
#else
|
||||
err = "prefill peer: needs the MMQ or int8 prompt path";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
{ // NVFP4: the peer's MMQ products have no per-expert scales (grp_tail, row_sd); its decode rows do
|
||||
const auto& lay = strata::kernels::cpu::expert_layout();
|
||||
for (const auto& f : lay.fmt)
|
||||
if (lay.native && f.tail_off) { err = "prefill peer: not for NVFP4 experts yet"; return false; }
|
||||
}
|
||||
@@ -3235,7 +3278,6 @@ bool Prefill::set_peer(core::PeerExperts* peer, int64_t cap_rows, std::string& e
|
||||
pp->T_max = m.T_max;
|
||||
pp->cap_rows = std::max<int64_t>(1, std::min<int64_t>(cap_rows, m.T_max * K));
|
||||
const int64_t R = pp->cap_rows;
|
||||
const MmqPlan& mp = mmq_plan();
|
||||
if (cudaEventCreateWithFlags(&pp->ev_in, cudaEventDisableTiming) != cudaSuccess) { err = "prefill peer: event"; return false; }
|
||||
if (!pp->p2p) { // the host route's copies on a stream of their own (STRATA_PF_PEER_XSTREAM=0: the compute stream)
|
||||
const char* xv = std::getenv("STRATA_PF_PEER_XSTREAM");
|
||||
@@ -3276,16 +3318,27 @@ bool Prefill::set_peer(core::PeerExperts* peer, int64_t cap_rows, std::string& e
|
||||
pp->cap_rows = m.T_max * K; // no row cap: only the row tables grow with it
|
||||
pp->G = m.T_max; // one expert never has more rows than the chunk has tokens
|
||||
const int64_t Gr = pp->G;
|
||||
pp->Xq_g = take(mmq::q8_bytes(Gr, N));
|
||||
pp->Hq_g = take(mmq::q8_bytes(Gr, kFF));
|
||||
#if defined(STRATA_PF_OWN_ONLY)
|
||||
const bool need_mmq_peer_bufs = pf_wmma() && mp.any;
|
||||
#else
|
||||
const bool need_mmq_peer_bufs = mp.any;
|
||||
#endif
|
||||
if (need_mmq_peer_bufs) {
|
||||
pp->Xq_g = take(std::max<size_t>(mmq::q8_bytes(Gr, N), pf_wmma() ? (size_t) Gr * (size_t) N * sizeof(uint16_t) : (size_t) 0));
|
||||
pp->Hq_g = take(mmq::q8_bytes(Gr, kFF));
|
||||
pp->H_g = (float*) take((size_t) Gr * kFF * 4);
|
||||
}
|
||||
if (any_peer_i8) {
|
||||
pp->fr_xq = take((size_t) m.T_max * (size_t) (N / 32) * 36);
|
||||
pp->i8_rec = (uint8_t*) take(strata::prefill::i8grp::kRecBytes);
|
||||
}
|
||||
pp->GU_g = (float*) take((size_t) Gr * kFF2 * 4);
|
||||
pp->H_g = (float*) take((size_t) Gr * kFF * 4);
|
||||
pp->Dm_b[0] = (float*) take((size_t) Gr * N * 4);
|
||||
pp->Dm_b[1] = (float*) take((size_t) Gr * N * 4);
|
||||
for (int b = 0; b < 2 && ok; ++b) ok = cudaEventCreateWithFlags(&pp->ev_dm[b], cudaEventDisableTiming) == cudaSuccess;
|
||||
const char* fs = std::getenv("STRATA_PF_PEER_STREAM");
|
||||
pp->ps_frac = fs ? std::atof(fs) : 0.35; // measured: 0.25-0.5 all ~1950-1970 at 32K, 0.35 best
|
||||
if (pp->ps_frac > 0.0 && !mp.fallback && m.T_max >= stream_all_min()) {
|
||||
if (pp->ps_frac > 0.0 && all_peer_layers && m.T_max >= stream_all_min()) {
|
||||
pp->RP = 48;
|
||||
if (const char* pr = std::getenv("STRATA_PF_PEER_RING"); pr != nullptr) pp->RP = std::atoi(pr);
|
||||
pp->pstage.assign((size_t) pp->RP, nullptr);
|
||||
@@ -3333,8 +3386,8 @@ bool Prefill::set_peer(core::PeerExperts* peer, int64_t cap_rows, std::string& e
|
||||
if (ident_rows == 0) ok = false;
|
||||
pp->ident = (int32_t*) take((size_t) ident_rows * 4);
|
||||
pp->bounds = (int32_t*) take((size_t) (2 * (NE + NE / MMQ_GROUP + 2)) * 4);
|
||||
pp->grp_gu = (uint8_t*) take(MMQ_GROUP * mp.gu_max + MMQ_TAIL);
|
||||
pp->grp_d = (uint8_t*) take(MMQ_GROUP * mp.d_max + MMQ_TAIL);
|
||||
if (mp.gu_max > 0) pp->grp_gu = (uint8_t*) take(MMQ_GROUP * mp.gu_max + MMQ_TAIL);
|
||||
if (mp.d_max > 0) pp->grp_d = (uint8_t*) take(MMQ_GROUP * mp.d_max + MMQ_TAIL);
|
||||
if (ok) {
|
||||
pp->ctx = std::make_unique<mmq::Context>();
|
||||
pp->run_ctx = pp->ctx.get();
|
||||
@@ -4193,7 +4246,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
const auto tsetup = Clock::now();
|
||||
// ---- embeddings, broadcast to the four streams - or, in a later stage of a layer split, the rows the
|
||||
// previous stage handed on
|
||||
if (hand_in_ != nullptr && hand_ev_ != nullptr) {
|
||||
if (hand_in_ != nullptr && hand_ev_ != nullptr && hand_pieces_ > 0) {
|
||||
// STRATA_HANDOFF_PIPE: each piece's upload waits on the GPU for its download on the stage before. The
|
||||
// stage before split the chunk it handed on (n rows); one chunk here is all of it, otherwise (a smaller
|
||||
// chunk here) every piece is waited for before the one copy.
|
||||
@@ -4216,7 +4269,15 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
cudaGetErrorString(cudaGetLastError());
|
||||
return false;
|
||||
}
|
||||
} else if (hand_in_ != nullptr) {
|
||||
} else if (hand_in_ != nullptr && hand_in_ == m.R && hand_ev_ != nullptr) {
|
||||
// Async NVLink P2P stage hand-off: wait on the previous stage's copy event on the GPU stream
|
||||
const auto* ev = static_cast<const cudaEvent_t*>(hand_ev_);
|
||||
if (cudaStreamWaitEvent(m.cs, *ev, 0) != cudaSuccess) {
|
||||
err = std::string("prefill: the layer split's P2P hand-off wait failed: ") +
|
||||
cudaGetErrorString(cudaGetLastError());
|
||||
return false;
|
||||
}
|
||||
} else if (hand_in_ != nullptr && hand_in_ != m.R) {
|
||||
if (cudaMemcpyAsync(m.R, hand_in_ + (size_t) c0 * D, (size_t) T * D * 4, cudaMemcpyHostToDevice, m.cs) !=
|
||||
cudaSuccess) {
|
||||
err = "prefill: the layer split's hand-off upload failed";
|
||||
@@ -5448,7 +5509,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
// --peer-device with MMQ: MMQ only, whether or not the peer took the prompt path (set_peer can decline), as
|
||||
// fused_ring() sized the ring and the buffers for it. Without MMQ the share is always declined: the
|
||||
// kernels the walk picks without the flag, in MMQ's buffer layout (own_only_line.hpp peer_keeps_mmq)
|
||||
const bool no_peer = !strata::prefill::peer_keeps_mmq(core::peer_portable(), kPfOwnOnlyBuild);
|
||||
const bool no_peer = !m.pp && !strata::prefill::peer_keeps_mmq(core::peer_portable(), kPfOwnOnlyBuild);
|
||||
const bool fused_only = mmq_plan().any && mmq_plan().fo[(size_t) l];
|
||||
// a Hadamard-folded layer (APR / Gyro) on the fused kernels: only the trellis pairs (CUDA, STRATA_PF_FUSED_TQ=1: native_supported
|
||||
// answers for them only with it), block 128: the gate/up input rotated into m.Xr as the MMQ path does, the down input
|
||||
@@ -5731,10 +5792,13 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
// it has not issued yet; the walk below gives every unrouted entry back without reading it)
|
||||
if (rs_on) rs_gate.publish(l, m.cnt.data());
|
||||
const bool pre_mmq = mmq_plan().any && mmq_plan().layer[(size_t) l];
|
||||
const bool pre_peer_i8 = m.pp && m.pp->compact && m.pp->fr_xq != nullptr && m.pp->i8_rec != nullptr &&
|
||||
!fused_l && peer_layer_i8_ok(l);
|
||||
const bool pre_peer = pre_mmq || pre_peer_i8;
|
||||
// STRATA_PF_PEER_CPU: an expert the peer computes below (streamed to it, or held by it) is not
|
||||
// the CPU's to take, nor one the primary would stream
|
||||
auto peer_takes = [&](int32_t e) -> bool {
|
||||
if (!m.pp || !pre_mmq) return false;
|
||||
if (!m.pp || !pre_peer) return false;
|
||||
const size_t i = (size_t) l * m.g->n_expert + e;
|
||||
if (!m.pp->ps_flag.empty() && m.pp->ps_flag[i]) return true;
|
||||
return m.pp->peer != nullptr && m.pp->peer->has(l, e);
|
||||
@@ -5777,7 +5841,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
// multi-GPU: the rows of the experts the peer computes go last, as one block [peer_at, T*K)
|
||||
std::vector<char> on_peer;
|
||||
int64_t rows_local = T * K, rows_peer = 0;
|
||||
if (m.pp && pre_mmq) {
|
||||
if (m.pp && pre_peer) {
|
||||
on_peer.assign((size_t) m.g->n_expert, 0);
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e) {
|
||||
const int32_t c = m.cnt[(size_t) e];
|
||||
@@ -5797,7 +5861,17 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
}
|
||||
// STRATA_PF_PEER_CPU: beside the peer the CPU's block goes before the peer's, which stays the tail
|
||||
// (its combine takes every row from back_at on); alone, last as before
|
||||
const bool tier_sort = detail::mmq_tier_sort_requested();
|
||||
const bool cpu_mid = !on_peer.empty() && !on_cpu.empty();
|
||||
std::vector<int32_t> order_peer_res;
|
||||
if (tier_sort && pre_peer && !on_peer.empty()) {
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e)
|
||||
if (m.cnt[(size_t) e] > 0 && on_peer[(size_t) e] == 1) order_peer_res.push_back(e);
|
||||
std::sort(order_peer_res.begin(), order_peer_res.end(), [&](int32_t a, int32_t b) {
|
||||
if (m.cnt[(size_t) a] != m.cnt[(size_t) b]) return m.cnt[(size_t) a] < m.cnt[(size_t) b];
|
||||
return a < b;
|
||||
});
|
||||
}
|
||||
{
|
||||
int32_t r = 0;
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e)
|
||||
@@ -5808,9 +5882,17 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
for (int32_t e = 0; e < m.g->n_expert && cpu_mid; ++e) // the CPU's block, before the peer's
|
||||
if (on_cpu[(size_t) e]) { m.off[(size_t) e] = r; r += m.cnt[(size_t) e]; }
|
||||
// the peer's rows in order_peer's order (peer-held, then peer-streamed): its groups need them contiguous
|
||||
for (int kind = 1; kind <= 2 && !on_peer.empty(); ++kind)
|
||||
if (!order_peer_res.empty()) {
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e)
|
||||
if (on_peer[(size_t) e] == kind) { m.off[(size_t) e] = r; r += m.cnt[(size_t) e]; }
|
||||
if (on_peer[(size_t) e] == 1 && m.cnt[(size_t) e] == 0) m.off[(size_t) e] = r;
|
||||
for (int32_t e : order_peer_res) { m.off[(size_t) e] = r; r += m.cnt[(size_t) e]; }
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e)
|
||||
if (on_peer[(size_t) e] == 2) { m.off[(size_t) e] = r; r += m.cnt[(size_t) e]; }
|
||||
} else {
|
||||
for (int kind = 1; kind <= 2 && !on_peer.empty(); ++kind)
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e)
|
||||
if (on_peer[(size_t) e] == kind) { m.off[(size_t) e] = r; r += m.cnt[(size_t) e]; }
|
||||
}
|
||||
for (int32_t e = 0; e < m.g->n_expert && !on_cpu.empty() && !cpu_mid; ++e) // the CPU's block, last
|
||||
if (on_cpu[(size_t) e]) { m.off[(size_t) e] = r; r += m.cnt[(size_t) e]; }
|
||||
m.off[(size_t) m.g->n_expert] = r;
|
||||
@@ -5827,27 +5909,46 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
}
|
||||
// the experts, in id order: resident ones from VRAM, the others through the staging ring
|
||||
std::vector<int32_t> order, order_peer;
|
||||
if (!order_peer_res.empty()) order_peer = order_peer_res;
|
||||
for (int32_t e = 0; e < m.g->n_expert; ++e)
|
||||
if (m.cnt[(size_t) e] > 0 && (on_peer.empty() || on_peer[(size_t) e] != 2) &&
|
||||
(on_cpu.empty() || !on_cpu[(size_t) e]))
|
||||
(!on_peer.empty() && on_peer[(size_t) e] ? order_peer : order).push_back(e);
|
||||
(on_cpu.empty() || !on_cpu[(size_t) e])) {
|
||||
if (!on_peer.empty() && on_peer[(size_t) e]) {
|
||||
if (order_peer_res.empty()) order_peer.push_back(e);
|
||||
} else {
|
||||
order.push_back(e);
|
||||
}
|
||||
}
|
||||
for (int32_t e = 0; e < m.g->n_expert && !on_peer.empty(); ++e) // the peer-streamed ones last:
|
||||
if (on_peer[(size_t) e] == 2) order_peer.push_back(e); // their copies get the most time
|
||||
// Aurora (STRATA_MMQ_RESIDENT_SORT_NE=1, opt-in): a layer whose experts are ALL resident and
|
||||
// run through MMQ groups takes them in row-count order, so each 16-expert group's max_rows
|
||||
// (its padded tile rows) is close to its experts' own; slot/src/off are rebuilt coherently
|
||||
// before the upload, the routed ids, weights and the within-expert row order stay as they are.
|
||||
// Aurora (STRATA_MMQ_RESIDENT_SORT_NE=1, opt-in) and GPUOS tiered sort (STRATA_MMQ_TIER_SORT=1,
|
||||
// opt-in): MMQ groups take experts partitioned by readiness tier (VRAM resident -> pinned RAM ->
|
||||
// unpinned/file stager) and sorted by row count within each tier, so each 16-expert group's
|
||||
// max_rows (its padded tile rows) is close to its experts' own while ready tiers launch before
|
||||
// host-staged ones; slot/src/off are rebuilt coherently before the upload, and the routed ids,
|
||||
// weights and within-expert row order stay as they are.
|
||||
// STRATA_MMQ_GROUP_SORT=1 (opt-in, exact): the same order for the full groups only, where each
|
||||
// tile is one block's whole K (MmqPlan::group_sort); the partial group keeps its ID order and bits.
|
||||
// STRATA_MMQ_RESIDENT_SORT_NE=1 takes precedence (it sorts the partial group too).
|
||||
const bool sort_all = detail::mmq_resident_sort_requested();
|
||||
// STRATA_MMQ_RESIDENT_SORT_NE=1 / STRATA_MMQ_TIER_SORT=1 take precedence (sorting the partial group too).
|
||||
const bool sort_all = detail::mmq_resident_sort_requested() || tier_sort;
|
||||
const bool sort_full = !sort_all && use_mmq && mmq_plan().group_sort[(size_t) l] &&
|
||||
order.size() >= (size_t) MMQ_GROUP;
|
||||
if (detail::mmq_resident_sort_eligible((sort_all || sort_full) && on_peer.empty(), use_mmq, lay.native,
|
||||
m.cache != nullptr, m.host_res ? m.host_res + (size_t) l * m.g->n_expert : nullptr,
|
||||
m.g->n_expert, stream_all, !stream_all || seq_start[(size_t) l] == seq_start[(size_t) l + 1]))
|
||||
const int32_t* layer_res = m.host_res && m.cache ? m.host_res + (size_t) l * m.g->n_expert : nullptr;
|
||||
if (detail::mmq_resident_sort_eligible(tier_sort || ((sort_all || sort_full) && on_peer.empty()), use_mmq, lay.native,
|
||||
m.cache != nullptr, layer_res, m.g->n_expert, stream_all,
|
||||
!stream_all || seq_start[(size_t) l] == seq_start[(size_t) l + 1], tier_sort)) {
|
||||
std::vector<char> layer_pin;
|
||||
if (tier_sort && !stream_all && m.src != nullptr) {
|
||||
layer_pin.assign((size_t) m.g->n_expert, 0);
|
||||
for (int32_t e : order)
|
||||
if (!layer_res || layer_res[(size_t) e] < 0)
|
||||
layer_pin[(size_t) e] = m.src->pinned(l, e) ? 1 : 0;
|
||||
}
|
||||
detail::mmq_resident_sort_rows(ids_h, T * K, (int32_t) K, m.cnt, m.off, order, slot_h, src_h,
|
||||
detail::mmq_resident_sort_span(order.size(), MMQ_GROUP, sort_full));
|
||||
detail::mmq_resident_sort_span(order.size(), MMQ_GROUP, sort_full),
|
||||
tier_sort ? layer_res : nullptr,
|
||||
layer_pin.empty() ? nullptr : layer_pin.data());
|
||||
}
|
||||
if (grp_mapped) {
|
||||
copy_i32(m.slot_dev, m.grp_dev + m.grp_tk, T * K, m.cs);
|
||||
copy_i32(m.src_dev, m.grp_dev + 2 * m.grp_tk, T * K, m.cs);
|
||||
@@ -5957,9 +6058,10 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
return true;
|
||||
});
|
||||
}
|
||||
// pf_wmma: this layer's groups on the FP16 tensor-core tiles (single GPU, native pack, Q2_0 / IQ4_NL down)
|
||||
const bool wmma_l = use_mmq && pf_wmma() && !fused_l && on_peer.empty() && lay.native &&
|
||||
(mmq_dt == 42 || mmq_dt == 20) && !lay.fmt[(size_t) l].tail_off &&
|
||||
// pf_wmma: this layer's groups on the FP16 tensor-core tiles (single GPU or P2P peer with compact buffers, native pack, Q2_0 / IQ4_NL down)
|
||||
const bool wmma_l = use_mmq && pf_wmma() && !fused_l &&
|
||||
(on_peer.empty() || (m.pp && m.pp->p2p && m.pp->compact && !had_gu && !had_d)) &&
|
||||
lay.native && (mmq_dt == 42 || mmq_dt == 20) && !lay.fmt[(size_t) l].tail_off &&
|
||||
strata::kernels::iq_row_bytes(mmq_gt, N) > 0;
|
||||
if (use_mmq && mmq_plan().wmma_only[(size_t) l] && !wmma_l) {
|
||||
err = "prefill: an IQ1_M layer in the MMQ grouping needs the WMMA tiles, which this chunk cannot take";
|
||||
@@ -6001,9 +6103,12 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
bool i8_l = false;
|
||||
bool i8_few = false; // the few-rows route: the layer's groups run on native_expert_grouped, the activations as quantize_q8_1_rows makes them
|
||||
// (a build without MMQ has no use_mmq layer: the layers the fused kernels do not take come here too, as long as the buffers below exist)
|
||||
if (lay.native && strata::kernels::i8_order_allows(fused_l, fz_staged) && !wmma_l && !had_gu && !had_d && share_keeps_own_kernels(rows_cpu) && on_peer.empty() && !m.pp &&
|
||||
const bool i8_peer_ok = on_peer.empty()
|
||||
? (!m.pp || (m.pp->compact && m.pp->fr_xq != nullptr && m.pp->i8_rec != nullptr))
|
||||
: (m.pp && m.pp->compact && m.pp->fr_xq != nullptr && m.pp->i8_rec != nullptr);
|
||||
if (lay.native && strata::kernels::i8_order_allows(fused_l, fz_staged) && !wmma_l && !had_gu && !had_d && share_keeps_own_kernels(rows_cpu) && i8_peer_ok &&
|
||||
m.group_cap == 0 && (!m.fused_bufs || !stream_all) && !lay.fmt[(size_t) l].tail_off && ws::mode() == 0 &&
|
||||
!(m.cache && mmq_plan().direct[(size_t) l]) && i8_group_env && !order.empty() &&
|
||||
!(m.cache && mmq_plan().direct[(size_t) l]) && i8_group_env && (!order.empty() || !order_peer.empty()) &&
|
||||
(!strata::kernels::native_expert_i8_floor_gated() || strata::kernels::i8_chunk_default_allows(-1, true, true, (int64_t) T, stream_all_min())) && // the P100 class rule: from the stream floor up the unset default is the FP16 path (i8_expert_rule.hpp)
|
||||
m.GU != nullptr && m.Dm != nullptr && m.src_dev != nullptr && m.ids_identity != nullptr &&
|
||||
#if STRATA_EXPERT_NIBBLE_BUILT
|
||||
@@ -6012,28 +6117,38 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
true) {
|
||||
const auto& f = lay.fmt[(size_t) l];
|
||||
i8_L = strata::kernels::native_expert_layout(f.gu_type, f.d_type, f.n_embd, f.n_ff);
|
||||
const int64_t i8_groups = ((int64_t) order.size() + MMQ_GROUP - 1) / MMQ_GROUP;
|
||||
const int64_t i8_experts = (int64_t) order.size() + (int64_t) order_peer.size();
|
||||
const int64_t i8_rows = rows_local + rows_peer;
|
||||
const int64_t i8_groups = (i8_experts + MMQ_GROUP - 1) / MMQ_GROUP;
|
||||
const bool i8_same = i8_L.up_off == f.up_off && i8_L.down_off == f.down_off && i8_L.bytes == f.bytes && f.n_embd == N && f.n_ff == kFF;
|
||||
// The few-rows route (i8_expert_rule.hpp): with it, the size floor of the int8 kernel (256 entries a group) gives way to the crossing; a layer
|
||||
// under it (average rows per expert, over the experts that have rows) runs on the grouped kernels in the same groups, from it up on the int8
|
||||
// kernel. A pair the grouped kernels do not have, or a group whose scratch would not fit the layer's GU rows, keeps the floor.
|
||||
const int i8_fr = i8_same ? strata::kernels::native_expert_i8_few_rows_limit() : 0;
|
||||
i8_l = i8_same && strata::kernels::native_expert_i8_prompt(i8_L, i8_fr > 0 ? strata::kernels::kI8MinGroupEntries : rows_local / i8_groups);
|
||||
if (i8_l && i8_fr > 0 && strata::kernels::i8_fewrows_takes(i8_fr, rows_local, (int64_t) order.size())) {
|
||||
i8_l = i8_same && strata::kernels::native_expert_i8_prompt(i8_L, i8_fr > 0 ? strata::kernels::kI8MinGroupEntries : i8_rows / i8_groups);
|
||||
if (i8_l && i8_fr > 0 && strata::kernels::i8_fewrows_takes(i8_fr, i8_rows, i8_experts)) {
|
||||
int64_t max_rows = 0; // the most rows one group of the walk launches with
|
||||
for (size_t j = 0; j < order.size(); j += (size_t) MMQ_GROUP) {
|
||||
const size_t je = std::min(order.size(), j + (size_t) MMQ_GROUP) - 1;
|
||||
max_rows = std::max<int64_t>(max_rows, (int64_t) m.off[(size_t) order[je]] + m.cnt[(size_t) order[je]] - m.off[(size_t) order[j]]);
|
||||
}
|
||||
int64_t peer_max_rows = 0;
|
||||
for (size_t j = 0; j < order_peer.size(); j += (size_t) MMQ_GROUP) {
|
||||
const size_t je = std::min(order_peer.size(), j + (size_t) MMQ_GROUP) - 1;
|
||||
peer_max_rows = std::max<int64_t>(peer_max_rows, (int64_t) m.off[(size_t) order_peer[je]] + m.cnt[(size_t) order_peer[je]] - m.off[(size_t) order_peer[j]]);
|
||||
}
|
||||
const bool peer_fit = order_peer.empty() ||
|
||||
(m.pp && strata::kernels::native_expert_scratch_bytes(peer_max_rows, kFF) <= (size_t) m.pp->G * (size_t) kFF2 * sizeof(float));
|
||||
if (strata::kernels::native_expert_supported(f.gu_type, f.d_type, f.n_embd, f.n_ff) &&
|
||||
strata::kernels::native_expert_scratch_bytes(max_rows, kFF) <= (size_t) rows_local * (size_t) kFF2 * sizeof(float))
|
||||
(order.empty() || strata::kernels::native_expert_scratch_bytes(max_rows, kFF) <= (size_t) rows_local * (size_t) kFF2 * sizeof(float)) &&
|
||||
peer_fit)
|
||||
i8_few = true;
|
||||
else
|
||||
i8_l = strata::kernels::native_expert_i8_prompt(i8_L, rows_local / i8_groups);
|
||||
i8_l = strata::kernels::native_expert_i8_prompt(i8_L, i8_rows / i8_groups);
|
||||
}
|
||||
if (i8_count_on() && i8_groups > 0) {
|
||||
I8Count& c = i8_count();
|
||||
c.min_avg = std::min<int64_t>(c.min_avg, rows_local / i8_groups);
|
||||
c.min_avg = std::min<int64_t>(c.min_avg, i8_rows / i8_groups);
|
||||
if (i8_l) c.groups_i8 += i8_groups;
|
||||
}
|
||||
}
|
||||
@@ -6227,7 +6342,8 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
if (had_gu) strata::kernels::hadamard_rows_f16(m.Xs, T * K, N, had_block, had_sx, m.cs);
|
||||
}
|
||||
// multi-GPU: the peer's share, enqueued before the primary's own experts so both cards work at once
|
||||
peer_now = use_mmq && !order_peer.empty();
|
||||
const bool peer_i8 = i8_l && !wmma_l && m.pp && m.pp->compact && m.pp->fr_xq != nullptr && m.pp->i8_rec != nullptr;
|
||||
peer_now = (use_mmq || peer_i8) && !order_peer.empty();
|
||||
if (peer_now) {
|
||||
PeerPrefill& P = *m.pp;
|
||||
// the host route's copies beside the compute stream: the primary's own experts start at once
|
||||
@@ -6253,7 +6369,16 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
cudaStreamWaitEvent(ps, P.ev_in, 0);
|
||||
if (P.out_pending) { cudaStreamWaitEvent(ps, P.ev_done, 0); P.out_pending = false; }
|
||||
pe.mark(kPeMoeIn, ps);
|
||||
if (P.p2p) cudaMemcpyPeerAsync(P.mixed, P.dev, m.mixed, prevd, (size_t) T * N * 4, ps);
|
||||
if (peer_i8) {
|
||||
if (P.p2p) {
|
||||
cudaMemcpyPeerAsync(P.fr_xq, P.dev, m.fr_xq, prevd, (size_t) T * (size_t) (N / 32) * 36, ps);
|
||||
} else {
|
||||
if (P.f16) f16_to_f32_wide(P.mixed, P.host_x16, T * N, ps);
|
||||
else copy_f32_wide(P.mixed, P.host_x, T * N, ps);
|
||||
if (i8_few) strata::kernels::quantize_q8_1_rows(P.mixed, T, N, P.fr_xq, ps);
|
||||
else strata::kernels::native_expert_i8_quantize(P.mixed, T, N, P.fr_xq, ps);
|
||||
}
|
||||
} else if (P.p2p) cudaMemcpyPeerAsync(P.mixed, P.dev, wmma_l ? (const void*) m.mixed_h : (const void*) m.mixed, prevd, (size_t) T * N * (wmma_l ? 2 : 4), ps);
|
||||
else if (P.f16) f16_to_f32_wide(P.mixed, P.host_x16, T * N, ps);
|
||||
else copy_f32_wide(P.mixed, P.host_x, T * N, ps);
|
||||
P.back_at = peer_at;
|
||||
@@ -6300,15 +6425,17 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
P.bounds_host[n + 1 + g2 * (MMQ_GROUP + 1) + i] =
|
||||
P.bounds_host[std::min(P.groups[g2].second, P.groups[g2].first + i)] -
|
||||
P.bounds_host[P.groups[g2].first];
|
||||
if (P.p2p || P.bounds_host.size() > PeerPrefill::kHostBounds) {
|
||||
if (P.up_ring.h2d(P.bounds, P.bounds_host.data(), P.bounds_host.size() * 4, ps) != cudaSuccess) { // #1996
|
||||
cudaSetDevice(prevd);
|
||||
err = "prefill: the peer's group bounds upload failed";
|
||||
return false;
|
||||
if (!peer_i8) {
|
||||
if (P.p2p || P.bounds_host.size() > PeerPrefill::kHostBounds) {
|
||||
if (P.up_ring.h2d(P.bounds, P.bounds_host.data(), P.bounds_host.size() * 4, ps) != cudaSuccess) { // #1996
|
||||
cudaSetDevice(prevd);
|
||||
err = "prefill: the peer's group bounds upload failed";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
std::memcpy(P.host_bounds, P.bounds_host.data(), P.bounds_host.size() * 4);
|
||||
copy_i32(P.bounds, P.host_bounds, (int64_t) P.bounds_host.size(), ps);
|
||||
}
|
||||
} else {
|
||||
std::memcpy(P.host_bounds, P.bounds_host.data(), P.bounds_host.size() * 4);
|
||||
copy_i32(P.bounds, P.host_bounds, (int64_t) P.bounds_host.size(), ps);
|
||||
}
|
||||
if (P.sums && P.gather) { // each group's tokens, their row lists in the experts' order
|
||||
P.adds_at.resize(ng);
|
||||
@@ -6351,6 +6478,11 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
const size_t j0 = P.groups[g2].first, j1 = P.groups[g2].second;
|
||||
const int ngx = (int) (j1 - j0);
|
||||
int64_t maxr = 0;
|
||||
mmq::GatherGroup pgg{};
|
||||
const uint8_t* pblob[MMQ_GROUP] = {};
|
||||
int pgg_slots[mmq::kGatherGroupMax] = {};
|
||||
int pgg_nslots = 0;
|
||||
const bool pgg_now = !peer_i8 && tier_sort && lay.native && ngx <= mmq::kGatherGroupMax;
|
||||
for (size_t j = j0; j < j1; ++j) {
|
||||
const int32_t e = order_peer[j];
|
||||
maxr = std::max<int64_t>(maxr, m.cnt[(size_t) e]);
|
||||
@@ -6366,45 +6498,124 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
psl = (int) (P.pk % (size_t) P.RP);
|
||||
cudaStreamWaitEvent(ps, P.pcopied[(size_t) psl], 0);
|
||||
bd = P.pstage[(size_t) psl];
|
||||
++P.pk;
|
||||
++P.ps_experts;
|
||||
} else {
|
||||
bd = P.peer->slot_ptr(l, e);
|
||||
}
|
||||
const size_t q = j - j0;
|
||||
if (lay.native)
|
||||
if (peer_i8) {
|
||||
pblob[q] = bd;
|
||||
if (psl >= 0) pgg_slots[pgg_nslots++] = psl;
|
||||
} else if (pgg_now) {
|
||||
pgg.blob[q] = bd;
|
||||
pgg.n = (int) q + 1;
|
||||
if (psl >= 0) pgg_slots[pgg_nslots++] = psl;
|
||||
} else if (lay.native) {
|
||||
mmq::gather_native(bd, bd + f.up_off, mmq_gub / 2, bd + f.down_off, mmq_db,
|
||||
P.grp_gu + q * mmq_gub, P.grp_d + q * mmq_db, ps);
|
||||
else
|
||||
} else {
|
||||
mmq::gather_strata_q2(bd, P.grp_gu + q * mmq_gub, P.grp_d + q * mmq_db, ps);
|
||||
if (psl >= 0) { // the slot is free once gathered
|
||||
}
|
||||
if (psl >= 0 && !pgg_now && !peer_i8) { // the slot is free once gathered
|
||||
cudaEventRecord(P.pused[(size_t) psl], ps);
|
||||
++P.pk;
|
||||
p_issue_until(P.pk + (size_t) P.RP);
|
||||
}
|
||||
}
|
||||
if (pgg_now && pgg.n > 0) {
|
||||
if (!mmq::gather_native_group(pgg, f.up_off, mmq_gub / 2, f.down_off, mmq_db, P.grp_gu,
|
||||
mmq_gub, P.grp_d, mmq_db, ps, f.tail_off, nullptr, MMQ_TAIL)) {
|
||||
for (int i = 0; i < pgg.n; ++i) {
|
||||
const uint8_t* b = pgg.blob[i];
|
||||
mmq::gather_native(b, b + f.up_off, mmq_gub / 2, b + f.down_off, mmq_db,
|
||||
P.grp_gu + (size_t) i * mmq_gub, P.grp_d + (size_t) i * mmq_db,
|
||||
ps, nullptr, nullptr, i + 1 == pgg.n ? MMQ_TAIL : 0);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < pgg_nslots; ++i)
|
||||
cudaEventRecord(P.pused[(size_t) pgg_slots[i]], ps);
|
||||
if (pgg_nslots > 0) p_issue_until(P.pk + (size_t) P.RP);
|
||||
}
|
||||
const int64_t r0 = P.bounds_host[j0], nr = P.bounds_host[j1] - r0;
|
||||
if (nr <= 0) continue;
|
||||
if (nr <= 0) {
|
||||
if (peer_i8) {
|
||||
for (int i = 0; i < pgg_nslots; ++i)
|
||||
cudaEventRecord(P.pused[(size_t) pgg_slots[i]], ps);
|
||||
if (pgg_nslots > 0) p_issue_until(P.pk + (size_t) P.RP);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const int32_t* rel = P.bounds + n + 1 + g2 * (MMQ_GROUP + 1);
|
||||
cudaMemsetAsync(P.grp_gu + (size_t) ngx * mmq_gub, 0, MMQ_TAIL, ps);
|
||||
cudaMemsetAsync(P.grp_d + (size_t) ngx * mmq_db, 0, MMQ_TAIL, ps);
|
||||
mmq::quantize(P.mixed, P.src + r0, P.Xq_g, mmq_gt, N, N, nr, ps);
|
||||
mmq::Product gu;
|
||||
gu.w = P.grp_gu; gu.type = mmq_gt; gu.w_rows = kFF2; gu.w_cols = N; gu.expert_bytes = mmq_gub;
|
||||
gu.n = ngx; gu.xq = P.Xq_g; gu.bounds = rel; gu.ids = P.ident;
|
||||
gu.total_rows = nr; gu.max_rows = maxr; gu.dst = P.GU_g; gu.ld_dst = kFF2;
|
||||
P.run_ctx->run(gu, ps);
|
||||
mmq::swiglu(P.GU_g, P.H_g, nr, kFF, !lay.native, ps);
|
||||
if (had_d) // APR: folded down weights take H (s * h), on this card as on the primary
|
||||
strata::kernels::hadamard_rows(P.H_g, P.H_g, nr, kFF, had_block, P.had_sh[(size_t) l], ps);
|
||||
mmq::quantize(P.H_g, nullptr, P.Hq_g, mmq_dt, kFF, kFF, nr, ps);
|
||||
if (!pgg_now && !peer_i8) {
|
||||
cudaMemsetAsync(P.grp_gu + (size_t) ngx * mmq_gub, 0, MMQ_TAIL, ps);
|
||||
cudaMemsetAsync(P.grp_d + (size_t) ngx * mmq_db, 0, MMQ_TAIL, ps);
|
||||
}
|
||||
const int b = (int) (g2 & 1);
|
||||
if (P.dm_live[b]) cudaStreamWaitEvent(ps, P.ev_dm[b], 0); // its last rows have left
|
||||
mmq::Product dn;
|
||||
dn.w = P.grp_d; dn.type = mmq_dt; dn.w_rows = N; dn.w_cols = kFF; dn.expert_bytes = mmq_db;
|
||||
dn.n = ngx; dn.xq = P.Hq_g; dn.bounds = rel;
|
||||
dn.ids = P.ident; dn.total_rows = nr; dn.max_rows = maxr; dn.dst = P.Dm_b[b];
|
||||
dn.ld_dst = N;
|
||||
P.run_ctx->run(dn, ps);
|
||||
if (peer_i8) {
|
||||
uint8_t rec_h[strata::prefill::i8grp::kRecBytes] = {};
|
||||
for (int i = 0; i < ngx; ++i) {
|
||||
const unsigned long long ptr = (unsigned long long) (uintptr_t) pblob[i];
|
||||
std::memcpy(rec_h + 8 * (size_t) i, &ptr, 8);
|
||||
const int32_t s_off = (int32_t) (P.bounds_host[j0 + (size_t) i] - r0);
|
||||
std::memcpy(rec_h + strata::prefill::i8grp::kRecStart + 4 * (size_t) i, &s_off, 4);
|
||||
}
|
||||
const int32_t s_end = (int32_t) nr;
|
||||
std::memcpy(rec_h + strata::prefill::i8grp::kRecStart + 4 * (size_t) ngx, &s_end, 4);
|
||||
std::memcpy(rec_h + strata::prefill::i8grp::kRecN, &ngx, 4);
|
||||
if (!strata::kernels::native_expert_i8_put_record(P.i8_rec, rec_h, strata::prefill::i8grp::kRecBytes, ps)) {
|
||||
err = "prefill: the peer int8 expert record upload failed";
|
||||
cudaSetDevice(prevd);
|
||||
return false;
|
||||
}
|
||||
if (i8_few) {
|
||||
strata::kernels::native_expert_grouped(
|
||||
i8_L, (const unsigned long long*) P.i8_rec,
|
||||
(const int32_t*) (P.i8_rec + strata::prefill::i8grp::kRecStart),
|
||||
(const int32_t*) (P.i8_rec + strata::prefill::i8grp::kRecN),
|
||||
P.ident, P.src + r0, ngx, nr, P.fr_xq, (void*) P.GU_g, P.Dm_b[b], ps);
|
||||
} else {
|
||||
strata::kernels::native_expert_i8(
|
||||
i8_L, (const unsigned long long*) P.i8_rec,
|
||||
(const int32_t*) (P.i8_rec + strata::prefill::i8grp::kRecStart),
|
||||
(const int32_t*) (P.i8_rec + strata::prefill::i8grp::kRecN),
|
||||
P.ident, P.src + r0, ngx, nr, P.fr_xq, (void*) P.GU_g, P.Dm_b[b], ps);
|
||||
}
|
||||
for (int i = 0; i < pgg_nslots; ++i)
|
||||
cudaEventRecord(P.pused[(size_t) pgg_slots[i]], ps);
|
||||
if (pgg_nslots > 0) p_issue_until(P.pk + (size_t) P.RP);
|
||||
} else if (wmma_l) {
|
||||
gather_rows16((const uint16_t*) P.mixed, P.src + r0, (uint16_t*) P.Xq_g, nr, N, ps);
|
||||
const bool ok1 = strata::kernels::gemm_iq_f16_grouped(
|
||||
mmq_gt, P.grp_gu, mmq_gub, kFF2, (int) N, (const uint16_t*) P.Xq_g, (int) N, rel,
|
||||
ngx, (int) maxr, P.GU_g, kFF2, ps);
|
||||
swiglu_split_f16(P.GU_g, (uint16_t*) P.H_g, nr, kFF, !lay.native, ps);
|
||||
const bool ok2 = strata::kernels::gemm_iq_f16_grouped(
|
||||
mmq_dt, P.grp_d, mmq_db, (int) N, kFF, (const uint16_t*) P.H_g, kFF, rel, ngx,
|
||||
(int) maxr, P.Dm_b[b], (int) N, ps);
|
||||
if (!ok1 || !ok2) {
|
||||
err = "prefill: the peer WMMA expert tiles could not launch";
|
||||
cudaSetDevice(prevd);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
mmq::quantize(P.mixed, P.src + r0, P.Xq_g, mmq_gt, N, N, nr, ps);
|
||||
mmq::Product gu;
|
||||
gu.w = P.grp_gu; gu.type = mmq_gt; gu.w_rows = kFF2; gu.w_cols = N; gu.expert_bytes = mmq_gub;
|
||||
gu.n = ngx; gu.xq = P.Xq_g; gu.bounds = rel; gu.ids = P.ident;
|
||||
gu.total_rows = nr; gu.max_rows = maxr; gu.dst = P.GU_g; gu.ld_dst = kFF2;
|
||||
P.run_ctx->run(gu, ps);
|
||||
mmq::swiglu(P.GU_g, P.H_g, nr, kFF, !lay.native, ps);
|
||||
if (had_d) // APR: folded down weights take H (s * h), on this card as on the primary
|
||||
strata::kernels::hadamard_rows(P.H_g, P.H_g, nr, kFF, had_block, P.had_sh[(size_t) l], ps);
|
||||
mmq::quantize(P.H_g, nullptr, P.Hq_g, mmq_dt, kFF, kFF, nr, ps);
|
||||
mmq::Product dn;
|
||||
dn.w = P.grp_d; dn.type = mmq_dt; dn.w_rows = N; dn.w_cols = kFF; dn.expert_bytes = mmq_db;
|
||||
dn.n = ngx; dn.xq = P.Hq_g; dn.bounds = rel;
|
||||
dn.ids = P.ident; dn.total_rows = nr; dn.max_rows = maxr; dn.dst = P.Dm_b[b];
|
||||
dn.ld_dst = N;
|
||||
P.run_ctx->run(dn, ps);
|
||||
}
|
||||
if (P.sums && P.gather) { // into the per-token sums, one launch for the group
|
||||
const int32_t* a = P.adds + P.adds_at[g2];
|
||||
const int64_t nt = P.ntok[g2];
|
||||
@@ -6437,15 +6648,17 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
for (size_t i = 0; i <= MMQ_GROUP; ++i)
|
||||
P.bounds_host[n + 1 + g2 * (MMQ_GROUP + 1) + i] =
|
||||
P.bounds_host[std::min(n, g2 * MMQ_GROUP + i)] - P.bounds_host[g2 * MMQ_GROUP];
|
||||
if (P.p2p || P.bounds_host.size() > PeerPrefill::kHostBounds) {
|
||||
if (P.up_ring.h2d(P.bounds, P.bounds_host.data(), P.bounds_host.size() * 4, ps) != cudaSuccess) { // #1996
|
||||
cudaSetDevice(prevd);
|
||||
err = "prefill: the peer's group bounds upload failed";
|
||||
return false;
|
||||
if (!peer_i8) {
|
||||
if (P.p2p || P.bounds_host.size() > PeerPrefill::kHostBounds) {
|
||||
if (P.up_ring.h2d(P.bounds, P.bounds_host.data(), P.bounds_host.size() * 4, ps) != cudaSuccess) { // #1996
|
||||
cudaSetDevice(prevd);
|
||||
err = "prefill: the peer's group bounds upload failed";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
std::memcpy(P.host_bounds, P.bounds_host.data(), P.bounds_host.size() * 4);
|
||||
copy_i32(P.bounds, P.host_bounds, (int64_t) P.bounds_host.size(), ps);
|
||||
}
|
||||
} else {
|
||||
std::memcpy(P.host_bounds, P.bounds_host.data(), P.bounds_host.size() * 4);
|
||||
copy_i32(P.bounds, P.host_bounds, (int64_t) P.bounds_host.size(), ps);
|
||||
}
|
||||
mmq::quantize(P.mixed, P.src, P.Xq, mmq_gt, N, N, rows_peer, ps);
|
||||
pe.mark(kPeMoeGemm, ps);
|
||||
@@ -7019,10 +7232,18 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
if (fz_staged && !order.empty()) fused::group_bounds(m.bounds_dev, (int) order.size(), m.GU, m.cs);
|
||||
const bool stream_ahead = stream_ahead_enabled();
|
||||
const size_t lookahead = group_resident ? (size_t) (STAGE_GRP - MMQ_GROUP - 1) : STAGE - 1;
|
||||
const size_t max_pending = group_resident ? (size_t) (STAGE_GRP - MMQ_GROUP) : (size_t) STAGE;
|
||||
for (size_t j = 0; j < order.size(); ++j) {
|
||||
// Resident experts occupy no staging slot. Keep STAGE actual transfers ahead,
|
||||
// rather than STAGE positions in the mixed resident/streamed order.
|
||||
while (staged < order.size() && (stream_ahead ? pending < STAGE : staged <= j + lookahead)) {
|
||||
// Resident experts occupy no staging slot. Keep max_pending actual transfers ahead,
|
||||
// rather than positions in the mixed resident/streamed order; when grouped, do not
|
||||
// block on a next-group Stager job (`staged >= j1 && job_of[staged] >= 0`) before the
|
||||
// open group `[j0, j1)` is flushed and launched on `m.cs`.
|
||||
const size_t j1 = group_resident
|
||||
? std::min(order.size(), (j / MMQ_GROUP + 1) * (size_t) MMQ_GROUP)
|
||||
: order.size();
|
||||
while (staged < order.size() &&
|
||||
(stream_ahead ? pending < max_pending : staged <= j + lookahead) &&
|
||||
(staged < j1 || job_of[staged] < 0)) {
|
||||
if (!stage_one(staged)) return false;
|
||||
if (stage_of[staged] >= 0) ++pending;
|
||||
++staged;
|
||||
@@ -7245,6 +7466,25 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
// The current hand-off slot was used two chunks ago.
|
||||
float* h = m.hand[hand_buf_];
|
||||
const int hp = m.hand_pieces;
|
||||
bool p2p_stage = false;
|
||||
if (hp == 0 && detail::mmq_tier_sort_requested() && next_->impl_ != nullptr && next_->impl_->device != m.device &&
|
||||
next_->impl_->R != nullptr && T <= next_->impl_->T) {
|
||||
int can01 = 0, can10 = 0;
|
||||
if (cudaDeviceCanAccessPeer(&can01, m.device, next_->impl_->device) == cudaSuccess &&
|
||||
cudaDeviceCanAccessPeer(&can10, next_->impl_->device, m.device) == cudaSuccess && can01 && can10) {
|
||||
int prevd = 0;
|
||||
cudaGetDevice(&prevd);
|
||||
cudaSetDevice(m.device);
|
||||
cudaError_t pe0 = cudaDeviceEnablePeerAccess(next_->impl_->device, 0);
|
||||
if (pe0 == cudaErrorPeerAccessAlreadyEnabled) cudaGetLastError();
|
||||
cudaSetDevice(next_->impl_->device);
|
||||
cudaError_t pe1 = cudaDeviceEnablePeerAccess(m.device, 0);
|
||||
if (pe1 == cudaErrorPeerAccessAlreadyEnabled) cudaGetLastError();
|
||||
cudaSetDevice(prevd);
|
||||
p2p_stage = (pe0 == cudaSuccess || pe0 == cudaErrorPeerAccessAlreadyEnabled) &&
|
||||
(pe1 == cudaSuccess || pe1 == cudaErrorPeerAccessAlreadyEnabled);
|
||||
}
|
||||
}
|
||||
if (hp > 0) {
|
||||
// STRATA_HANDOFF_PIPE: the pieces' downloads stay queued; the host waits for the chunk's work only (the
|
||||
// state on_stage_chunk saves, the error check), the next stage's uploads wait on the pieces' events
|
||||
@@ -7261,6 +7501,11 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
err = std::string("prefill: the layer split's hand-off: ") + cudaGetErrorString(cudaGetLastError());
|
||||
return false;
|
||||
}
|
||||
} else if (p2p_stage) {
|
||||
if (on_stage_chunk && cudaStreamSynchronize(m.cs) != cudaSuccess) {
|
||||
err = std::string("prefill: the layer split's P2P hand-off sync: ") + cudaGetErrorString(cudaGetLastError());
|
||||
return false;
|
||||
}
|
||||
} else if (cudaMemcpyAsync(h, m.R, (size_t) T * D * 4, cudaMemcpyDeviceToHost, m.cs) != cudaSuccess ||
|
||||
cudaStreamSynchronize(m.cs) != cudaSuccess) {
|
||||
err = std::string("prefill: the layer split's hand-off: ") + cudaGetErrorString(cudaGetLastError());
|
||||
@@ -7271,8 +7516,22 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
|
||||
if (on_stage_chunk && !on_stage_chunk(p0 + T, err)) return false;
|
||||
if (next_run_.valid() && !next_run_.get()) { err = next_err_; return false; }
|
||||
next_err_.clear();
|
||||
next_->hand_in_ = h;
|
||||
next_->hand_ev_ = hp > 0 ? static_cast<const void*>(m.hand_ev[hand_buf_]) : nullptr;
|
||||
if (p2p_stage) {
|
||||
if (!m.p2p_ev && cudaEventCreateWithFlags(&m.p2p_ev, cudaEventDisableTiming) != cudaSuccess) {
|
||||
err = std::string("prefill: the layer split's P2P hand-off event: ") + cudaGetErrorString(cudaGetLastError());
|
||||
return false;
|
||||
}
|
||||
if (cudaMemcpyPeerAsync(next_->impl_->R, next_->impl_->device, m.R, m.device, (size_t) T * D * 4, m.cs) != cudaSuccess ||
|
||||
cudaEventRecord(m.p2p_ev, m.cs) != cudaSuccess) {
|
||||
err = std::string("prefill: the layer split's P2P hand-off copy: ") + cudaGetErrorString(cudaGetLastError());
|
||||
return false;
|
||||
}
|
||||
next_->hand_in_ = next_->impl_->R;
|
||||
} else {
|
||||
next_->hand_in_ = h;
|
||||
}
|
||||
next_->hand_ev_ = hp > 0 ? static_cast<const void*>(m.hand_ev[hand_buf_])
|
||||
: (p2p_stage ? static_cast<const void*>(&m.p2p_ev) : nullptr);
|
||||
next_->hand_pieces_ = hp;
|
||||
next_->single_chunk_ = single_chunk;
|
||||
next_->pipe_chunked_ = pipe_chunked;
|
||||
@@ -8075,13 +8334,32 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
if (e < 0 || e >= NE) { err = "prefill (layer-major): routed id out of range"; return false; }
|
||||
++cnt[(size_t) e];
|
||||
}
|
||||
const int mmq_gt = lay.native ? lay.fmt[(size_t) l].gu_type : 42;
|
||||
const int mmq_dt = lay.native ? lay.fmt[(size_t) l].d_type : 42;
|
||||
const bool fz_l = lb.xa != nullptr && lm_fused_layer(l, m.group_cap > 0);
|
||||
// a layer MMQ does not take runs run_impl's FP16 path (port, 2026-10-24): each expert dequantized to FP16 once
|
||||
// per super-chunk, then per entry its rows' FP16 inputs (lb.mixed_h, the bits run_impl's gather reads) through
|
||||
// two FP16 GEMMs into the group's Dm rows; the group's rows are added per token as on the MMQ path
|
||||
const bool fp16_l = !mmq_plan().layer[(size_t) l] && !fz_l; // (fz_l without an MMQ layer: a build without MMQ, a layer of the plan's `fo` set)
|
||||
for (int32_t e = 0; e < NE; ++e) off[(size_t) e + 1] = off[(size_t) e] + cnt[(size_t) e];
|
||||
// ---- the routed experts in id order: resident ones from the cache, the others staged once (run_impl's walk)
|
||||
// ---- the routed experts in id order (or GPUOS readiness-tier + row-count order when STRATA_MMQ_TIER_SORT=1 /
|
||||
// STRATA_MMQ_RESIDENT_SORT_NE=1): resident ones from the cache, the others staged once (run_impl's walk)
|
||||
// (started before the tables are built: the stager's threads read while the host builds them)
|
||||
std::vector<int32_t> uniq;
|
||||
for (int32_t e = 0; e < NE; ++e)
|
||||
if (cnt[(size_t) e] > 0) uniq.push_back(e);
|
||||
auto resident = [&](int32_t e) { return m.host_res && m.cache && m.host_res[(size_t) l * NE + e] >= 0; };
|
||||
if (!fp16_l && !fz_l && detail::mmq_tier_sort_requested()) {
|
||||
const int32_t* layer_res = m.host_res && m.cache ? m.host_res + (size_t) l * NE : nullptr;
|
||||
std::vector<char> layer_pin;
|
||||
if (m.src != nullptr) {
|
||||
layer_pin.assign((size_t) NE, 0);
|
||||
for (int32_t e : uniq)
|
||||
if (!layer_res || layer_res[(size_t) e] < 0)
|
||||
layer_pin[(size_t) e] = m.src->pinned(l, e) ? 1 : 0;
|
||||
}
|
||||
detail::mmq_lm_sort_uniq(cnt, off, uniq, layer_res, layer_pin.empty() ? nullptr : layer_pin.data(), pf_on);
|
||||
}
|
||||
// the stager was started with every streamed expert of the layer when its attention halves began (the
|
||||
// prefetch); an expert the routing skipped is never waited for (a later job's issue covers its buffer)
|
||||
std::vector<int> job_of(uniq.size(), -1), stage_of(uniq.size(), -1);
|
||||
@@ -8127,9 +8405,9 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
}
|
||||
struct Entry { int32_t e, r0, nr; };
|
||||
std::vector<Entry> ents;
|
||||
for (int32_t e = 0; e < NE; ++e)
|
||||
for (int32_t r = off[(size_t) e]; r < off[(size_t) e + 1]; r += (int32_t) G)
|
||||
ents.push_back({e, r, (int32_t) std::min<int64_t>(G, off[(size_t) e + 1] - r)});
|
||||
for (int32_t e : uniq)
|
||||
for (int32_t r = off[(size_t) e]; r < off[(size_t) e] + cnt[(size_t) e]; r += (int32_t) G)
|
||||
ents.push_back({e, r, (int32_t) std::min<int64_t>(G, off[(size_t) e] + cnt[(size_t) e] - r)});
|
||||
struct Grp { size_t j0, j1; int32_t r0, nr, maxr; int64_t b_at, u_at, uo_at, nu; };
|
||||
std::vector<Grp> grps;
|
||||
for (size_t j = 0; j < ents.size();) {
|
||||
@@ -8203,15 +8481,21 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
const float* d_u_w = (const float*) (d_u_rows + rows);
|
||||
ms_host_tables += ms_since(th1);
|
||||
// (the entries' last index per expert, for releasing a staged blob's ring slot)
|
||||
std::vector<size_t> last_ent;
|
||||
std::vector<size_t> last_ent, ent_u(ents.size());
|
||||
for (size_t j = 0; j < ents.size(); ++j) {
|
||||
if (j == 0 || ents[j - 1].e != ents[j].e) last_ent.push_back(j);
|
||||
else last_ent.back() = j;
|
||||
ent_u[j] = last_ent.size() - 1;
|
||||
}
|
||||
// P4-SMALL: a fused layer's group reads its staged experts where they landed (no gather), so their slots stay held until the group's
|
||||
// launch: STAGE_GRP slots, staged no further ahead than the open group allows (as the staged walk's resident groups, STAGE_GRP's note)
|
||||
const bool fz_l = lb.xa != nullptr && lm_fused_layer(l, m.group_cap > 0);
|
||||
const int stage_n = fz_l ? STAGE_GRP : STAGE;
|
||||
// P4-SMALL / MMQ group gather: a fused layer or grouped-MMQ layer holds its open group's staged slots until
|
||||
// the group's launch (`STAGE_GRP` slots).
|
||||
static const bool lm_group_env = [] {
|
||||
const char* v = std::getenv("STRATA_PREFILL_GROUP_GATHER");
|
||||
return v == nullptr || std::atoi(v) != 0;
|
||||
}();
|
||||
const bool group_lm = lm_group_env && !fz_l && !fp16_l && lay.native && MMQ_GROUP <= mmq::kGatherGroupMax;
|
||||
const bool need_grp = fz_l || group_lm;
|
||||
const int stage_n = need_grp ? STAGE_GRP : STAGE;
|
||||
const size_t ahead = fz_l ? (size_t) (STAGE_GRP - MMQ_GROUP - 1) : (size_t) STAGE - 1;
|
||||
int stage_next = 0;
|
||||
auto stage_one = [&](size_t u) -> bool {
|
||||
@@ -8243,14 +8527,11 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
lm_bytes += (uint64_t) lay.blob_bytes(l);
|
||||
return true;
|
||||
};
|
||||
const int mmq_gt = lay.native ? lay.fmt[(size_t) l].gu_type : 42;
|
||||
const int mmq_dt = lay.native ? lay.fmt[(size_t) l].d_type : 42;
|
||||
// a layer MMQ does not take runs run_impl's FP16 path (port, 2026-10-24): each expert dequantized to FP16 once
|
||||
// per super-chunk, then per entry its rows' FP16 inputs (lb.mixed_h, the bits run_impl's gather reads) through
|
||||
// two FP16 GEMMs into the group's Dm rows; the group's rows are added per token as on the MMQ path
|
||||
const bool fp16_l = !mmq_plan().layer[(size_t) l] && !fz_l; // (fz_l without an MMQ layer: a build without MMQ, a layer of the plan's `fo` set)
|
||||
const size_t mmq_gub = fp16_l ? 0 : mmq::matrix_bytes(mmq_gt, kFF2, N), mmq_db = fp16_l ? 0 : mmq::matrix_bytes(mmq_dt, N, kFF);
|
||||
size_t staged = 0, u = 0;
|
||||
const bool stream_ahead = stream_ahead_enabled();
|
||||
const size_t lookahead = group_lm ? (size_t) (STAGE_GRP - MMQ_GROUP - 1) : (fz_l ? ahead : (size_t) STAGE - 1);
|
||||
const size_t max_pending = group_lm ? (size_t) (STAGE_GRP - 4) : (size_t) STAGE;
|
||||
size_t staged = 0, pending = 0, u = 0;
|
||||
const uint8_t* blob_dev = nullptr;
|
||||
size_t gi = 0;
|
||||
int dq = -1; // FP16 path: the dequant slot of the current expert
|
||||
@@ -8264,12 +8545,21 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
fz_geom = fused::NativeGeom{f.gu_type, f.d_type, f.gu_row, f.d_row, f.up_off, f.down_off};
|
||||
fused::quantize_act_native(lb.mixed, Sn, N, lb.xa, cs);
|
||||
}
|
||||
mmq::GatherGroup gg;
|
||||
int gg_slots[MMQ_GROUP];
|
||||
int gg_nslots = 0, gg_wait = -1;
|
||||
for (size_t j = 0; j < ents.size(); ++j) {
|
||||
const int32_t e = ents[j].e;
|
||||
const Grp& gp = grps[gi];
|
||||
if (j == 0 || ents[j - 1].e != e) { // the next expert: staged ahead, waited for, its blob located
|
||||
if (j > 0) ++u;
|
||||
while (staged < uniq.size() && staged <= u + ahead) {
|
||||
const size_t u1 = group_lm ? ent_u[gp.j1 - 1] + 1 : uniq.size();
|
||||
while (staged < uniq.size() &&
|
||||
(fz_l ? (staged <= u + ahead)
|
||||
: ((stream_ahead ? pending < max_pending : staged <= u + lookahead) &&
|
||||
(staged < u1 || job_of[staged] < 0)))) {
|
||||
if (!stage_one(staged)) return false;
|
||||
if (stage_of[staged] >= 0) ++pending;
|
||||
++staged;
|
||||
}
|
||||
if (stage_of[u] < 0) {
|
||||
@@ -8277,15 +8567,16 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
++stats_.experts_resident;
|
||||
++lm_resident;
|
||||
} else {
|
||||
pt.mark(kPfWaitCopy, cs);
|
||||
cudaStreamWaitEvent(cs, m.copied[stage_of[u]], 0);
|
||||
if (!group_lm) {
|
||||
pt.mark(kPfWaitCopy, cs);
|
||||
cudaStreamWaitEvent(cs, m.copied[stage_of[u]], 0);
|
||||
}
|
||||
blob_dev = m.stage_dev[stage_of[u]];
|
||||
}
|
||||
}
|
||||
const Grp& gp = grps[gi];
|
||||
const size_t q = j - gp.j0;
|
||||
pt.mark(kPfDequant, cs);
|
||||
if (fp16_l) {
|
||||
pt.mark(kPfDequant, cs);
|
||||
if (j == 0 || ents[j - 1].e != e) { // the expert's FP16 matrices, once (run_impl's dequant)
|
||||
dq = (dq + 1) % DQ;
|
||||
if (lay.native) {
|
||||
@@ -8300,6 +8591,7 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
if (stage_of[u] >= 0) { // the blob is read by the dequant: its ring slot is free
|
||||
cudaEventRecord(m.used[stage_of[u]], cs);
|
||||
m.used_of[stage_of[u]] = stage_of[u];
|
||||
--pending;
|
||||
}
|
||||
}
|
||||
// this entry's rows (group-relative offset o): FP16 inputs, gate/up, SwiGLU, down
|
||||
@@ -8346,23 +8638,61 @@ bool Prefill::lm_run(const std::vector<Seg>& segs, int depth, const std::vector<
|
||||
core::progress_beat();
|
||||
continue;
|
||||
}
|
||||
if (lay.native) {
|
||||
if (group_lm) {
|
||||
gg.blob[q] = blob_dev;
|
||||
gg.n = (int) q + 1;
|
||||
if (stage_of[u] >= 0) {
|
||||
gg_wait = stage_of[u];
|
||||
if (j == last_ent[u]) {
|
||||
gg_slots[gg_nslots++] = stage_of[u];
|
||||
}
|
||||
}
|
||||
if (j + 1 < gp.j1) continue;
|
||||
const auto& f = lay.fmt[(size_t) l];
|
||||
mmq::gather_native(blob_dev, blob_dev + f.up_off, mmq_gub / 2, blob_dev + f.down_off, mmq_db,
|
||||
m.grp_gu + q * mmq_gub, m.grp_d + q * mmq_db, cs);
|
||||
if (gg_wait >= 0) {
|
||||
pt.mark(kPfWaitCopy, cs);
|
||||
cudaStreamWaitEvent(cs, m.copied[gg_wait], 0);
|
||||
}
|
||||
pt.mark(kPfDequant, cs);
|
||||
if (!mmq::gather_native_group(gg, f.up_off, mmq_gub / 2, f.down_off, mmq_db, m.grp_gu, mmq_gub,
|
||||
m.grp_d, mmq_db, cs, 0, nullptr, MMQ_TAIL)) {
|
||||
for (int i = gg.first; i < gg.n; ++i) {
|
||||
const uint8_t* b = gg.blob[i];
|
||||
mmq::gather_native(b, b + f.up_off, mmq_gub / 2, b + f.down_off, mmq_db,
|
||||
m.grp_gu + (size_t) i * mmq_gub, m.grp_d + (size_t) i * mmq_db, cs,
|
||||
nullptr, nullptr, i + 1 == gg.n ? MMQ_TAIL : 0);
|
||||
}
|
||||
}
|
||||
if (gg_nslots > 0) {
|
||||
const int rel = gg_slots[gg_nslots - 1];
|
||||
cudaEventRecord(m.used[rel], cs);
|
||||
for (int i = 0; i < gg_nslots; ++i) m.used_of[gg_slots[i]] = rel;
|
||||
pending -= (size_t) gg_nslots;
|
||||
}
|
||||
gg = mmq::GatherGroup{};
|
||||
gg_nslots = 0;
|
||||
gg_wait = -1;
|
||||
} else {
|
||||
mmq::gather_strata_q2(blob_dev, m.grp_gu + q * mmq_gub, m.grp_d + q * mmq_db, cs);
|
||||
pt.mark(kPfDequant, cs);
|
||||
if (lay.native) {
|
||||
const auto& f = lay.fmt[(size_t) l];
|
||||
mmq::gather_native(blob_dev, blob_dev + f.up_off, mmq_gub / 2, blob_dev + f.down_off, mmq_db,
|
||||
m.grp_gu + q * mmq_gub, m.grp_d + q * mmq_db, cs);
|
||||
} else {
|
||||
mmq::gather_strata_q2(blob_dev, m.grp_gu + q * mmq_gub, m.grp_d + q * mmq_db, cs);
|
||||
}
|
||||
if (j == last_ent[u] && stage_of[u] >= 0) { // the blob is read: its ring slot is free
|
||||
cudaEventRecord(m.used[stage_of[u]], cs);
|
||||
m.used_of[stage_of[u]] = stage_of[u];
|
||||
--pending;
|
||||
}
|
||||
if (j + 1 < gp.j1) continue;
|
||||
cudaMemsetAsync(m.grp_gu + (size_t) (gp.j1 - gp.j0) * mmq_gub, 0, MMQ_TAIL, cs);
|
||||
cudaMemsetAsync(m.grp_d + (size_t) (gp.j1 - gp.j0) * mmq_db, 0, MMQ_TAIL, cs);
|
||||
}
|
||||
if (j == last_ent[u] && stage_of[u] >= 0) { // the blob is read: its ring slot is free
|
||||
cudaEventRecord(m.used[stage_of[u]], cs);
|
||||
m.used_of[stage_of[u]] = stage_of[u];
|
||||
}
|
||||
if (j + 1 < gp.j1) continue;
|
||||
// ---- the group's products over all of its rows of the super-chunk, then the rows added per token
|
||||
const int ngx = (int) (gp.j1 - gp.j0);
|
||||
pt.mark(kPfGemmGU, cs);
|
||||
cudaMemsetAsync(m.grp_gu + (size_t) ngx * mmq_gub, 0, MMQ_TAIL, cs);
|
||||
cudaMemsetAsync(m.grp_d + (size_t) ngx * mmq_db, 0, MMQ_TAIL, cs);
|
||||
mmq::quantize(lb.mixed, d_row_tok + gp.r0, m.Xq, mmq_gt, N, N, gp.nr, cs);
|
||||
mmq::Product gu;
|
||||
gu.w = m.grp_gu; gu.type = mmq_gt; gu.w_rows = kFF2; gu.w_cols = N; gu.expert_bytes = mmq_gub;
|
||||
|
||||
@@ -12588,14 +12588,46 @@ int main(int argc, char** argv) {
|
||||
: strata::kernels::kVerifyNarrowT;
|
||||
const size_t hb = (size_t) hrows * (size_t) strata::core::Verifier::handoff_floats(g) * sizeof(float);
|
||||
std::vector<float*> hand((size_t) n_stages - 1, nullptr);
|
||||
for (float*& h : hand) {
|
||||
float* hh = nullptr;
|
||||
if (cudaHostAlloc((void**) &hh, hb, cudaHostAllocMapped | cudaHostAllocPortable) != cudaSuccess ||
|
||||
cudaHostGetDevicePointer((void**) &h, hh, 0) != cudaSuccess) {
|
||||
std::fprintf(stderr, "strata serve: the layer-split hand-off allocation failed\n");
|
||||
return 1;
|
||||
for (size_t si = 0; si < hand.size(); ++si) {
|
||||
float*& h = hand[si];
|
||||
const int dev_from = si == 0 ? strata::core::primary_device() : stages[si - 1]->dev;
|
||||
const int dev_to = split_same ? dev_from : stages[si]->dev;
|
||||
bool p2p_allocated = false;
|
||||
if (!split_same && dev_from != dev_to) {
|
||||
int can01 = 0, can10 = 0;
|
||||
if (cudaDeviceCanAccessPeer(&can01, dev_from, dev_to) == cudaSuccess &&
|
||||
cudaDeviceCanAccessPeer(&can10, dev_to, dev_from) == cudaSuccess && can01 && can10) {
|
||||
cudaError_t e0 = cudaSuccess, e1 = cudaSuccess;
|
||||
{
|
||||
const strata::core::OnDevice on0(dev_from);
|
||||
e0 = cudaDeviceEnablePeerAccess(dev_to, 0);
|
||||
if (e0 == cudaErrorPeerAccessAlreadyEnabled) { cudaGetLastError(); e0 = cudaSuccess; }
|
||||
}
|
||||
{
|
||||
const strata::core::OnDevice on1(dev_to);
|
||||
e1 = cudaDeviceEnablePeerAccess(dev_from, 0);
|
||||
if (e1 == cudaErrorPeerAccessAlreadyEnabled) { cudaGetLastError(); e1 = cudaSuccess; }
|
||||
}
|
||||
if (e0 == cudaSuccess && e1 == cudaSuccess) {
|
||||
const strata::core::OnDevice on_dst(dev_to);
|
||||
if (cudaMalloc((void**) &h, hb) == cudaSuccess && cudaMemset(h, 0, hb) == cudaSuccess) {
|
||||
p2p_allocated = true;
|
||||
} else {
|
||||
cudaGetLastError();
|
||||
if (h != nullptr) { cudaFree(h); h = nullptr; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!p2p_allocated) {
|
||||
float* hh = nullptr;
|
||||
if (cudaHostAlloc((void**) &hh, hb, cudaHostAllocMapped | cudaHostAllocPortable) != cudaSuccess ||
|
||||
cudaHostGetDevicePointer((void**) &h, hh, 0) != cudaSuccess) {
|
||||
std::fprintf(stderr, "strata serve: the layer-split hand-off allocation failed\n");
|
||||
return 1;
|
||||
}
|
||||
std::memset(hh, 0, hb);
|
||||
}
|
||||
std::memset(hh, 0, hb);
|
||||
}
|
||||
// STRATA_SPLIT_OVERLAP=1 (opt-in; measured on 2x RX 7900 XTX only): a ready word per hand-off, raised by the
|
||||
// writing stage's GPU, so the next stage's window is launched early and the host never syncs between
|
||||
@@ -14159,6 +14191,7 @@ int main(int argc, char** argv) {
|
||||
// misses are cheap and the skip costs more draft acceptance (70.1% -> 68.2%) than it saves: -1..2% decode. No default then.
|
||||
size_t cached_experts = 0;
|
||||
for (int32_t r : host_res) cached_experts += r >= 0 ? 1 : 0;
|
||||
if (peer.valid()) cached_experts += (size_t) peer.resident();
|
||||
// (STRATA_TAIL_SKIP_MAX_CACHED=<percent>, default 90, moves the line; 101 = never). 0.1.43: 60 on a HIP layer split, where
|
||||
// 2x R9700 (5 pairs, skip on vs off): Q2_0 story -6.2% at 70% cached, -1.8% at 60%; IQ3_S +6..15% at 44-52%, about 0 at 60%.
|
||||
#if defined(STRATA_USE_HIP)
|
||||
@@ -14179,13 +14212,12 @@ int main(int argc, char** argv) {
|
||||
nvfp4_experts = nvfp4_experts || f.gu_type == strata::kernels::cpu::kNvfp4Type ||
|
||||
f.d_type == strata::kernels::cpu::kNvfp4Type;
|
||||
const bool tail_default_path = tse == nullptr && !all_experts_resident && !nearly_all_cached && o.batch == 0 &&
|
||||
decode_defaults_arch_ok() &&
|
||||
o.peer_device < 0;
|
||||
decode_defaults_arch_ok();
|
||||
const bool tail_default_ok = tail_default_path && !nvfp4_experts;
|
||||
if (tail_default_path && nvfp4_experts)
|
||||
std::fprintf(stderr, "strata serve: STRATA_ROUTE_TAIL_SKIP is off by default with NVFP4 experts (it moved an NVFP4 "
|
||||
"pack's answers by about as much as its quantization does); STRATA_ROUTE_TAIL_SKIP=7 turns it on\n");
|
||||
if (tse == nullptr && nearly_all_cached && o.batch == 0 && o.peer_device < 0 && decode_defaults_arch_ok())
|
||||
if (tse == nullptr && nearly_all_cached && o.batch == 0 && decode_defaults_arch_ok())
|
||||
std::fprintf(stderr, "strata serve: STRATA_ROUTE_TAIL_SKIP is off by default: %.1f%% of the experts are in the GPU cache, so "
|
||||
"few are missed and skipping them costs more draft acceptance than it saves; "
|
||||
"STRATA_ROUTE_TAIL_SKIP=7 turns it on\n", 100.0 * (double) cached_experts / (double) host_res.size());
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// Readiness-tier and row-count MMQ expert sorting (src/prefill/mmq_resident_sort.hpp): header-only, no GPU.
|
||||
#include "../../src/prefill/mmq_resident_sort.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace d = strata::prefill::detail;
|
||||
|
||||
static int failed = 0;
|
||||
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
|
||||
|
||||
int main() {
|
||||
// 1. Eligibility on streamed vs staged walks
|
||||
{
|
||||
const int32_t all_res[4] = {0, 1, 2, 3};
|
||||
const int32_t part_res[4] = {0, -1, 2, -1};
|
||||
CHECK(d::mmq_resident_sort_eligible(true, true, true, true, all_res, 4, true, true));
|
||||
CHECK(!d::mmq_resident_sort_eligible(true, true, true, true, part_res, 4, true, true));
|
||||
CHECK(!d::mmq_resident_sort_eligible(true, true, true, true, all_res, 4, true, false));
|
||||
// Staged walk (!stream_all): resident-only sort still requires all-resident unless allow_staged_tiers=true
|
||||
CHECK(!d::mmq_resident_sort_eligible(true, true, true, true, part_res, 4, false, true, false));
|
||||
CHECK(d::mmq_resident_sort_eligible(true, true, true, true, part_res, 4, false, true, true));
|
||||
CHECK(d::mmq_resident_sort_eligible(true, true, true, false, nullptr, 4, false, true, true));
|
||||
CHECK(!d::mmq_resident_sort_eligible(false, true, true, true, all_res, 4, false, true, true));
|
||||
CHECK(!d::mmq_resident_sort_eligible(true, false, true, true, all_res, 4, false, true, true));
|
||||
}
|
||||
|
||||
// 2. Readiness-tier + row-count sort with partial tail group kept and CPU-shared expert offsets preserved
|
||||
{
|
||||
// 7 routed experts: 6 GPU-local (group size 4 -> span = 4, tail = 2) and 1 CPU-shared (expert 6)
|
||||
// GPU-local experts in ID order: 0, 1, 2, 3 (in span 0..4), 4, 5 (in tail 4..6)
|
||||
// Counts: e0=5 (Tier 2), e1=3 (Tier 1), e2=4 (Tier 0), e3=1 (Tier 0), e4=2, e5=1, e6(CPU)=2
|
||||
const int32_t res[7] = {-1, -1, 10, 11, -1, -1, -1};
|
||||
const char pin[7] = {0, 1, 0, 0, 1, 0, 1};
|
||||
std::vector<int32_t> count = {5, 3, 4, 1, 2, 1, 2};
|
||||
// Build routes (K = 2, T = 9 -> 18 routes)
|
||||
std::vector<int32_t> ids = {
|
||||
0, 2, 1, 0, 2, 3, 0, 1, 4, 6, 0, 2, 1, 4, 0, 5, 2, 6
|
||||
};
|
||||
const int64_t routes = (int64_t) ids.size();
|
||||
const int32_t K = 2;
|
||||
std::vector<int32_t> order = {0, 1, 2, 3, 4, 5};
|
||||
std::vector<int32_t> off(8, 0);
|
||||
int32_t r = 0;
|
||||
for (int32_t e : order) { off[(size_t) e] = r; r += count[(size_t) e]; }
|
||||
const int32_t cpu_off = r; // 16
|
||||
off[6] = r; r += count[6]; // 16..18
|
||||
off[7] = r; // 18
|
||||
|
||||
std::vector<int32_t> slot((size_t) routes, -1), src((size_t) routes, -1);
|
||||
const size_t span = d::mmq_resident_sort_span(order.size(), 4, true);
|
||||
CHECK(span == 4);
|
||||
d::mmq_resident_sort_rows(ids.data(), routes, K, count, off, order, slot.data(), src.data(), span, res, pin);
|
||||
|
||||
// Expected order[0..4): Tier 0 sorted by count (e3:1, e2:4), then Tier 1 (e1:3), then Tier 2 (e0:5)
|
||||
// Expected tail order[4..6): unchanged (e4, e5)
|
||||
CHECK(order.size() == 6);
|
||||
CHECK(order[0] == 3 && order[1] == 2 && order[2] == 1 && order[3] == 0);
|
||||
CHECK(order[4] == 4 && order[5] == 5);
|
||||
|
||||
// Offsets for GPU-local experts follow `order`, and CPU-shared expert 6 keeps `cpu_off` (16)
|
||||
CHECK(off[3] == 0);
|
||||
CHECK(off[2] == 1);
|
||||
CHECK(off[1] == 5);
|
||||
CHECK(off[0] == 8);
|
||||
CHECK(off[4] == 13);
|
||||
CHECK(off[5] == 15);
|
||||
CHECK(off[6] == cpu_off);
|
||||
CHECK(off[7] == 18);
|
||||
|
||||
// Every route i maps to a valid row inside its expert's [off[e], off[e] + count[e]) and src[slot[i]] == i / K
|
||||
std::vector<int32_t> seen((size_t) routes, 0);
|
||||
for (int64_t i = 0; i < routes; ++i) {
|
||||
const int32_t e = ids[(size_t) i];
|
||||
const int32_t p = slot[(size_t) i];
|
||||
CHECK(p >= off[(size_t) e] && p < off[(size_t) e] + count[(size_t) e]);
|
||||
CHECK(src[(size_t) p] == (int32_t) (i / K));
|
||||
++seen[(size_t) p];
|
||||
}
|
||||
for (int32_t v : seen) CHECK(v == 1);
|
||||
}
|
||||
|
||||
// 3. Layer-major `mmq_lm_sort_uniq` with and without Tier 2 ID-order preservation
|
||||
{
|
||||
const int32_t res[6] = {-1, 0, -1, -1, 1, -1};
|
||||
const char pin[6] = {0, 0, 1, 0, 0, 1};
|
||||
const std::vector<int32_t> count = {8, 5, 4, 2, 1, 9};
|
||||
// Tiers: e0=T2(8), e1=T0(5), e2=T1(4), e3=T2(2), e4=T0(1), e5=T1(9)
|
||||
std::vector<int32_t> uniq_pf = {0, 1, 2, 3, 4, 5}, off_pf(7, 0);
|
||||
d::mmq_lm_sort_uniq(count, off_pf, uniq_pf, res, pin, true);
|
||||
// Tier 0 sorted by count: 4(1), 1(5); Tier 1 sorted by count: 2(4), 5(9); Tier 2 in ID order: 0(8), 3(2)
|
||||
CHECK(uniq_pf[0] == 4 && uniq_pf[1] == 1);
|
||||
CHECK(uniq_pf[2] == 2 && uniq_pf[3] == 5);
|
||||
CHECK(uniq_pf[4] == 0 && uniq_pf[5] == 3);
|
||||
CHECK(off_pf[4] == 0 && off_pf[1] == 1 && off_pf[2] == 6 && off_pf[5] == 10 && off_pf[0] == 19 && off_pf[3] == 27 && off_pf[6] == 29);
|
||||
|
||||
std::vector<int32_t> uniq_nopf = {0, 1, 2, 3, 4, 5}, off_nopf(7, 0);
|
||||
d::mmq_lm_sort_uniq(count, off_nopf, uniq_nopf, res, pin, false);
|
||||
// Tier 2 also sorted by count: 3(2), 0(8)
|
||||
CHECK(uniq_nopf[4] == 3 && uniq_nopf[5] == 0);
|
||||
CHECK(off_nopf[3] == 19 && off_nopf[0] == 21 && off_nopf[6] == 29);
|
||||
}
|
||||
|
||||
if (failed == 0) std::printf("mmq_resident_sort_test: ok\n");
|
||||
return failed ? 1 : 0;
|
||||
}
|
||||
@@ -19927,6 +19927,36 @@
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
{
|
||||
"name": "STRATA_MMQ_TIER_SORT",
|
||||
"backends": [
|
||||
"cuda-hip"
|
||||
],
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/prefill/mmq_resident_sort.hpp",
|
||||
"line": 43,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
],
|
||||
"parse": "string",
|
||||
"default_state": null,
|
||||
"code_default": null,
|
||||
"engine_sets": [],
|
||||
"engine_defaults": [],
|
||||
"launch_files": [],
|
||||
"launch_sets": [],
|
||||
"launch_reads": [],
|
||||
"doc_mentions": [
|
||||
"docs/NVIDIA_V100.md"
|
||||
],
|
||||
"status": "research",
|
||||
"owner": "prefill",
|
||||
"note": "GPUOS-inspired readiness-tier + row-count prompt expert sorting across staged and layer-major prefill walks plus NVLink P2P p2p_stage / peer wmma_l; off unless set",
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
{
|
||||
"name": "STRATA_MMQ_WS",
|
||||
"backends": [
|
||||
|
||||
Reference in new issue
Block a user