[PR #214] Pascal (sm_6x): build with three guards, cache global loads in L1 (-dlcm=ca) - P40 decode 1.7-3x, same answers #398

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

Original Pull Request: https://github.com/mw00/project-maya/pull/214

State: closed
Merged: Yes


Follow-up to #212 (and possibly the answer to #189's first question). Maya builds for Pascal (sm_6x, e.g. the Tesla P40) with three small guards. With global loads cached in L1 it decodes 1.7-3x as fast there, with the same answers. Builds for sm_70 and newer are unchanged.

This does not change the setup: MIN_CC still refuses compute capability 6.x, so whether Pascal is offered stays your decision. It lets a hand-made Pascal build, CMAKE_CUDA_ARCHITECTURES=native as arch_setting() asks for below sm_75, compile and run at the card's speed.

The change (38 lines, one topic)

  • glm_batch.cu: the bodies of mla_attn_tc_kernel and mla_attn_tc_reg_kernel (nvcuda::wmma, sm_70+) compile to nothing for __CUDA_ARCH__ < 700. mla_attn already picks the F32 kernel when major < 7 (tc_ok = -1, and major >= 7 short-circuits the fits() check), so neither is ever launched there.
  • elementwise.cu (doorbell_wait_kernel) and verify_kernels.cu (wait_flag_ge_kernel, wait_flag_ge_or_kernel): __nanosleep is sm_70+, so below that the wait is a plain spin.
  • CMakeLists.txt: when the CUDA architectures include an sm_6x one (CMAKE_CUDA_ARCHITECTURES, or CMAKE_CUDA_ARCHITECTURES_NATIVE for native), -Xptxas -dlcm=ca is appended to CMAKE_CUDA_FLAGS, and the configure says so. GP102 / GP104 cache global loads in L2 only unless the code asks for L1 too; Volta and newer cache them in L1 by default. The GEMVs' many small loads (get_int_b2, scales, the q8_1 activations every warp of a block reads) starved there.
  • Not touched: the explicit-arch guard (_base LESS 75 refuses 61), the setup, the HIP path.

All three guards are under __CUDA_ARCH__ < 700, which a build for sm_70+ never defines, and the flag needs an sm_6x architecture. Configuring on an RTX 3090 Ti with native and with 86, the flag is in none of the compile commands. On a P40 with native, it is in all 86 CUDA compile commands and the configure prints Strata: Pascal (sm_61): global loads cached in L1 (-Xptxas -dlcm=ca).

Why: the profile

nsys profile -t cuda around ./maya.sh --bench, Maya-L on one P40, without the flag:

  • mv_kernel_t<14> (Q6_K) was 51% of GPU time: about 150 calls a token at 563 µs, so ~84 ms of a ~150 ms token. That is a quarter of what the P40's 347 GB/s allows for the dense weights, or less.
  • Then moe_fetch_kernel (17%), moe_cpu_wait_kernel (7%) and moe_gate_up_kernel<21> (7%).

Before and after: ./maya.sh --bench

3x Tesla P40 24 GB (driver 580.126.20, CUDA 12.8), EPYC 7302P as a KVM guest with 32 vCPUs (no SMT siblings visible), 184 GB RAM, Debian 12, kernel 6.1. Context 32768, --prefill auto, --kv-streaming on, the shipped expert profile, no vision. One and two GPUs use the cards at x16.

model, P40s without the flag with -dlcm=ca decode
Maya-L, 1 5.8, 5.8 9.9, 10.0 x1.7
Maya-L, 2 9.7, 9.7 16.9 (v1.1.12: 16.8) x1.7
Maya-L, 3 8.7, 8.7 16.0 x1.8
Maya-S24, 1 5.3, 5.3 15.6 x2.9
Maya-S24, 2 9.4, 9.3 28.0, 28.1 (v1.1.12: 28.2) x3.0
Maya-S24, 3 9.6, 8.1 28.4 x3.0

Prefill stays at 160-210 tok/s with or without the flag (the prompt attention runs on the F32 cores). Per-question numbers, the split lines and the report are in #212.

Same answers: I checked greedy chat answers from the builds with and without the flag (Maya-S24, one P40, three prompts of up to 200 tokens). All three are identical to the character, at 5.3-5.5 and 14.9-16.7 tok/s. The flag changes where loads are cached, not the arithmetic.

This branch's build is the measured engine:

  • The numbers above came from v1.1.11 / v1.1.12 with the guards and CMAKE_CUDA_FLAGS=-Xptxas -dlcm=ca passed by hand.
  • This branch (v1.1.12 + the commit), configured with no flags, produced the same machine code: cuobjdump -sass of both binaries is identical once the path-dependent anonymous-namespace hashes (_GLOBAL__N__<hash>) are normalised (2,944,748 lines, 0 different).

Checks

On the P40 box (Linux), with the CI commands, on this branch:

  • tools/check_hip_compat.py: every CUDA name has a mapping (no new CUDA calls).
  • python -m unittest discover -s serve -p "test_*.py" -t .: 189 tests OK (3 skipped).
  • python -m unittest discover -s tools -p "test_*.py": 266 tests OK (27 skipped).

The engine was built for sm_61 (P40). The 3090 Ti box only configured the branch, for native and 86.

Not measured

  • The engine's parity tests (glm_*_parity --selftest) on sm_61.
  • Long contexts.
  • Pascal cards other than the P40 (sm_60 P100, sm_62 Jetson TX2).
  • Windows.
  • AMD, beyond reading: the HIP build does not define __CUDA_ARCH__ (hip_compat/ leaves it undefined), so every guard is false there and today's code compiles. The wmma kernels are inside #if !defined(STRATA_USE_HIP) anyway, and the CMake change only reads CUDA architectures.

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/mw00/project-maya/pull/214 **State:** closed **Merged:** Yes --- Follow-up to #212 (and possibly the answer to #189's first question). Maya builds for Pascal (sm_6x, e.g. the Tesla P40) with three small guards. With global loads cached in L1 it decodes 1.7-3x as fast there, with the same answers. Builds for sm_70 and newer are unchanged. This does not change the setup: `MIN_CC` still refuses compute capability 6.x, so whether Pascal is offered stays your decision. It lets a hand-made Pascal build, `CMAKE_CUDA_ARCHITECTURES=native` as `arch_setting()` asks for below sm_75, compile and run at the card's speed. ## The change (38 lines, one topic) - **`glm_batch.cu`:** the bodies of `mla_attn_tc_kernel` and `mla_attn_tc_reg_kernel` (`nvcuda::wmma`, sm_70+) compile to nothing for `__CUDA_ARCH__ < 700`. `mla_attn` already picks the F32 kernel when `major < 7` (`tc_ok = -1`, and `major >= 7` short-circuits the `fits()` check), so neither is ever launched there. - **`elementwise.cu` (`doorbell_wait_kernel`) and `verify_kernels.cu` (`wait_flag_ge_kernel`, `wait_flag_ge_or_kernel`):** `__nanosleep` is sm_70+, so below that the wait is a plain spin. - **`CMakeLists.txt`:** when the CUDA architectures include an sm_6x one (`CMAKE_CUDA_ARCHITECTURES`, or `CMAKE_CUDA_ARCHITECTURES_NATIVE` for `native`), `-Xptxas -dlcm=ca` is appended to `CMAKE_CUDA_FLAGS`, and the configure says so. GP102 / GP104 cache global loads in L2 only unless the code asks for L1 too; Volta and newer cache them in L1 by default. The GEMVs' many small loads (`get_int_b2`, scales, the q8_1 activations every warp of a block reads) starved there. - **Not touched:** the explicit-arch guard (`_base LESS 75` refuses `61`), the setup, the HIP path. All three guards are under `__CUDA_ARCH__ < 700`, which a build for sm_70+ never defines, and the flag needs an sm_6x architecture. Configuring on an RTX 3090 Ti with `native` and with `86`, the flag is in none of the compile commands. On a P40 with `native`, it is in all 86 CUDA compile commands and the configure prints `Strata: Pascal (sm_61): global loads cached in L1 (-Xptxas -dlcm=ca)`. ## Why: the profile `nsys profile -t cuda` around `./maya.sh --bench`, Maya-L on one P40, without the flag: - `mv_kernel_t<14>` (Q6_K) was 51% of GPU time: about 150 calls a token at 563 µs, so ~84 ms of a ~150 ms token. That is a quarter of what the P40's 347 GB/s allows for the dense weights, or less. - Then `moe_fetch_kernel` (17%), `moe_cpu_wait_kernel` (7%) and `moe_gate_up_kernel<21>` (7%). ## Before and after: `./maya.sh --bench` 3x Tesla P40 24 GB (driver 580.126.20, CUDA 12.8), EPYC 7302P as a KVM guest with 32 vCPUs (no SMT siblings visible), 184 GB RAM, Debian 12, kernel 6.1. Context 32768, `--prefill auto`, `--kv-streaming on`, the shipped expert profile, no vision. One and two GPUs use the cards at x16. | model, P40s | without the flag | with `-dlcm=ca` | decode | | --- | ---: | ---: | ---: | | Maya-L, 1 | 5.8, 5.8 | 9.9, 10.0 | x1.7 | | Maya-L, 2 | 9.7, 9.7 | 16.9 (v1.1.12: 16.8) | x1.7 | | Maya-L, 3 | 8.7, 8.7 | 16.0 | x1.8 | | Maya-S24, 1 | 5.3, 5.3 | 15.6 | x2.9 | | Maya-S24, 2 | 9.4, 9.3 | 28.0, 28.1 (v1.1.12: 28.2) | x3.0 | | Maya-S24, 3 | 9.6, 8.1 | 28.4 | x3.0 | Prefill stays at 160-210 tok/s with or without the flag (the prompt attention runs on the F32 cores). Per-question numbers, the split lines and the report are in #212. **Same answers:** I checked greedy chat answers from the builds with and without the flag (Maya-S24, one P40, three prompts of up to 200 tokens). All three are identical to the character, at 5.3-5.5 and 14.9-16.7 tok/s. The flag changes where loads are cached, not the arithmetic. **This branch's build is the measured engine:** - The numbers above came from v1.1.11 / v1.1.12 with the guards and `CMAKE_CUDA_FLAGS=-Xptxas -dlcm=ca` passed by hand. - This branch (v1.1.12 + the commit), configured with no flags, produced the same machine code: `cuobjdump -sass` of both binaries is identical once the path-dependent anonymous-namespace hashes (`_GLOBAL__N__<hash>`) are normalised (2,944,748 lines, 0 different). ## Checks On the P40 box (Linux), with the CI commands, on this branch: - `tools/check_hip_compat.py`: every CUDA name has a mapping (no new CUDA calls). - `python -m unittest discover -s serve -p "test_*.py" -t .`: 189 tests OK (3 skipped). - `python -m unittest discover -s tools -p "test_*.py"`: 266 tests OK (27 skipped). The engine was built for sm_61 (P40). The 3090 Ti box only configured the branch, for `native` and `86`. ## Not measured - The engine's parity tests (`glm_*_parity --selftest`) on sm_61. - Long contexts. - Pascal cards other than the P40 (sm_60 P100, sm_62 Jetson TX2). - Windows. - AMD, beyond reading: the HIP build does not define `__CUDA_ARCH__` (`hip_compat/` leaves it undefined), so every guard is false there and today's code compiles. The wmma kernels are inside `#if !defined(STRATA_USE_HIP)` anyway, and the CMake change only reads CUDA architectures. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
bsakaguchi 2026-10-29 21:25:02 +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#398
No description provided.