Files
Strata/engine/include/strata/program/split_ring.hpp
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
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.
2026-11-17 13:19:21 +01:00

50 lines
3.0 KiB
C++

#pragma once
#include <cstdint>
#include <cstdlib>
// A layer split's prompt-path ring and the lend slots sized from it, kept apart from the engine so they can be tested
// on the CPU (header-only, like pipeline_gate.hpp).
//
// 1. split_ring_slots: the streamed-ring override a split chooses (STRATA_SPLIT_RING, else 96 when most experts are
// resident). The choice must be made BEFORE anything sizes the prompt path with Prefill::bytes_needed (which counts
// ring_slots * max_blob): the split's lend regions (the RAM copies of the experts the prompt path borrows) used to
// be sized first, with the default ring, so a larger ring borrowed more slots than the copy kept.
// 2. split_lend_slots: how many tail slots of a cache `need` bytes take - the scan's own arithmetic, used for the
// RAM-copy region and for the borrow itself so the two cannot disagree.
namespace strata::program {
/// The ring override (slots) for a layer split, 0 = none (the pinned-share rule stays).
/// env STRATA_SPLIT_RING as read from the environment (nullptr = unset); 0 / non-numeric = the pinned-share rule
/// res_share the share of (layer, expert) pairs resident in some stage cache, 0..1
inline int split_ring_slots(const char* env, double res_share) {
const int ring = env != nullptr ? std::atoi(env) : (res_share >= 0.75 ? 96 : 0);
return ring > 0 ? ring : 0;
}
/// The number of tail slots of a cache of `slots` slots whose bytes cover `need`. `offsets` is the cache's per-slot
/// byte-offset prefix sum (slots + 1 entries, `bytes` = offsets[slots]) or nullptr when every slot is `max_blob` bytes.
inline int64_t split_lend_slots(int64_t slots, int64_t bytes, const uint64_t* offsets, uint64_t max_blob, uint64_t need) {
if (offsets != nullptr) {
int64_t k = 0;
while (k < slots && (uint64_t) (bytes - (int64_t) offsets[slots - k]) < need) ++k;
return k;
}
return max_blob == 0 ? 0 : (int64_t) ((need + max_blob - 1) / max_blob);
}
/// A figure about one participant of a layer split's prompt path (its Prefill::bytes_needed, which the lend is sized
/// from): `fn()`, evaluated with device `dev` current (-1: CUDA0's own part, the device is left as it is).
/// `on_device(dev)` returns a guard that makes `dev` current and puts the previous one back (strata::core::OnDevice in
/// the engine; the CPU test fakes it). #5722: bytes_needed answers for the CURRENT device (the fused layout and its
/// smaller MoE buffers are decided per card, prefill.cpp fused_ring), and each stage's init carves on its own device,
/// so a stage priced while CUDA0 was current was lent CUDA0's figure: on an RTX 5080 + RTX 4090 split the 4090's loan
/// was 2882 MiB for buffers that take 3014 MiB there. On like cards every device answers the same, so nothing changes.
template <class OnDev, class Fn>
auto split_part_figure(OnDev&& on_device, int dev, Fn&& fn) {
[[maybe_unused]] auto guard = on_device(dev);
return fn();
}
} // namespace strata::program