[PR #261] [MERGED] Pascal sm_60 (Tesla P100, GP100): the engine builds - __dp4a as four vmad below sm_61, __grid_constant__ from sm_70 - and four GP100 decode kernels, Maya-M on four GP100 dies 21.0 -> 28.2 tok/s, the same answers #432

Closed
opened 2026-10-29 21:25:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/261
Author: @ruibeikaa
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/20/2026
Merged by: @mw00

Base: main ← Head: sm60-p100


📝 Commits (5)

  • a7f3375 Pascal sm_60 (Tesla P100, GP100) builds: __dp4a by name maps to four vmad below sm_61 and grid_constant drops below sm_70 - v1.1.15 stopped in six files on a P100
  • dcd004a sm_60 decode: the routed experts' IQ2_S / IQ3_XXS / IQ3_S signs from a table in shared memory - Maya-M on four GP100 dies 21.04 -> 21.58 tok/s, the same answers
  • ab8c5c5 sm_60 decode: the one-column Q6_K GEMV as aligned word loads handed out by shuffles (mv_q6_p100_kernel) - Maya-M on four GP100 dies 20.99 -> 26.65 tok/s with the sign tables, the same answers
  • 8c98d09 sm_60 decode: Q6_K's integer steps as exact rewrites (q - 32 in two instructions, one mul.wide.s16, the int -> float through 1.5 * 2^23) - the Q6_K GEMV 9% faster on a GP100 die, the same sums
  • e08067c sm_60 decode: moe_gate_up stages the layer input in shared memory (MAYA_GLM_GU_STAGE=0 reads it from global) - with the integer rewrites, Maya-M on four GP100 dies 26.55 -> 28.34 tok/s, the same answers

📊 Changes

10 files changed (+556 additions, -30 deletions)

View changed files

📝 CMakeLists.txt (+7 -0)
📝 docs/SETTINGS.md (+2 -0)
➕ include/strata/kernels/dp4a.hpp (+37 -0)
📝 src/kernels/cuda/exl3.cu (+1 -0)
📝 src/kernels/cuda/exl3_legacy.cu (+1 -0)
📝 src/kernels/cuda/glm_fast.cu (+389 -30)
📝 src/kernels/cuda/iq_kernels.cu (+1 -0)
📝 src/kernels/cuda/native_mmvq.cu (+1 -0)
📝 src/kernels/cuda/s2_expert_grouped.cu (+1 -0)
➕ tests/dp4a_sm60_test.cu (+116 -0)

📄 Description

The setup accepts compute capability 6.0 since #212 and the v1.1.15 notes name the P100, but the engine does not build for one: with CUDA 12.9 and maya.py's own configure (CMAKE_CUDA_ARCHITECTURES=native, CUDA_VISIBLE_DEVICES = the P100s) six files stop. GP100 has no dp4a (that is sm_61 and newer), and glm_fast.cu, native_mmvq.cu, s2_expert_grouped.cu, iq_kernels.cu (its ggml_cuda_dp4a), exl3.cu and exl3_legacy.cu call __dp4a ("identifier __dp4a is undefined", 67 times); and nvcc refuses glm_fast.cu's 22 __grid_constant__ kernel arguments in any Pascal pass ("__grid_constant__ annotation is only allowed for architecture compute_70 or later" - an sm_61 pass, a P40's, too). The first commit makes it build; the other four make GP100's decode faster with kernels that run on compute capability 6.0 only and give the same tokens.

1. The build - include/strata/kernels/dp4a.hpp defines __dp4a below __CUDA_ARCH__ 610 as an overload set that mirrors CUDA's two integer forms - signed bytes into int (four PTX vmad.s32.s32.s32 with byte selectors, VMAD.S8.S8 in the SASS), unsigned bytes into unsigned (four vmad.u32.u32.u32) - and the six files include it after cuda_runtime.h, so their call sites compile unchanged. glm_fast.cu's kernel arguments take STRATA_GRID_CONSTANT: __grid_constant__ from sm_70, nothing below (the same guard as on hengwen1's P40 branch). sm_61 and newer, and HIP, compile what they did: the header is empty there and STRATA_GRID_CONSTANT is __grid_constant__ (hip_compat's empty one on HIP). tests/dp4a_sm60_test.cu (registered with the GPU tests) checks __dp4a as the kernels see it against the byte-wise definition, both forms, ~1.07e9 cases each - every edge byte against every edge byte, every lane x a byte x b byte once, the rest random: 0 differ on a GP100 die (the signed form 2.1x the byte loop's speed) and on an RTX 3090 Ti (the hardware instruction).

2. IQ2_S / IQ3_XXS / IQ3_S signs from a table in shared memory - dw<T>'s __vcmpne4 / __vsub4 are SIMD-in-word intrinsics GP100 emulates in ~10 instructions each, in the inner loop of every routed expert. On cc 6.0 moe_gate_up_kernel / moe_down_kernel load each sign byte's byte masks (and their +1s) once a block and take (g ^ m) + (m & 0x01010101) for __vsub4(g ^ m, m) - every grid byte of those types is nonzero, so the negation never carries: the same bytes. One die, 8 experts at Maya-M's decode shapes: IQ2_S gate/up 312 -> 273 us, IQ3_XXS down 167 -> 156, IQ3_S down 195 -> 185.

3. The one-column Q6_K GEMV as aligned word loads (mv_q6_p100_kernel) - Maya-M's dense weights are Q6_K (~2/3 of a decode token's bytes). mv_kernel_t ran them at 135-150 GB/s of GP100's 732, bound by its loads: a lane reads its weights in seven 8- and 16-bit pieces (the 210-byte blocks are only 2-aligned). The new kernel takes R rows a warp (2 below 4096 rows in the launch, else 4), reads each row's block as 53 aligned words (two coalesced loads a lane, nothing outside the block) and hands every lane its call's fields with six shuffles, the activation staged in shared memory; each lane then makes dot_q6_K's calls in row_dot's order with the same ints and floats. One die, us: KDA q/k/v 24576 x 4096 561 -> 389, attn_output 4096 x 16384 406 -> 279, q_b 142 -> 105, shared expert gate/up 106 -> 79, q_a + kv_a 59 -> 48, FFN 287 -> 204, the head 3466 -> 2362. It runs where the device reports compute capability 6.0 only (asked once a device); STRATA_GLM_MV_P100=0 keeps mv_kernel_t, STRATA_GLM_MV_P100_R=2|4 forces R (docs/SETTINGS.md).

4. Q6_K's integer steps as exact rewrites (sm_60 pass only) - q - 32 per byte as (q + 0x60) ^ 0x80 (q in [0, 63]: no carry) for __vsubss4's emulation, dp4a * scale as one mul.wide.s16, the product (|p| <= 2^21) to float through the bits of 1.5 * 2^23, which is exact. Nothing while the GEMV was load-bound; with commit 3: KDA q/k/v 390 -> 352 us, attn_output 277 -> 253, the head 2285 -> 2088.

5. moe_gate_up stages the layer input in shared memory - every block reads the same q8_1 input (4.6 KB); on cc 6.0 the launch gives the kernel the room and it stages the input before the __syncthreads it already has. IQ2_S gate/up 274 -> 256 us. STRATA_GLM_GU_STAGE=0 turns it off (docs/SETTINGS.md).

Every kernel was checked against the one it replaces on real shapes with synthetic data, every output compared: 0 differ.

Measured

Two PH402 SKU 200 boards - each two GP100 dies with 32 GB of HBM2 on one card (sm_60, 732 GB/s a die; this vBIOS caps a die at 1050 MHz / 140 W, below a P100's clocks) - four dies, Windows 11, driver 581.80 (TCC), CUDA 12.9, MSVC 2022. Maya-M, maya.py --bench's requests: three questions, 256 tokens each, greedy, thinking off, and prompts of 2K / 8K tokens; the engine's defaults (--expert-cache auto, --prefill auto, the automatic layer split - every expert in VRAM) with STRATA_GLM_RAM_GB=1. "answers" hashes the three answers' token ids together; the prompts' first tokens were [220] / [9093] in every row.

build decode tok/s, the three questions mean prompt 2K / 8K tok/s answers
1 - it builds (this branch) 21.58 / 19.32 / 22.12 21.01 67.1 / 85.8 b84579eb2ca9addf
+ 2, sign tables 22.27 / 19.85 / 22.63 21.58 66.9 / 85.8 b84579eb2ca9addf
+ 3, mv_q6_p100_kernel 27.43 / 24.39 / 28.12 26.65 67.2 / 85.9 b84579eb2ca9addf
+ 4 + 5 29.07 / 26.04 / 29.91 28.34 (see below) b84579eb2ca9addf
1-5 (this branch) 28.92 / 25.98 / 29.81 28.24 67.2 / 85.8 b84579eb2ca9addf

On this branch: decode 21.01 -> 28.24 tok/s, +34% (+34.0 / +34.5 / +34.8% the three questions), prompts unchanged, every answer the same token for token.

The rows for commits 2-5 were measured while the kernels were written, on the same kernel code over v1.1.15 with an equivalent sm_60 build fix (its glm_fast.cu differs from commit 1's in one comment), the "+ 4 + 5" row with the ggml change under "Not in this PR" built in - it touches prompts only, so that row's prompt numbers are left out; the first and last rows were measured again on this branch, one after the other. With STRATA_GLM_DSA_ALL=0 that earlier sm_60 build gave the tokens a v1.1.11 build gave on the same machine (DSA_ALL's short-context shortcut changes them on every GPU, as its notes say).

The same kernels in a longer conversation (a 12K-token prompt, then two turns adding ~1.8K tokens each, 256 tokens out each; --prefill 1024, layer split 14,25,36, STRATA_GLM_COMPLETE_POOL=1, STRATA_GLM_RESIDENT_SKIP=1): the decode after each prompt 18.7 / 18.7 / 19.5 -> 24.3 / 24.2 / 25.2 tok/s, the same tokens.

Checked

  • sm_60: the engine builds through maya.py's own configure (native, the four dies visible), 150 / 150, the same warnings as before; the series' first commit alone builds too. Also built: the whole engine for an RTX 3090 Ti (sm_86, native), and the six touched files alone for sm_61 and sm_70 (v1.1.15's glm_fast.cu alone fails for sm_61 with the 22 __grid_constant__ errors).
  • tests/dp4a_sm60_test.cu on a GP100 die and an RTX 3090 Ti: 0 differ (above).
  • HIP is not built here; nothing in this changes it (the new code sits behind __CUDA_ARCH__ < 610, which HIP leaves undefined, or returns 0 / false under STRATA_USE_HIP).

Not in this PR

  • hengwen1's P40 work (their p40 branch: the STRATA_EXPERIMENTAL_SM60 CMake option for explicit sm_6x builds, the INT8 latent records' F32 product, STRATA_DENSE_F32, IQ4_XS in the wide dequant, the draft attention's per-device shared-memory ceiling, the vision build's fatbin compression): P40-specific or not needed to build or run on a P100 with MTP drafts; the __grid_constant__ guard here is the same as theirs. The shared-memory ceiling matters to GP100 too (48 KB a block) once DFlash2 drafts are used.
  • Prompts: ggml's MMQ falls back to a byte loop for ggml_cuda_dp4a on sm_60. A PRMT + mad.wide.s16 form of that fallback (the same sums) read Maya-M's 2K / 8K prompts 7.7% / 9.3% faster on the same four dies (67.0 / 85.9 -> 72.4 / 93.9 tok/s), with the same tokens - but it is a change to ggml's common.cuh, so it belongs in llama.cpp, not here.
  • -dlcm=ca (#214) changes nothing on GP100: it caches global loads in L1 by default, and the sm_60 SASS is the same with and without the flag.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/261 **Author:** [@ruibeikaa](https://github.com/ruibeikaa) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/20/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `sm60-p100` --- ### 📝 Commits (5) - [`a7f3375`](https://github.com/mw00/project-maya/commit/a7f33758a06201172e65be59d0df67e42c98f9b1) Pascal sm_60 (Tesla P100, GP100) builds: __dp4a by name maps to four vmad below sm_61 and __grid_constant__ drops below sm_70 - v1.1.15 stopped in six files on a P100 - [`dcd004a`](https://github.com/mw00/project-maya/commit/dcd004ac7bf460e8ae239b1b9ba39fbebcae44e2) sm_60 decode: the routed experts' IQ2_S / IQ3_XXS / IQ3_S signs from a table in shared memory - Maya-M on four GP100 dies 21.04 -> 21.58 tok/s, the same answers - [`ab8c5c5`](https://github.com/mw00/project-maya/commit/ab8c5c56bf2a3ec913bef0453dca61c66cf76751) sm_60 decode: the one-column Q6_K GEMV as aligned word loads handed out by shuffles (mv_q6_p100_kernel) - Maya-M on four GP100 dies 20.99 -> 26.65 tok/s with the sign tables, the same answers - [`8c98d09`](https://github.com/mw00/project-maya/commit/8c98d093b8da34525dcf4259755ffda93cff537b) sm_60 decode: Q6_K's integer steps as exact rewrites (q - 32 in two instructions, one mul.wide.s16, the int -> float through 1.5 * 2^23) - the Q6_K GEMV 9% faster on a GP100 die, the same sums - [`e08067c`](https://github.com/mw00/project-maya/commit/e08067c372c1dd56780debab9799a2907af2da4f) sm_60 decode: moe_gate_up stages the layer input in shared memory (MAYA_GLM_GU_STAGE=0 reads it from global) - with the integer rewrites, Maya-M on four GP100 dies 26.55 -> 28.34 tok/s, the same answers ### 📊 Changes **10 files changed** (+556 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+7 -0) 📝 `docs/SETTINGS.md` (+2 -0) ➕ `include/strata/kernels/dp4a.hpp` (+37 -0) 📝 `src/kernels/cuda/exl3.cu` (+1 -0) 📝 `src/kernels/cuda/exl3_legacy.cu` (+1 -0) 📝 `src/kernels/cuda/glm_fast.cu` (+389 -30) 📝 `src/kernels/cuda/iq_kernels.cu` (+1 -0) 📝 `src/kernels/cuda/native_mmvq.cu` (+1 -0) 📝 `src/kernels/cuda/s2_expert_grouped.cu` (+1 -0) ➕ `tests/dp4a_sm60_test.cu` (+116 -0) </details> ### 📄 Description The setup accepts compute capability 6.0 since #212 and the v1.1.15 notes name the P100, but the engine does not build for one: with CUDA 12.9 and maya.py's own configure (`CMAKE_CUDA_ARCHITECTURES=native`, `CUDA_VISIBLE_DEVICES` = the P100s) six files stop. GP100 has no dp4a (that is sm_61 and newer), and `glm_fast.cu`, `native_mmvq.cu`, `s2_expert_grouped.cu`, `iq_kernels.cu` (its `ggml_cuda_dp4a`), `exl3.cu` and `exl3_legacy.cu` call `__dp4a` ("identifier `__dp4a` is undefined", 67 times); and nvcc refuses `glm_fast.cu`'s 22 `__grid_constant__` kernel arguments in any Pascal pass ("`__grid_constant__` annotation is only allowed for architecture compute_70 or later" - an sm_61 pass, a P40's, too). The first commit makes it build; the other four make GP100's decode faster with kernels that run on compute capability 6.0 only and give the same tokens. **1. The build** - `include/strata/kernels/dp4a.hpp` defines `__dp4a` below `__CUDA_ARCH__` 610 as an overload set that mirrors CUDA's two integer forms - signed bytes into int (four PTX `vmad.s32.s32.s32` with byte selectors, `VMAD.S8.S8` in the SASS), unsigned bytes into unsigned (four `vmad.u32.u32.u32`) - and the six files include it after `cuda_runtime.h`, so their call sites compile unchanged. `glm_fast.cu`'s kernel arguments take `STRATA_GRID_CONSTANT`: `__grid_constant__` from sm_70, nothing below (the same guard as on hengwen1's P40 branch). sm_61 and newer, and HIP, compile what they did: the header is empty there and `STRATA_GRID_CONSTANT` is `__grid_constant__` (hip_compat's empty one on HIP). `tests/dp4a_sm60_test.cu` (registered with the GPU tests) checks `__dp4a` as the kernels see it against the byte-wise definition, both forms, ~1.07e9 cases each - every edge byte against every edge byte, every lane x a byte x b byte once, the rest random: 0 differ on a GP100 die (the signed form 2.1x the byte loop's speed) and on an RTX 3090 Ti (the hardware instruction). **2. IQ2_S / IQ3_XXS / IQ3_S signs from a table in shared memory** - `dw<T>`'s `__vcmpne4` / `__vsub4` are SIMD-in-word intrinsics GP100 emulates in ~10 instructions each, in the inner loop of every routed expert. On cc 6.0 `moe_gate_up_kernel` / `moe_down_kernel` load each sign byte's byte masks (and their +1s) once a block and take `(g ^ m) + (m & 0x01010101)` for `__vsub4(g ^ m, m)` - every grid byte of those types is nonzero, so the negation never carries: the same bytes. One die, 8 experts at Maya-M's decode shapes: IQ2_S gate/up 312 -> 273 us, IQ3_XXS down 167 -> 156, IQ3_S down 195 -> 185. **3. The one-column Q6_K GEMV as aligned word loads (`mv_q6_p100_kernel`)** - Maya-M's dense weights are Q6_K (~2/3 of a decode token's bytes). `mv_kernel_t` ran them at 135-150 GB/s of GP100's 732, bound by its loads: a lane reads its weights in seven 8- and 16-bit pieces (the 210-byte blocks are only 2-aligned). The new kernel takes R rows a warp (2 below 4096 rows in the launch, else 4), reads each row's block as 53 aligned words (two coalesced loads a lane, nothing outside the block) and hands every lane its call's fields with six shuffles, the activation staged in shared memory; each lane then makes `dot_q6_K`'s calls in `row_dot`'s order with the same ints and floats. One die, us: KDA q/k/v 24576 x 4096 561 -> 389, attn_output 4096 x 16384 406 -> 279, q_b 142 -> 105, shared expert gate/up 106 -> 79, q_a + kv_a 59 -> 48, FFN 287 -> 204, the head 3466 -> 2362. It runs where the device reports compute capability 6.0 only (asked once a device); `STRATA_GLM_MV_P100=0` keeps `mv_kernel_t`, `STRATA_GLM_MV_P100_R=2|4` forces R (docs/SETTINGS.md). **4. Q6_K's integer steps as exact rewrites** (sm_60 pass only) - `q - 32` per byte as `(q + 0x60) ^ 0x80` (q in [0, 63]: no carry) for `__vsubss4`'s emulation, `dp4a * scale` as one `mul.wide.s16`, the product (|p| <= 2^21) to float through the bits of 1.5 * 2^23, which is exact. Nothing while the GEMV was load-bound; with commit 3: KDA q/k/v 390 -> 352 us, attn_output 277 -> 253, the head 2285 -> 2088. **5. `moe_gate_up` stages the layer input in shared memory** - every block reads the same q8_1 input (4.6 KB); on cc 6.0 the launch gives the kernel the room and it stages the input before the `__syncthreads` it already has. IQ2_S gate/up 274 -> 256 us. `STRATA_GLM_GU_STAGE=0` turns it off (docs/SETTINGS.md). Every kernel was checked against the one it replaces on real shapes with synthetic data, every output compared: 0 differ. ### Measured Two PH402 SKU 200 boards - each two GP100 dies with 32 GB of HBM2 on one card (sm_60, 732 GB/s a die; this vBIOS caps a die at 1050 MHz / 140 W, below a P100's clocks) - four dies, Windows 11, driver 581.80 (TCC), CUDA 12.9, MSVC 2022. Maya-M, maya.py --bench's requests: three questions, 256 tokens each, greedy, thinking off, and prompts of 2K / 8K tokens; the engine's defaults (`--expert-cache auto`, `--prefill auto`, the automatic layer split - every expert in VRAM) with `STRATA_GLM_RAM_GB=1`. "answers" hashes the three answers' token ids together; the prompts' first tokens were [220] / [9093] in every row. | build | decode tok/s, the three questions | mean | prompt 2K / 8K tok/s | answers | |---|---|---:|---|---| | 1 - it builds (this branch) | 21.58 / 19.32 / 22.12 | **21.01** | 67.1 / 85.8 | b84579eb2ca9addf | | + 2, sign tables | 22.27 / 19.85 / 22.63 | 21.58 | 66.9 / 85.8 | b84579eb2ca9addf | | + 3, `mv_q6_p100_kernel` | 27.43 / 24.39 / 28.12 | 26.65 | 67.2 / 85.9 | b84579eb2ca9addf | | + 4 + 5 | 29.07 / 26.04 / 29.91 | 28.34 | (see below) | b84579eb2ca9addf | | 1-5 (this branch) | 28.92 / 25.98 / 29.81 | **28.24** | 67.2 / 85.8 | b84579eb2ca9addf | On this branch: decode 21.01 -> 28.24 tok/s, +34% (+34.0 / +34.5 / +34.8% the three questions), prompts unchanged, every answer the same token for token. The rows for commits 2-5 were measured while the kernels were written, on the same kernel code over v1.1.15 with an equivalent sm_60 build fix (its `glm_fast.cu` differs from commit 1's in one comment), the "+ 4 + 5" row with the ggml change under "Not in this PR" built in - it touches prompts only, so that row's prompt numbers are left out; the first and last rows were measured again on this branch, one after the other. With `STRATA_GLM_DSA_ALL=0` that earlier sm_60 build gave the tokens a v1.1.11 build gave on the same machine (`DSA_ALL`'s short-context shortcut changes them on every GPU, as its notes say). The same kernels in a longer conversation (a 12K-token prompt, then two turns adding ~1.8K tokens each, 256 tokens out each; `--prefill 1024`, layer split 14,25,36, `STRATA_GLM_COMPLETE_POOL=1`, `STRATA_GLM_RESIDENT_SKIP=1`): the decode after each prompt 18.7 / 18.7 / 19.5 -> 24.3 / 24.2 / 25.2 tok/s, the same tokens. ### Checked - sm_60: the engine builds through maya.py's own configure (native, the four dies visible), 150 / 150, the same warnings as before; the series' first commit alone builds too. Also built: the whole engine for an RTX 3090 Ti (sm_86, native), and the six touched files alone for sm_61 and sm_70 (v1.1.15's `glm_fast.cu` alone fails for sm_61 with the 22 `__grid_constant__` errors). - `tests/dp4a_sm60_test.cu` on a GP100 die and an RTX 3090 Ti: 0 differ (above). - HIP is not built here; nothing in this changes it (the new code sits behind `__CUDA_ARCH__` < 610, which HIP leaves undefined, or returns 0 / false under `STRATA_USE_HIP`). ### Not in this PR - hengwen1's P40 work (their `p40` branch: the `STRATA_EXPERIMENTAL_SM60` CMake option for explicit sm_6x builds, the INT8 latent records' F32 product, `STRATA_DENSE_F32`, IQ4_XS in the wide dequant, the draft attention's per-device shared-memory ceiling, the vision build's fatbin compression): P40-specific or not needed to build or run on a P100 with MTP drafts; the `__grid_constant__` guard here is the same as theirs. The shared-memory ceiling matters to GP100 too (48 KB a block) once DFlash2 drafts are used. - Prompts: ggml's MMQ falls back to a byte loop for `ggml_cuda_dp4a` on sm_60. A PRMT + `mad.wide.s16` form of that fallback (the same sums) read Maya-M's 2K / 8K prompts 7.7% / 9.3% faster on the same four dies (67.0 / 85.9 -> 72.4 / 93.9 tok/s), with the same tokens - but it is a change to ggml's `common.cuh`, so it belongs in llama.cpp, not here. - `-dlcm=ca` (#214) changes nothing on GP100: it caches global loads in L1 by default, and the sm_60 SASS is the same with and without the flag. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:20 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#432
No description provided.