mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 07:18:50 +00:00
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
repository paths inside tests.
engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.
No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
79 lines
4.1 KiB
C++
79 lines
4.1 KiB
C++
// include/strata/core/progress.hpp - issue #29: whether a request is still moving, and where it is.
|
|
//
|
|
// The engine's host loop and the GPU wait on each other through flags; a protocol bug there does not crash, it
|
|
// spins forever (the GPU "100%", one CPU core busy, no tokens). `--serve` runs a watchdog thread over this: a
|
|
// request whose heartbeat stops for `STRATA_WATCHDOG_S` seconds (default 60; 0 = off) ends the engine with the
|
|
// stage it was stuck in, and the server starts it again instead of hanging. Tokens, prompt chunks and verify
|
|
// windows beat; the stage is two relaxed stores per layer, which the token path does not notice.
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
namespace strata::core {
|
|
|
|
struct Progress {
|
|
std::atomic<uint64_t> beats{0};
|
|
std::atomic<bool> busy{false};
|
|
std::atomic<const char*> where{"idle"};
|
|
std::atomic<int64_t> detail{-1};
|
|
std::atomic<int64_t> chunk{-1}; ///< #251: the prompt chunk (its first position) a batched-read stage is in
|
|
std::atomic<int64_t> since_ms{0}; ///< when `where` was set (steady clock): how long a stage has lasted
|
|
std::atomic<uint64_t> ticks{0}; ///< layers served: a window that still moves, slowly, against one that stopped
|
|
/// a step that blocks in one call (a file flush, a host->device transfer of a whole session) is given until this
|
|
/// time (steady ms; 0 = none) instead of the watchdog's limit - an explicit, bounded allowance, not a beat
|
|
std::atomic<int64_t> allow_until_ms{0};
|
|
};
|
|
|
|
inline int64_t progress_now_ms() {
|
|
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch())
|
|
.count();
|
|
}
|
|
|
|
/// What the watchdog prints about a part of the engine when it fires (the expert pool, the verify window).
|
|
using DiagFn = void (*)(std::FILE*);
|
|
inline std::atomic<DiagFn>& diag_pool_fn() { static std::atomic<DiagFn> f{nullptr}; return f; }
|
|
inline std::atomic<DiagFn>& diag_verify_fn() { static std::atomic<DiagFn> f{nullptr}; return f; }
|
|
/// #267: what a path that ends the engine runs first - it releases the GPU's spin waits on host flags (the verify
|
|
/// window's), so no kernel stays resident while the process goes away (on Windows that left the GPU "lost").
|
|
inline std::atomic<DiagFn>& release_gpu_fn() { static std::atomic<DiagFn> f{nullptr}; return f; }
|
|
inline void release_gpu_waits(std::FILE* f) {
|
|
if (auto fn = release_gpu_fn().load()) fn(f);
|
|
}
|
|
/// The same release with one bound for all live verifiers, silent; true when their streams finished within `ms` (kfd_quiet.hpp,
|
|
/// EXIT). True when no verifier is live.
|
|
using ReleaseWithinFn = bool (*)(int);
|
|
inline std::atomic<ReleaseWithinFn>& release_gpu_within_fn() { static std::atomic<ReleaseWithinFn> f{nullptr}; return f; }
|
|
inline bool release_gpu_waits_within(int ms) {
|
|
if (auto fn = release_gpu_within_fn().load()) return fn(ms);
|
|
return true;
|
|
}
|
|
/// --pipeline-windows: the pipelined loop's windows and the drafter's chain (set while that loop runs)
|
|
inline std::atomic<DiagFn>& diag_pipeline_fn() { static std::atomic<DiagFn> f{nullptr}; return f; }
|
|
|
|
inline Progress& progress() {
|
|
static Progress p;
|
|
return p;
|
|
}
|
|
|
|
inline void progress_at(const char* where, int64_t detail = -1, int64_t chunk = -1) {
|
|
Progress& p = progress();
|
|
p.where.store(where, std::memory_order_relaxed);
|
|
p.detail.store(detail, std::memory_order_relaxed);
|
|
p.chunk.store(chunk, std::memory_order_relaxed);
|
|
p.since_ms.store(progress_now_ms(), std::memory_order_relaxed);
|
|
}
|
|
|
|
inline void progress_beat() { progress().beats.fetch_add(1, std::memory_order_relaxed); }
|
|
inline void progress_tick() { progress().ticks.fetch_add(1, std::memory_order_relaxed); }
|
|
/// A beat that also sets (seconds > 0) or clears (0) the allowance of a blocking step: the watchdog does not fire
|
|
/// before the allowance ends, and fires at its end if nothing beat since.
|
|
inline void progress_allow(int64_t seconds) {
|
|
progress().allow_until_ms.store(seconds > 0 ? progress_now_ms() + seconds * 1000 : 0, std::memory_order_relaxed);
|
|
progress_beat();
|
|
}
|
|
|
|
} // namespace strata::core
|