[PR #618] [CLOSED] ds4: Pool::start fences its generation store before the sleeper load, and a worker starts from generation 0 (either could leave a batch nobody helps unrun) #626

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/618
Author: @SeriousRising
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: ds4-pool-start-fence


📝 Commits (1)

  • 84db9a0 ds4: Pool::start fences its generation store before the sleeper load, and a worker starts from generation 0 (either could leave a batch nobody helps unrun)

📊 Changes

2 files changed (+45 additions, -2 deletions)

View changed files

📝 src/ds4/ds4_pool.hpp (+4 -1)
📝 tests/ds4_pool_test.cpp (+41 -1)

📄 Description

Fixes #615.

What. Two lines in src/ds4/ds4_pool.hpp, for the two ways a worker could sleep through a batch (#615):

  • Pool::start(): std::atomic_thread_fence(std::memory_order_seq_cst) between the gen_ store and the sleeping_ load. Without it x86 may read sleeping_ before gen_ is visible, and a worker going to sleep at that instant misses both the generation and the notify.
  • loop(): seen = 0 (the value of gen_ at construction) instead of gen_.load() when the thread first runs, so a batch start()ed before the thread ran is still new to it.

Test. tests/ds4_pool_test.cpp gains pool_start_wakes_sleeper: 200000 one-job batches on a one-worker pool, spin_us = 0, start() + wait() and no help(), with a watchdog (5 s without progress fails). Build as the file's header says (g++ -std=c++17 -O2 -pthread -I src/ds4 tests/ds4_pool_test.cpp). 10 runs each:

ds4_pool.hpp Xeon E5-2697 v4 VM (16 vCPU) Ryzen 7 9800X3D
v1.1.35 10 / 10 hang 10 / 10 hang
fence only 9 / 10 hang (all at batch 0) 0 / 30
seen = 0 only 10 / 10 hang (batches 5 .. 10410) -
this PR 0 / 10 0 / 30

Output: unchanged. Speed: no cost visible. Engine on 2x CMP 170HX 64 GB (sm_80, CUDA 12.8; PCIe Gen2 x16 + Gen2 x4), 16-vCPU Xeon E5-2697 v4 VM, DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS, --tp 1 --gpus 0,1 --dspark on --cpu-threads 14 --suffix-draft 0, ~2240 routed experts on the CPU lane: 2000 fixed prompt ids + 256 greedy tokens give the same ids and DSpark counts as v1.1.35; decode 40.68 (v1.1.35) / 40.99 (this PR) tok/s, one run each. One mfence per start() is ~16-30 a token, a few µs of a ~26 ms token (estimate).

Checks (as .github/workflows/tests.yml): tools/check_hip_compat.py OK; server tests 463 OK (12 skipped); installer and tools tests 584 OK (31 skipped) - the same counts as v1.1.35.

Not touched: glmfast::Workers (src/core/glm_fast_state.hpp:164-165, :202) has the same shape; noted in #615, not tested.

🤖 Generated with Claude Code


🔄 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/618 **Author:** [@SeriousRising](https://github.com/SeriousRising) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `ds4-pool-start-fence` --- ### 📝 Commits (1) - [`84db9a0`](https://github.com/mw00/project-maya/commit/84db9a0fb517ba646f7690976727696823477407) ds4: Pool::start fences its generation store before the sleeper load, and a worker starts from generation 0 (either could leave a batch nobody helps unrun) ### 📊 Changes **2 files changed** (+45 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/ds4/ds4_pool.hpp` (+4 -1) 📝 `tests/ds4_pool_test.cpp` (+41 -1) </details> ### 📄 Description Fixes #615. **What.** Two lines in `src/ds4/ds4_pool.hpp`, for the two ways a worker could sleep through a batch (#615): - `Pool::start()`: `std::atomic_thread_fence(std::memory_order_seq_cst)` between the `gen_` store and the `sleeping_` load. Without it x86 may read `sleeping_` before `gen_` is visible, and a worker going to sleep at that instant misses both the generation and the notify. - `loop()`: `seen = 0` (the value of `gen_` at construction) instead of `gen_.load()` when the thread first runs, so a batch `start()`ed before the thread ran is still new to it. **Test.** `tests/ds4_pool_test.cpp` gains `pool_start_wakes_sleeper`: 200000 one-job batches on a one-worker pool, `spin_us = 0`, `start()` + `wait()` and no `help()`, with a watchdog (5 s without progress fails). Build as the file's header says (`g++ -std=c++17 -O2 -pthread -I src/ds4 tests/ds4_pool_test.cpp`). 10 runs each: | `ds4_pool.hpp` | Xeon E5-2697 v4 VM (16 vCPU) | Ryzen 7 9800X3D | |---|---|---| | v1.1.35 | 10 / 10 hang | 10 / 10 hang | | fence only | 9 / 10 hang (all at batch 0) | 0 / 30 | | `seen = 0` only | 10 / 10 hang (batches 5 .. 10410) | - | | this PR | **0 / 10** | 0 / 30 | **Output: unchanged.** **Speed: no cost visible.** Engine on 2x CMP 170HX 64 GB (sm_80, CUDA 12.8; PCIe Gen2 x16 + Gen2 x4), 16-vCPU Xeon E5-2697 v4 VM, DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS, `--tp 1 --gpus 0,1 --dspark on --cpu-threads 14 --suffix-draft 0`, ~2240 routed experts on the CPU lane: 2000 fixed prompt ids + 256 greedy tokens give the same ids and DSpark counts as v1.1.35; decode 40.68 (v1.1.35) / 40.99 (this PR) tok/s, one run each. One `mfence` per `start()` is ~16-30 a token, a few µs of a ~26 ms token (estimate). **Checks** (as `.github/workflows/tests.yml`): `tools/check_hip_compat.py` OK; server tests 463 OK (12 skipped); installer and tools tests 584 OK (31 skipped) - the same counts as v1.1.35. Not touched: `glmfast::Workers` (`src/core/glm_fast_state.hpp:164-165`, `:202`) has the same shape; noted in #615, not tested. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:27:37 +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#626
No description provided.