Archived
place: the caching layer -- hot VRAM cache, deposits, copyless relabels
Routing-aware reads leave a routed expert's bytes on the drive when the pass routes nothing to it, but the reads that DO happen still have two wasteful fates: they land in a per-pass buffer thrown away at the next layer, and they cross the link even when the same bytes already sit in a host pool slot that just went cold. This commit gives both bytes somewhere to stay. The hot VRAM cache: a routed expert whose read heat ranks past the admission bar lands in a shadow slab slot and stays there. The slot is its address from then on, until heat evicts it -- eviction is a copyless relabel (back to Tier::SSD, publish null); the container is ground truth. The planner budgets the shadow slots for it (per-class on_disk count); the mover admits (Kind::Admit), evicts, and retires the admissions. Deposits: a free pool slot takes the O_DIRECT read directly -- the read's destination IS the slot -- and the unit becomes a pool unit the GEMM reads zero-copy, with heat promoting it at PCIe speed later. Its demotion is a copyless drop (the slot still holds the bytes). A full pool evicts its coldest unrouted unit by relabel, copyless, and the freed slot feeds the next deposit. The counters follow the traffic: the file stager's family is renamed file_* -> ssd_* (ssd_layers, ssd_units, ssd_read_bytes, ssd_preads, ssd_read_ns, ssd_wait_ns) beside the existing ssd_reads/ssd_bytes, and the new legs are counted (ssd_staging_bytes, ssd_promotions and ssd_promoted_bytes, ssd_deposits and ssd_deposit_bytes, pool_evictions). The dashboard's expert plane gains the matching staging, promotions and deposits rows, and --weights-disk-tier's help text names the tier. Measured on GLM-5.3-Flash TP2 (2x Radeon R9700), 250-token essay at temp 0: 5.49 tok/s at ~104 GiB of SSD reads per run, against main's 2.05 tok/s at ~378 GiB. Assisted-by: GLM-5.3-Flash
This commit is contained in:
1 parent
9efdd00c4c
commit
8da043c246
13 files changed
+485
-73
No files matched your search
+3
-2
@@ -119,8 +119,9 @@ static const Flag g_flags[] = {
|
||||
" two engines on separate cards hold one table: the\n"
|
||||
" first fills it, the last to exit deletes it" },
|
||||
{ "--weights-disk-tier", nullptr, "read weights that fit neither VRAM nor the host pool from the\n"
|
||||
" container on disk (O_DIRECT); a routed expert is read a layer\n"
|
||||
" at a time, so a step is paced by the drive" },
|
||||
" container on disk (O_DIRECT) -- the file tier, units on\n"
|
||||
" Tier::SSD; a routed expert is read a layer at\n"
|
||||
" a time, so a step is paced by the drive" },
|
||||
{ "--row-prefetch", "MODE", "on (default) | off -- a host gather from a table read through\n"
|
||||
" the container's mapping (--ngram-placement disk) asks for the\n"
|
||||
" pages its rows cover before its kernel runs, or beside it when\n"
|
||||
|
||||
@@ -2466,6 +2466,9 @@ int Engine::run_server() {
|
||||
s.link.h2d_bytes = s.link.d2h_bytes = s.link.ssd_reads = 0;
|
||||
s.link.ssd_bytes = s.link.prefetched = s.link.prefetch_bytes = 0;
|
||||
s.link.stream_bytes = s.link.staged_bytes = 0;
|
||||
s.link.ssd_staging_bytes = s.link.ssd_promoted_bytes = 0;
|
||||
s.link.ssd_deposits = s.link.ssd_deposit_bytes = 0;
|
||||
s.link.pool_evictions = 0;
|
||||
s.link.kv_stream_bytes = 0;
|
||||
s.link.kv_streaming = cfg_.kv_resident > 0; /* zeroed here if the arch refused it */
|
||||
/* The ring's depth, not the flag: KVStreamStats::resident_blocks sums the device pool
|
||||
@@ -2478,6 +2481,11 @@ int Engine::run_server() {
|
||||
s.link.d2h_bytes += (int64_t)rms.d2h_bytes;
|
||||
s.link.ssd_reads += (int64_t)rms.ssd_reads;
|
||||
s.link.ssd_bytes += (int64_t)rms.ssd_bytes;
|
||||
s.link.ssd_staging_bytes += (int64_t)rms.ssd_staging_bytes;
|
||||
s.link.ssd_promoted_bytes += (int64_t)rms.ssd_promoted_bytes;
|
||||
s.link.ssd_deposits += (int64_t)rms.ssd_deposits;
|
||||
s.link.ssd_deposit_bytes += (int64_t)rms.ssd_deposit_bytes;
|
||||
s.link.pool_evictions += (int64_t)rms.pool_evictions;
|
||||
s.link.prefetched += (int64_t)rms.prefetched;
|
||||
s.link.prefetch_bytes += (int64_t)rms.prefetch_bytes;
|
||||
s.link.staged_bytes += (int64_t)rms.staged_bytes;
|
||||
|
||||
+42
-14
@@ -23,22 +23,28 @@ int HeatEngine::init(const Plan& plan, const HeatParams& params) {
|
||||
tier_pub_.assign(n);
|
||||
busy_.assign(n, 0u);
|
||||
movable_.assign(n, 0u);
|
||||
evictable_.assign(n, 0u);
|
||||
pinned_.assign(n, 0u);
|
||||
layer_of_.assign(n, -1);
|
||||
bytes_.assign(n, 0);
|
||||
ever_.assign(n, 0u);
|
||||
|
||||
/* The movable units' slab classes as dense indices (heat.h: `cls_`). */
|
||||
/* The movable units' slab classes as dense indices (heat.h: `cls_`). File-tier units with a
|
||||
* class join them: the hot VRAM cache admits one into a slab slot at run
|
||||
* time, and step() files every candidate by class. Their rank stays 0 (never a promotion
|
||||
* candidate) until the mover admits one and marks it evictable. */
|
||||
cls_.assign(n, -1);
|
||||
{
|
||||
std::vector<int32_t> dense;
|
||||
for (size_t u = 0; u < n; ++u) {
|
||||
const MoveUnit& mu = plan.units[u];
|
||||
if (!mu.movable) continue;
|
||||
const int32_t k = mu.slab_class;
|
||||
auto dense_of = [&dense](int32_t k) {
|
||||
auto it = std::find(dense.begin(), dense.end(), k);
|
||||
if (it == dense.end()) { dense.push_back(k); it = dense.end() - 1; }
|
||||
cls_[u] = (int32_t)(it - dense.begin());
|
||||
return (int32_t)(it - dense.begin());
|
||||
};
|
||||
for (size_t u = 0; u < n; ++u) {
|
||||
const MoveUnit& mu = plan.units[u];
|
||||
if (mu.movable) cls_[u] = dense_of(mu.slab_class);
|
||||
else if (mu.tier == Tier::SSD && mu.slab_class >= 0) cls_[u] = dense_of(mu.slab_class);
|
||||
}
|
||||
n_cls_ = dense.empty() ? 1 : (int32_t)dense.size();
|
||||
}
|
||||
@@ -142,11 +148,11 @@ int HeatEngine::init(const Plan& plan, const HeatParams& params) {
|
||||
}
|
||||
enabled_ = true;
|
||||
RAD_INFO("heat engine: %lld movable units, %d move%s a step, "
|
||||
"decay %.3f hysteresis %.2f min-gain %.2f credit cap %.0f",
|
||||
"decay %.3f hysteresis %.2f min-gain %.2f credit cap %.0f admit-heat %.1f",
|
||||
(long long)movable, params_.moves_per_step,
|
||||
params_.moves_per_step == 1 ? "" : "s",
|
||||
(double)params_.decay, (double)params_.hysteresis, (double)params_.min_gain,
|
||||
(double)params_.credit_cap);
|
||||
(double)params_.credit_cap, (double)params_.admit_heat);
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
@@ -282,12 +288,32 @@ void HeatEngine::set_busy(int32_t unit, bool busy) {
|
||||
end_invalidate(unit);
|
||||
}
|
||||
|
||||
void HeatEngine::set_evictable(int32_t unit, bool evictable) {
|
||||
if (unit < 0 || (size_t)unit >= evictable_.size()) return;
|
||||
evictable_[(size_t)unit] = evictable ? 1u : 0u;
|
||||
set_place(unit);
|
||||
end_invalidate(unit);
|
||||
}
|
||||
|
||||
void HeatEngine::set_movable(int32_t unit, bool movable) {
|
||||
if (unit < 0 || (size_t)unit >= movable_.size()) return;
|
||||
movable_[(size_t)unit] = movable ? 1u : 0u;
|
||||
set_place(unit);
|
||||
end_invalidate(unit);
|
||||
}
|
||||
|
||||
void HeatEngine::set_place(int32_t unit) {
|
||||
const size_t u = (size_t)unit, p = (size_t)pos_[u];
|
||||
const bool vram = tier_[u] == Tier::VRAM;
|
||||
/* A pinned resident is never a candidate to leave the card: it ranks as off-device only, so a
|
||||
* promotion can still target it but a demotion cannot. */
|
||||
rank_as_[p] = (!movable_[u] || busy_[u] || (pinned_[u] && vram)) ? 0u : vram ? 2u : 1u;
|
||||
/* Two candidate lists share rank 2/1 (heat.h): promotions rank movable units off the
|
||||
* device; demotions rank movable -- or hot-cache -- units on it. A hot-cache unit joins
|
||||
* only the demotion end, and only while resident. A pinned resident (main) is never a
|
||||
* candidate to leave the card: it ranks as off-device only, so a promotion can still target
|
||||
* it but a demotion cannot. */
|
||||
rank_as_[p] = busy_[u] ? 0u
|
||||
: (!movable_[u] && !evictable_[u]) ? 0u
|
||||
: (pinned_[u] && vram) ? 0u
|
||||
: vram ? 2u : 1u;
|
||||
routed_as_[p] = vram ? 2u : 1u;
|
||||
miss_bytes_[p] = vram ? 0 : bytes_[u];
|
||||
}
|
||||
@@ -331,7 +357,7 @@ bool HeatEngine::pick(Swap* out) const {
|
||||
std::vector<int32_t> hot_res((size_t)n_cls_, 0), cold_res((size_t)n_cls_, 0);
|
||||
|
||||
for (size_t i = 0; i < movable_.size(); ++i) {
|
||||
if (!movable_[i] || busy_[i]) continue;
|
||||
if (busy_[i] || (!movable_[i] && !evictable_[i])) continue;
|
||||
const size_t c = (size_t)cls_[i];
|
||||
const int32_t l = layer_of_[i];
|
||||
const int32_t rc = l >= 0 ? res_count_[(size_t)l] : 0;
|
||||
@@ -343,14 +369,16 @@ bool HeatEngine::pick(Swap* out) const {
|
||||
if (cold[c] < 0 || h < cold_h[c] || (h == cold_h[c] && rc > cold_res[c])) {
|
||||
cold[c] = (int32_t)i; cold_h[c] = h; cold_res[c] = rc;
|
||||
}
|
||||
} else {
|
||||
} else if (movable_[i]) {
|
||||
/* Hotter wins; on a tie, the layer with the fewest resident units, whose tokens miss
|
||||
* most often.
|
||||
*
|
||||
* Both Tier::SSD and Tier::HostPinned units are candidates: promotion is from wherever
|
||||
* the unit is, and the mover knows the source. Demotion never targets the file tier,
|
||||
* since a frequency counter cannot justify a bet that a unit will not be needed; it
|
||||
* targets the host pool, and only the planner assigns SSD. */
|
||||
* targets the host pool, and only the planner assigns SSD. The hot VRAM cache's units
|
||||
* are excluded here while they sit on it (movable_ is false for them): admission is
|
||||
* the stager's decision, not a swap. */
|
||||
if (hot[c] < 0 || h > hot_h[c] || (h == hot_h[c] && rc < hot_res[c])) {
|
||||
hot[c] = (int32_t)i; hot_h[c] = h; hot_res[c] = rc;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,15 @@ struct HeatParams {
|
||||
* `hot >= cold*hysteresis + 1.5`, which against a zero-heat victim is two tokens agreeing in
|
||||
* one dispatch; a warmup only delays convergence. */
|
||||
int warmup_dispatches = 0;
|
||||
|
||||
/* The hot VRAM cache's admission bar: the heat at which the file stager
|
||||
* may read a routed expert into a slab slot permanently instead of its per-pass buffer.
|
||||
* Absolute, not relative to a victim: admission happens when the unit is read anyway, and the
|
||||
* shadow slots are the budget. A value near min_gain (1.5) admits anything routed twice
|
||||
* lately and churns; 8 is roughly two consistently-routed steps of the verify union at
|
||||
* MTP-d3, well above an occasional expert's credit of one or two. Eviction is free (the
|
||||
* container is ground truth), so the cost of an admission mistake is one future re-read. */
|
||||
float admit_heat = 8.0f;
|
||||
};
|
||||
|
||||
/* A promotion and its matching demotion. The mover issues two transfers, but they are decided
|
||||
@@ -249,6 +258,28 @@ public:
|
||||
}
|
||||
bool busy(int32_t unit) const { return busy_[(size_t)unit] != 0; }
|
||||
|
||||
/* ---- the hot VRAM cache ----------------------------------------------
|
||||
*
|
||||
* A unit the file stager admitted keeps heat's history and, while resident, joins the
|
||||
* demotion ranking as an evictable victim — but never the promotion ranking: its admission
|
||||
* is the stager's own decision (it is read anyway; the slot is the only extra cost), and
|
||||
* once evicted it has no address to promote from (the container, read by the stager).
|
||||
*
|
||||
* set_evictable marks a unit the mover has admitted or may admit. admit_hot is the
|
||||
* admission test: heat past the bar and not already in flight. */
|
||||
void set_evictable(int32_t unit, bool evictable);
|
||||
/* A deposit's plan says Tier::SSD -- non-movable --
|
||||
* but its pool slot makes it a PCIe-speed promotion candidate all the same. The deposit
|
||||
* flips movability here, keeping the plan's word for everything else. */
|
||||
void set_movable(int32_t unit, bool movable);
|
||||
bool evictable(int32_t unit) const { return evictable_[(size_t)unit] != 0; }
|
||||
bool admit_hot(int32_t unit) const {
|
||||
return enabled_ && unit >= 0 && (size_t)unit < tier_.size() &&
|
||||
tier_[(size_t)unit] == Tier::SSD && !busy_[(size_t)unit] &&
|
||||
pos_[(size_t)unit] >= 0 &&
|
||||
heat_[(size_t)pos_[(size_t)unit]] >= params_.admit_heat;
|
||||
}
|
||||
|
||||
/* The best swap available, or false when the guards refuse. */
|
||||
bool pick(Swap* out) const;
|
||||
|
||||
@@ -317,6 +348,10 @@ private:
|
||||
* lock-free and the mirror one byte per unit. */
|
||||
TierMirror tier_pub_;
|
||||
std::vector<uint8_t> busy_;
|
||||
/* Per unit, whether heat may rank it as a demotion victim though the plan called it
|
||||
* unmovable: the mover admitted it into the hot VRAM cache. Never a
|
||||
* promotion candidate: with no pool slot, only the stager can bring the unit back. */
|
||||
std::vector<uint8_t> evictable_;
|
||||
std::vector<uint8_t> movable_;
|
||||
/* --expert-pin-top: a decode-hot resident the planner pinned is never a demotion candidate,
|
||||
* even where a later pass made its unit movable again. */
|
||||
|
||||
+246
-19
@@ -446,6 +446,7 @@ int Mover::record_gate() {
|
||||
|
||||
int Mover::begin_dispatch(int dispatch, HeatEngine* heat) {
|
||||
dispatch_ = dispatch;
|
||||
heat_ = heat;
|
||||
++stats_.dispatches;
|
||||
RAD_TRY(retire(heat));
|
||||
|
||||
@@ -667,6 +668,12 @@ namespace {
|
||||
struct FileExt {
|
||||
int64_t foff = 0, bytes = 0;
|
||||
char* dst = nullptr;
|
||||
/* Into a hot-cache slot rather than the layer buffer: counted as
|
||||
* ssd_promoted_bytes, and the copy leaves the unit resident. */
|
||||
bool hot = false;
|
||||
/* Into a host pool slot rather than the layer buffer: counted as
|
||||
* ssd_deposit_bytes, and the copy leaves the unit resident in RAM. */
|
||||
bool deposit = false;
|
||||
};
|
||||
|
||||
/* The largest gap a run reads through instead of starting another pread. A routed layer's
|
||||
@@ -681,16 +688,18 @@ constexpr int64_t kReadThrough = (int64_t)256 << 10;
|
||||
int Mover::stage_file_units(const std::vector<int32_t>& units, char* dst, int64_t cap,
|
||||
RadEvent after, RadEvent done, std::vector<int32_t>* staged,
|
||||
std::vector<int32_t>* skipped, const int32_t* ecnt,
|
||||
int32_t n_expert) {
|
||||
int32_t n_expert, std::vector<int32_t>* promoted) {
|
||||
if (!plan_ || !dst || !staged || !done) return RAD_E_INVAL;
|
||||
staged->clear();
|
||||
if (skipped) skipped->clear();
|
||||
if (promoted) promoted->clear();
|
||||
if (!file_.ok() || !windows_ || n_windows_ <= 0) return RAD_E_STATE;
|
||||
|
||||
/* The layout in `dst`, unit by unit in the order given, and every weight's extent. */
|
||||
std::vector<FileExt> ext;
|
||||
std::vector<int64_t> at;
|
||||
int64_t off = 0;
|
||||
std::vector<char*> pbases; /* hot-cache units' slot bases, in promoted order */
|
||||
int64_t off = 0, hot_bytes = 0;
|
||||
for (int32_t u : units) {
|
||||
if (u < 0 || (size_t)u >= unit_.size()) return RAD_E_INVAL;
|
||||
UnitState& us = unit_[(size_t)u];
|
||||
@@ -707,6 +716,131 @@ int Mover::stage_file_units(const std::vector<int32_t>& units, char* dst, int64_
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* The hot VRAM cache: heat past the admission bar and a free
|
||||
* budgeted slot, and this pass's read lands in the slot and stays there. The read is
|
||||
* one the stager makes anyway; the slot is the whole cost, and eviction is
|
||||
* bookkeeping (the container is ground truth), so a mistake costs one future
|
||||
* re-read. No free slot, no heat, or no move record: the buffer path below, as
|
||||
* before. */
|
||||
if (promoted && plan_->dynamic && heat_ && heat_->admit_hot(u) && !unit_in_flight(u)) {
|
||||
ClassPools& cp = pools_[(size_t)us.klass];
|
||||
const int rec = free_move_record();
|
||||
int64_t slot = -1;
|
||||
if (rec < 0) ++stats_.no_record;
|
||||
else slot = cp.slab.take_where([&](int64_t s) { return s < cp.n_fixed; });
|
||||
if (slot >= 0 && record_gate() < 0) { cp.slab.add_free(slot); slot = -1; }
|
||||
if (slot >= 0) {
|
||||
const MoveUnit& mu = plan_->units[(size_t)u];
|
||||
char* const base = cp.slot_ptr(slot);
|
||||
Move& m = moves_[(size_t)rec];
|
||||
m.state = Move::State::Copying;
|
||||
m.kind = Move::Kind::Admit;
|
||||
m.unit = u;
|
||||
m.slab_slot = slot;
|
||||
m.pool_slot = -1;
|
||||
++copying_[(size_t)u];
|
||||
us.slab_slot = slot;
|
||||
us.hot = true;
|
||||
heat_->set_busy(u, true);
|
||||
++stats_.ssd_promotions;
|
||||
for (size_t k = 0; k < mu.weights.size(); ++k) {
|
||||
const WeightInfo& w = prog_->weights[mu.weights[k]];
|
||||
if (w.stored_bytes <= 0) continue; /* nothing to read, nothing to place */
|
||||
ext.push_back(FileExt{ (int64_t)w.file_offset, w.stored_bytes,
|
||||
base + mu.offset[k], true });
|
||||
}
|
||||
promoted->push_back(u);
|
||||
pbases.push_back(base);
|
||||
hot_bytes += us.bytes;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* A free pool slot and this read deposits the unit into the pool -- the O_DIRECT
|
||||
* read's destination IS the slot, and the unit becomes a pool unit: the GEMM reads it
|
||||
* zero-copy this step, heat promotes it at PCIe speed, and its demotion is a copyless
|
||||
* drop. The pool is ALL cache: no free slot and the coldest idle pool unit -- native
|
||||
* or deposited, the container is ground truth for both -- relabels back to the file
|
||||
* tier, copyless. Its slot feeds a future deposit after the
|
||||
* coldest idle pool unit -- native or deposited, the container is ground truth for both --
|
||||
* relabels back to the file tier, copyless. Its slot feeds a future deposit after the
|
||||
* quarantine; this read takes the buffer path. */
|
||||
if (promoted && plan_->dynamic && heat_ && !unit_in_flight(u)) {
|
||||
ClassPools& cp = pools_[(size_t)us.klass];
|
||||
const int rec = free_move_record();
|
||||
int64_t g = -1;
|
||||
if (rec < 0) ++stats_.no_record;
|
||||
else if (record_gate() >= 0) g = cp.pool.take();
|
||||
if (g < 0 && heat_) {
|
||||
/* The pool is full. Eviction is a copyless relabel: the
|
||||
* container holds every unit's bytes, so the victim loses nothing but its slot --
|
||||
* it becomes a file-tier unit whose next read deposits again. The victim is the
|
||||
* coldest idle unit of the class, however it got there: the cache adapts to the
|
||||
* workload, not to where a unit started. The freed slot feeds a future deposit
|
||||
* after the quarantine; this read takes the buffer path. */
|
||||
int32_t victim = -1;
|
||||
float best = 0;
|
||||
for (int32_t v = 0; v < (int32_t)unit_.size(); ++v) {
|
||||
UnitState& vs = unit_[(size_t)v];
|
||||
if (vs.klass != us.klass ||
|
||||
vs.tier != Tier::HostPinned || vs.pool_slot < 0 ||
|
||||
vs.slab_slot >= 0 || copying_[(size_t)v] || unit_in_flight(v))
|
||||
continue;
|
||||
const MoveUnit& mv = plan_->units[(size_t)v];
|
||||
if (mv.expert >= 0 && mv.expert < n_expert && ecnt && ecnt[mv.expert] > 0)
|
||||
continue; /* routed this pass: still wanted */
|
||||
const float h = heat_->heat(v);
|
||||
if (victim < 0 || h < best) { victim = v; best = h; }
|
||||
}
|
||||
if (victim >= 0) {
|
||||
const int r2 = free_move_record();
|
||||
if (r2 >= 0) {
|
||||
UnitState& vs = unit_[(size_t)victim];
|
||||
const MoveUnit& mv = plan_->units[(size_t)victim];
|
||||
Move& m2 = moves_[(size_t)r2];
|
||||
m2.state = Move::State::Published; /* nothing to copy: the drive has it */
|
||||
m2.kind = Move::Kind::Evict;
|
||||
m2.unit = victim;
|
||||
m2.slab_slot = -1;
|
||||
m2.pool_slot = vs.pool_slot;
|
||||
for (size_t k = 0; k < mv.weights.size(); ++k)
|
||||
res_.publish(mv.weights[k], calm_);
|
||||
vs.tier = Tier::SSD;
|
||||
vs.site = Site::DeviceStaged;
|
||||
vs.pool_slot = -1;
|
||||
heat_->set_tier(victim, Tier::SSD);
|
||||
++stats_.pool_evictions;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (g >= 0) {
|
||||
const MoveUnit& mu = plan_->units[(size_t)u];
|
||||
Move& m = moves_[(size_t)rec];
|
||||
m.state = Move::State::Copying;
|
||||
m.kind = Move::Kind::Deposit;
|
||||
m.unit = u;
|
||||
m.slab_slot = -1;
|
||||
m.pool_slot = g;
|
||||
++copying_[(size_t)u];
|
||||
us.pool_slot = g;
|
||||
us.tier = Tier::HostPinned;
|
||||
us.site = Site::DeviceZeroCopy;
|
||||
heat_->set_tier(u, Tier::HostPinned);
|
||||
heat_->set_movable(u, true); /* the slot makes it a PCIe-speed promotion candidate */
|
||||
heat_->set_busy(u, true);
|
||||
++stats_.ssd_deposits;
|
||||
for (size_t k = 0; k < mu.weights.size(); ++k) {
|
||||
const WeightInfo& w = prog_->weights[mu.weights[k]];
|
||||
if (w.stored_bytes <= 0) continue; /* nothing to read, nothing to place */
|
||||
ext.push_back(FileExt{ (int64_t)w.file_offset, w.stored_bytes,
|
||||
(char*)cp.pool_base + g * cp.stride + mu.offset[k],
|
||||
false, true });
|
||||
}
|
||||
for (size_t k = 0; k < mu.weights.size(); ++k)
|
||||
res_.publish(mu.weights[k],
|
||||
(char*)cp.pool_dev + g * cp.stride + mu.offset[k]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const int64_t need = align_up(us.bytes, RAD_ALIGN_UNIT);
|
||||
if (off + need > cap) {
|
||||
RAD_ERR("file stager: a routed layer's file-tier units need more than the %s buffer "
|
||||
@@ -748,7 +882,16 @@ int Mover::stage_file_units(const std::vector<int32_t>& units, char* dst, int64_
|
||||
* its own link reads here; the file stager's were invisible, so the panels showed zero
|
||||
* however much the drive streamed. */
|
||||
stats_.ssd_reads += (uint64_t)ext.size();
|
||||
for (const FileExt& e : ext) stats_.ssd_bytes += (uint64_t)e.bytes;
|
||||
for (const FileExt& e : ext) {
|
||||
stats_.ssd_bytes += (uint64_t)e.bytes;
|
||||
/* The copies below move the same bytes from the windows to their destination, which
|
||||
* crosses the link either way: into the layer buffer when the unit is discarded at the
|
||||
* next layer (ssd_staging_bytes), into a hot-cache or host-pool slot when it stays
|
||||
* (ssd_promoted_bytes and ssd_deposit_bytes, the kept-copy half of the split). */
|
||||
if (e.hot) stats_.ssd_promoted_bytes += (uint64_t)e.bytes;
|
||||
else if (e.deposit) stats_.ssd_deposit_bytes += (uint64_t)e.bytes;
|
||||
else stats_.ssd_staging_bytes += (uint64_t)e.bytes;
|
||||
}
|
||||
|
||||
if (after) RAD_TRY(rad_event_wait(mover_, after));
|
||||
|
||||
@@ -768,7 +911,7 @@ int Mover::stage_file_units(const std::vector<int32_t>& units, char* dst, int64_
|
||||
/* The window's copies from the round before must have left it. */
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
RAD_TRY(rad_event_sync(win_ev_[(size_t)w]));
|
||||
stats_.file_wait_ns += (uint64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
stats_.ssd_wait_ns += (uint64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - t0).count();
|
||||
win_rec_[(size_t)w] = 0;
|
||||
}
|
||||
@@ -804,11 +947,13 @@ int Mover::stage_file_units(const std::vector<int32_t>& units, char* dst, int64_
|
||||
if (cps.empty()) return RAD_E_STATE; /* a window that takes nothing cannot end */
|
||||
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
for (const Seg& s : segs) {
|
||||
for (const Seg& s : segs) {
|
||||
RAD_TRY(file_.read((uint64_t)s.fs, s.fe - s.fs, win + s.ws, W - s.ws));
|
||||
++stats_.file_preads;
|
||||
++stats_.ssd_preads;
|
||||
}
|
||||
stats_.file_read_ns += (uint64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
}
|
||||
stats_.ssd_read_ns += (uint64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - t0).count();
|
||||
for (const Cp& c : cps) RAD_TRY(rad_memcpy_async(c.dst, win + c.wo, c.bytes, mover_));
|
||||
RAD_TRY(rad_event_record(win_ev_[(size_t)w], mover_));
|
||||
@@ -821,11 +966,20 @@ int Mover::stage_file_units(const std::vector<int32_t>& units, char* dst, int64_
|
||||
const MoveUnit& mu = plan_->units[(size_t)u];
|
||||
for (size_t j = 0; j < mu.weights.size(); ++j)
|
||||
res_.publish(mu.weights[j], dst + at[k] + mu.offset[j]);
|
||||
stats_.file_bytes += (uint64_t)unit_[(size_t)u].bytes;
|
||||
stats_.ssd_read_bytes += (uint64_t)unit_[(size_t)u].bytes;
|
||||
}
|
||||
++stats_.file_layers;
|
||||
stats_.file_units += (uint64_t)staged->size();
|
||||
stats_.h2d_bytes += off;
|
||||
/* Hot-cache units publish at their slots and stay published: nothing unstages them, and
|
||||
* retire() finishes their admission when the copies land. */
|
||||
for (size_t k = 0; k < pbases.size(); ++k) {
|
||||
const int32_t u = (*promoted)[k];
|
||||
const MoveUnit& mu = plan_->units[(size_t)u];
|
||||
for (size_t j = 0; j < mu.weights.size(); ++j)
|
||||
res_.publish(mu.weights[j], pbases[k] + mu.offset[j]);
|
||||
stats_.ssd_read_bytes += (uint64_t)unit_[(size_t)u].bytes;
|
||||
}
|
||||
++stats_.ssd_layers;
|
||||
stats_.ssd_units += (uint64_t)(staged->size() + pbases.size());
|
||||
stats_.h2d_bytes += (uint64_t)(off + hot_bytes);
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
@@ -856,6 +1010,35 @@ int Mover::issue(const Swap& s, HeatEngine* heat) {
|
||||
* bytes, so there is nothing to copy and no second pool slot to take. */
|
||||
if (!promote && us.pool_slot >= 0 && us.slab_slot >= 0) return drop(unit, heat) >= 0;
|
||||
|
||||
/* A hot-cache unit has no pool slot to demote into and needs none:
|
||||
* the container holds its bytes, so the eviction is bookkeeping — free the slot,
|
||||
* publish null, and the file stager reads the expert again if routing asks for it.
|
||||
* The quarantine below is the same as any demotion's: kernels issued in earlier
|
||||
* layers may still name the slot. */
|
||||
if (!promote && us.hot && us.slab_slot >= 0) {
|
||||
const int rec = free_move_record();
|
||||
if (rec < 0) { ++stats_.no_record; return false; }
|
||||
if (record_gate() < 0) return false;
|
||||
Move& m = moves_[(size_t)rec];
|
||||
m.state = Move::State::Published; /* nothing to copy: the drive still has it */
|
||||
m.kind = Move::Kind::Evict;
|
||||
m.unit = unit;
|
||||
m.slab_slot = us.slab_slot;
|
||||
m.pool_slot = -1;
|
||||
us.slab_slot = -1;
|
||||
us.tier = Tier::SSD;
|
||||
us.site = Site::DeviceStaged;
|
||||
us.hot = false;
|
||||
republish(unit); /* the pointer stops naming the slot first */
|
||||
++stats_.demotions;
|
||||
++stats_.dropped; /* a copyless demotion, like a lent unit's drop */
|
||||
if (heat) {
|
||||
heat->set_tier(unit, Tier::SSD);
|
||||
heat->set_busy(unit, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (promote) {
|
||||
const int64_t slot = cp.slab.take();
|
||||
if (slot < 0) { ++stats_.starved_slab; return false; }
|
||||
@@ -1218,7 +1401,7 @@ int Mover::promote_to(int32_t unit, int64_t slot) {
|
||||
/* Into a lent slot the host copy stays: the loan can be recalled at any time, and a unit
|
||||
* that kept its pool slot goes back by a change of address instead of needing a pool slot and
|
||||
* a link copy just as the cache wants its memory. The quarantine then has no pool slot to
|
||||
* free. */
|
||||
* free. Every pool unit keeps its slot on promotion: the pool is one cache, so the later demotion is a copyless drop for natives and deposits alike. */
|
||||
m.pool_slot = cp.is_flex(slot) ? -1 : us.pool_slot;
|
||||
m.state = Move::State::Copying;
|
||||
m.unit = unit;
|
||||
@@ -1376,7 +1559,7 @@ int Mover::balance(HeatEngine* heat, bool turnover) {
|
||||
const UnitState& us = unit_[(size_t)u];
|
||||
if (us.klass != (int32_t)c || us.slab_slot < 0 || cp.is_flex(us.slab_slot)) continue;
|
||||
if (us.tier != Tier::VRAM || us.site != Site::Device || us.pool_slot >= 0) continue;
|
||||
if (!plan_->units[(size_t)u].movable) continue;
|
||||
if (!plan_->units[(size_t)u].movable && !unit_[(size_t)u].hot) continue;
|
||||
if (heat && heat->busy(u)) continue;
|
||||
const float h = heat ? heat->heat(u) : 0.0f;
|
||||
if (victim < 0 || h < coldest) { victim = u; coldest = h; }
|
||||
@@ -1593,6 +1776,34 @@ int Mover::retire(HeatEngine* heat) {
|
||||
* record for two more dispatches and stall the prefetch on a real card. */
|
||||
m.clear();
|
||||
continue;
|
||||
case Move::Kind::Admit:
|
||||
/* The hot cache's copy landed: like a Stage, the slot was
|
||||
* published at issue and the compute stream waited on the event, which now
|
||||
* clears; and like a Stage it frees nothing, so no quarantine — the slot is
|
||||
* the unit's home from here on. The tier change makes heat rank the unit as
|
||||
* resident (its next miss costs nothing to stream), and evictable: a later
|
||||
* swap frees the slot by bookkeeping (Mover::issue's Evict). */
|
||||
for (rad_weight w : plan_->units[(size_t)m.unit].weights) res_.settle(w);
|
||||
us.tier = Tier::VRAM;
|
||||
us.site = Site::Device;
|
||||
++stats_.promotions;
|
||||
if (heat) {
|
||||
heat->set_tier(m.unit, Tier::VRAM);
|
||||
heat->set_busy(m.unit, false);
|
||||
}
|
||||
m.clear();
|
||||
continue;
|
||||
case Move::Kind::Deposit:
|
||||
/* The deposit's copy landed: like an Admit, the slot was
|
||||
* published at issue and frees nothing — no quarantine. The tier change at issue
|
||||
* made heat rank the unit as a promotion candidate; the pool slot is the unit's
|
||||
* home, so its demotion is a copyless relabel. */
|
||||
for (rad_weight w : plan_->units[(size_t)m.unit].weights) res_.settle(w);
|
||||
us.tier = Tier::HostPinned;
|
||||
us.site = Site::DeviceZeroCopy;
|
||||
if (heat) heat->set_busy(m.unit, false);
|
||||
m.clear();
|
||||
continue;
|
||||
case Move::Kind::Migrate:
|
||||
us.slab_slot = m.to_slot;
|
||||
--pools_[(size_t)us.klass].n_donated;
|
||||
@@ -1632,7 +1843,12 @@ int Mover::retire(HeatEngine* heat) {
|
||||
|
||||
/* A Stage record never gets here: it is freed as soon as it lands. */
|
||||
ClassPools& cp = pools_[(size_t)unit_[(size_t)m.unit].klass];
|
||||
if (m.kind == Move::Kind::Promote) cp.pool.add_free(m.pool_slot);
|
||||
if (m.kind == Move::Kind::Promote) {
|
||||
/* Every promotion keeps its pool slot: pool_slot is -1, nothing to free. */
|
||||
if (m.pool_slot >= 0) cp.pool.add_free(m.pool_slot);
|
||||
}
|
||||
else if (m.kind == Move::Kind::Evict && m.pool_slot >= 0)
|
||||
cp.pool.add_free(m.pool_slot); /* pool relabel: the slot, named, is freed */
|
||||
else if (m.frees_slab()) cp.slab.add_free(m.slab_slot);
|
||||
if (heat && m.kind != Move::Kind::Release) heat->set_busy(m.unit, false);
|
||||
m.clear();
|
||||
@@ -1664,16 +1880,27 @@ std::string Mover::report() const {
|
||||
s += fmt(" file tier: %llu demand reads (%.2f GiB), each a blocking pread in the middle "
|
||||
"of a dispatch. Raise --host-pool-mib.\n",
|
||||
(unsigned long long)stats_.ssd_reads, (double)stats_.ssd_bytes * gib);
|
||||
if (stats_.ssd_promotions)
|
||||
s += fmt(" hot cache: %llu expert units read into VRAM slots (%.2f GiB) and left there; "
|
||||
"they stream no more\n",
|
||||
(unsigned long long)stats_.ssd_promotions,
|
||||
(double)stats_.ssd_promoted_bytes * gib);
|
||||
if (stats_.ssd_deposits)
|
||||
s += fmt(" ssd deposits: %llu (%.2f GiB), %llu copyless evictions of cold pool "
|
||||
"units back to the file tier\n",
|
||||
(unsigned long long)stats_.ssd_deposits,
|
||||
(double)stats_.ssd_deposit_bytes * gib,
|
||||
(unsigned long long)stats_.pool_evictions);
|
||||
/* The file stager's cost to the issuing thread: read is time in the drive, wait is time on a
|
||||
* window whose copies had not drained when it came round again. */
|
||||
if (stats_.file_layers) {
|
||||
const double rs = (double)stats_.file_read_ns * 1e-9;
|
||||
if (stats_.ssd_layers) {
|
||||
const double rs = (double)stats_.ssd_read_ns * 1e-9;
|
||||
s += fmt(" file stager: %llu routed layers read, %llu units, %.2f GiB in %llu preads; "
|
||||
"%.2f s reading (%.2f GB/s), %.2f s waiting on windows\n",
|
||||
(unsigned long long)stats_.file_layers, (unsigned long long)stats_.file_units,
|
||||
(double)stats_.file_bytes * gib, (unsigned long long)stats_.file_preads, rs,
|
||||
rs > 0 ? (double)stats_.file_bytes / rs * 1e-9 : 0.0,
|
||||
(double)stats_.file_wait_ns * 1e-9);
|
||||
(unsigned long long)stats_.ssd_layers, (unsigned long long)stats_.ssd_units,
|
||||
(double)stats_.ssd_read_bytes * gib, (unsigned long long)stats_.ssd_preads, rs,
|
||||
rs > 0 ? (double)stats_.ssd_read_bytes / rs * 1e-9 : 0.0,
|
||||
(double)stats_.ssd_wait_ns * 1e-9);
|
||||
if (stats_.ssd_skipped_units)
|
||||
s += fmt(" file stager: routing-aware reads skipped %llu units (%.2f GiB) whose "
|
||||
"experts were not routed this pass\n",
|
||||
|
||||
+60
-20
@@ -342,14 +342,29 @@ struct MoverStats {
|
||||
* dropped by a recall or shrink; recalls that found no free slot for a donor. */
|
||||
uint64_t donated = 0, relocated = 0, stranded = 0;
|
||||
uint64_t ssd_reads = 0, ssd_bytes = 0;
|
||||
/* The staging leg of the same bytes: the file stager's copies from its pinned windows
|
||||
* into the VRAM staging buffer, which cross the link. Moves out of h2d_bytes so the
|
||||
* dashboard's Promotions row shows heat's churn, not the streaming it is spent on. */
|
||||
uint64_t ssd_staging_bytes = 0;
|
||||
/* The hot VRAM cache's leg: the same extents, staged into a slab slot
|
||||
* instead of the per-pass buffer because heat said the expert keeps routing. A promotion
|
||||
* the stager charges nothing extra to read for: the unit was read anyway. Pairs with
|
||||
* `ssd_staging_bytes`; together with it, the PCIe legs of `ssd_bytes`. */
|
||||
uint64_t ssd_promotions = 0, ssd_promoted_bytes = 0;
|
||||
/* The SSD tier's deposit leg: file reads whose bytes stayed in a
|
||||
* pool slot -- the kept-copy half of the split, like ssd_promoted_bytes, only one tier
|
||||
* down. Evictions stay pool_*: they relabel a cold pool unit -- native or deposited, the
|
||||
* container is ground truth for both -- back to the file tier, copyless, so they are the
|
||||
* pool's ledger, not SSD traffic. */
|
||||
uint64_t ssd_deposits = 0, ssd_deposit_bytes = 0, pool_evictions = 0;
|
||||
/* The prefill stager (stage_units). `stage_overflow`: units no buffer had room for, read in
|
||||
* place. `stage_copies`: copies issued; neighbouring pool slots go as one. */
|
||||
uint64_t stage_layers = 0, staged_units = 0, staged_bytes = 0, stage_overflow = 0;
|
||||
uint64_t stage_copies = 0;
|
||||
/* The file stager (stage_file_units), including the host time spent in preads and waiting
|
||||
* for a window's copies to drain. */
|
||||
uint64_t file_layers = 0, file_units = 0, file_bytes = 0, file_preads = 0;
|
||||
uint64_t file_read_ns = 0, file_wait_ns = 0;
|
||||
uint64_t ssd_layers = 0, ssd_units = 0, ssd_read_bytes = 0, ssd_preads = 0;
|
||||
uint64_t ssd_read_ns = 0, ssd_wait_ns = 0;
|
||||
/* Routing-aware reads: units of experts whose routing count was zero at the layer's
|
||||
* trigger, not read (their weights are re-published to the layer buffer as a dummy
|
||||
* address for the pass, and nulled again with the staged units). */
|
||||
@@ -374,8 +389,10 @@ struct MoverCounters {
|
||||
std::atomic<uint64_t> ssd_reads{0}, ssd_bytes{0};
|
||||
std::atomic<uint64_t> stage_layers{0}, staged_units{0}, staged_bytes{0}, stage_overflow{0};
|
||||
std::atomic<uint64_t> stage_copies{0};
|
||||
std::atomic<uint64_t> file_layers{0}, file_units{0}, file_bytes{0}, file_preads{0};
|
||||
std::atomic<uint64_t> file_read_ns{0}, file_wait_ns{0};
|
||||
std::atomic<uint64_t> ssd_staging_bytes{0}, ssd_promotions{0}, ssd_promoted_bytes{0};
|
||||
std::atomic<uint64_t> ssd_deposits{0}, ssd_deposit_bytes{0}, pool_evictions{0};
|
||||
std::atomic<uint64_t> ssd_layers{0}, ssd_units{0}, ssd_read_bytes{0}, ssd_preads{0};
|
||||
std::atomic<uint64_t> ssd_read_ns{0}, ssd_wait_ns{0};
|
||||
std::atomic<uint64_t> ssd_skipped_units{0}, ssd_skipped_bytes{0};
|
||||
|
||||
void reset() {
|
||||
@@ -402,12 +419,18 @@ struct MoverCounters {
|
||||
staged_bytes.store(0, std::memory_order_relaxed);
|
||||
stage_overflow.store(0, std::memory_order_relaxed);
|
||||
stage_copies.store(0, std::memory_order_relaxed);
|
||||
file_layers.store(0, std::memory_order_relaxed);
|
||||
file_units.store(0, std::memory_order_relaxed);
|
||||
file_bytes.store(0, std::memory_order_relaxed);
|
||||
file_preads.store(0, std::memory_order_relaxed);
|
||||
file_read_ns.store(0, std::memory_order_relaxed);
|
||||
file_wait_ns.store(0, std::memory_order_relaxed);
|
||||
ssd_staging_bytes.store(0, std::memory_order_relaxed);
|
||||
ssd_promotions.store(0, std::memory_order_relaxed);
|
||||
ssd_promoted_bytes.store(0, std::memory_order_relaxed);
|
||||
ssd_deposits.store(0, std::memory_order_relaxed);
|
||||
ssd_deposit_bytes.store(0, std::memory_order_relaxed);
|
||||
pool_evictions.store(0, std::memory_order_relaxed);
|
||||
ssd_layers.store(0, std::memory_order_relaxed);
|
||||
ssd_units.store(0, std::memory_order_relaxed);
|
||||
ssd_read_bytes.store(0, std::memory_order_relaxed);
|
||||
ssd_preads.store(0, std::memory_order_relaxed);
|
||||
ssd_read_ns.store(0, std::memory_order_relaxed);
|
||||
ssd_wait_ns.store(0, std::memory_order_relaxed);
|
||||
ssd_skipped_units.store(0, std::memory_order_relaxed);
|
||||
ssd_skipped_bytes.store(0, std::memory_order_relaxed);
|
||||
}
|
||||
@@ -436,12 +459,18 @@ struct MoverCounters {
|
||||
s.staged_bytes = staged_bytes.load(std::memory_order_relaxed);
|
||||
s.stage_overflow = stage_overflow.load(std::memory_order_relaxed);
|
||||
s.stage_copies = stage_copies.load(std::memory_order_relaxed);
|
||||
s.file_layers = file_layers.load(std::memory_order_relaxed);
|
||||
s.file_units = file_units.load(std::memory_order_relaxed);
|
||||
s.file_bytes = file_bytes.load(std::memory_order_relaxed);
|
||||
s.file_preads = file_preads.load(std::memory_order_relaxed);
|
||||
s.file_read_ns = file_read_ns.load(std::memory_order_relaxed);
|
||||
s.file_wait_ns = file_wait_ns.load(std::memory_order_relaxed);
|
||||
s.ssd_staging_bytes = ssd_staging_bytes.load(std::memory_order_relaxed);
|
||||
s.ssd_promotions = ssd_promotions.load(std::memory_order_relaxed);
|
||||
s.ssd_promoted_bytes = ssd_promoted_bytes.load(std::memory_order_relaxed);
|
||||
s.ssd_deposits = ssd_deposits.load(std::memory_order_relaxed);
|
||||
s.ssd_deposit_bytes = ssd_deposit_bytes.load(std::memory_order_relaxed);
|
||||
s.pool_evictions = pool_evictions.load(std::memory_order_relaxed);
|
||||
s.ssd_layers = ssd_layers.load(std::memory_order_relaxed);
|
||||
s.ssd_units = ssd_units.load(std::memory_order_relaxed);
|
||||
s.ssd_read_bytes = ssd_read_bytes.load(std::memory_order_relaxed);
|
||||
s.ssd_preads = ssd_preads.load(std::memory_order_relaxed);
|
||||
s.ssd_read_ns = ssd_read_ns.load(std::memory_order_relaxed);
|
||||
s.ssd_wait_ns = ssd_wait_ns.load(std::memory_order_relaxed);
|
||||
s.ssd_skipped_units = ssd_skipped_units.load(std::memory_order_relaxed);
|
||||
s.ssd_skipped_bytes = ssd_skipped_bytes.load(std::memory_order_relaxed);
|
||||
return s;
|
||||
@@ -644,7 +673,8 @@ public:
|
||||
int stage_file_units(const std::vector<int32_t>& units, char* dst, int64_t cap,
|
||||
RadEvent after, RadEvent done, std::vector<int32_t>* staged,
|
||||
std::vector<int32_t>* skipped = nullptr,
|
||||
const int32_t* ecnt = nullptr, int32_t n_expert = 0);
|
||||
const int32_t* ecnt = nullptr, int32_t n_expert = 0,
|
||||
std::vector<int32_t>* promoted = nullptr);
|
||||
char* file_buffer(int i) const {
|
||||
return (file_vram_ && (i == 0 || i == 1)) ? file_vram_ + i * file_buf_bytes_ : nullptr;
|
||||
}
|
||||
@@ -667,7 +697,7 @@ private:
|
||||
* need the quarantine, which guards issued kernels, not bytes in flight. Migrate: a donor
|
||||
* (Mover::donor_slot) from an uncovered lent slot (`slab_slot`) to a free budgeted one
|
||||
* (`to_slot`). */
|
||||
enum class Kind { Promote, Demote, Stage, Release, Drop, Migrate };
|
||||
enum class Kind { Promote, Demote, Stage, Release, Drop, Migrate, Admit, Evict, Deposit };
|
||||
State state = State::Free;
|
||||
Kind kind = Kind::Promote;
|
||||
int32_t unit = -1;
|
||||
@@ -681,8 +711,10 @@ private:
|
||||
unit = -1;
|
||||
slab_slot = pool_slot = to_slot = -1;
|
||||
}
|
||||
/* Whether the move hands `slab_slot` back once its quarantine clears. */
|
||||
bool frees_slab() const { return kind != Kind::Promote && kind != Kind::Stage; }
|
||||
/* Whether the move hands `slab_slot` back once its quarantine clears. An Admit keeps
|
||||
* its slot: the unit becomes the slot's resident. */
|
||||
bool frees_slab() const { return kind != Kind::Promote && kind != Kind::Stage &&
|
||||
kind != Kind::Admit && kind != Kind::Deposit; }
|
||||
};
|
||||
|
||||
struct UnitState {
|
||||
@@ -693,6 +725,10 @@ private:
|
||||
int64_t static_off = -1; /* byte offset into the static VRAM region, or -1 */
|
||||
int32_t klass = -1;
|
||||
int64_t bytes = 0;
|
||||
/* Admitted into the hot VRAM cache: read from the container into a
|
||||
* slab slot and left there. Eviction is bookkeeping (kind Evict): re-tier to SSD, free
|
||||
* the slot, publish null — the container is ground truth. */
|
||||
bool hot = false;
|
||||
};
|
||||
|
||||
/* One weight class's memory. Budgeted slots sit at a fixed stride from one base in the
|
||||
@@ -733,6 +769,10 @@ private:
|
||||
MoverConfig cfg_;
|
||||
Residency res_;
|
||||
MoverCounters stats_;
|
||||
/* The heat engine of the dispatch in flight, bound by begin_dispatch: the file stager's
|
||||
* admission test (which units read into the hot cache) runs between dispatches on this
|
||||
* same thread. Null when heat is off — no hot cache, no evictable victims. */
|
||||
HeatEngine* heat_ = nullptr;
|
||||
Pools* budget_ = nullptr;
|
||||
/* True only when this object called the allocator itself (the test path). A Pool
|
||||
* reservation belongs to the Pool; freeing it here would be a double free. */
|
||||
|
||||
+16
-4
@@ -746,26 +746,38 @@ int Planner::assign_expert_tiered(Plan* p) {
|
||||
}
|
||||
|
||||
/* Slots used per class, which sizes the spares. A static plan reserves no shadow slots. */
|
||||
std::vector<int64_t> resident(p->classes.size(), 0), staged(p->classes.size(), 0);
|
||||
std::vector<int64_t> resident(p->classes.size(), 0), staged(p->classes.size(), 0),
|
||||
on_disk(p->classes.size(), 0);
|
||||
for (const MoveUnit& mu : p->units) {
|
||||
if (mu.slab_class < 0) continue;
|
||||
if (mu.movable && mu.tier == Tier::VRAM) ++resident[(size_t)mu.slab_class];
|
||||
if (mu.tier == Tier::SSD) ++on_disk[(size_t)mu.slab_class];
|
||||
/* The staging ring is slab memory too. finish() sizes it from the staged units,
|
||||
* known only after the fill, so it is reserved the same two-pass way as the shadow
|
||||
* slots. Routed file-tier units are excluded; the file stager has its own buffers. */
|
||||
if (mu.site == Site::DeviceStaged && mu.access != RAD_ACCESS_CONDITIONAL)
|
||||
++staged[(size_t)mu.slab_class];
|
||||
}
|
||||
/* The hot VRAM cache's budget: with file-tier units in a class, the shadow slots
|
||||
* may be filled with hot experts — read a routed expert into a shadow slab slot
|
||||
* permanently, instead of the stager's per-pass buffer, when heat says the expert
|
||||
* keeps routing. Eviction is bookkeeping (the container is ground truth). The
|
||||
* budget is the full shadow cap rather than the swap formula's resident/4 share.
|
||||
* Bounded by the class's residents so the two-pass fill converges — a later pass
|
||||
* with fewer residents reserves fewer — and charged to the weights budget through
|
||||
* k.spare like any shadow slot. */
|
||||
for (size_t c = 0; c < p->classes.size(); ++c) {
|
||||
const int64_t ring = std::min<int64_t>(RAD_PLACE_STAGE_RING, staged[c]);
|
||||
const int64_t shadow = (p->dynamic && resident[c] > 0)
|
||||
? std::min<int64_t>(RAD_PLACE_SHADOW_SLOTS, std::max<int64_t>(1, resident[c] / 4))
|
||||
: 0;
|
||||
p->classes[c].n_shadow = shadow;
|
||||
if (shadow + ring <= 0) continue;
|
||||
const int64_t hot = (p->dynamic && on_disk[c] > 0 && resident[c] > 0)
|
||||
? std::min<int64_t>(RAD_PLACE_SHADOW_SLOTS, resident[c]) : 0;
|
||||
p->classes[c].n_shadow = std::max(shadow, hot);
|
||||
if (p->classes[c].n_shadow + ring <= 0) continue;
|
||||
/* Plus the slab's tail pad: a kernel assembling a packed code window from a wide read
|
||||
* reads a few bytes past the last slot, which would fault at the allocation's end. */
|
||||
k.spare += (shadow + ring) * p->classes[c].stride + RAD_ALIGN_UNIT;
|
||||
k.spare += (p->classes[c].n_shadow + ring) * p->classes[c].stride + RAD_ALIGN_UNIT;
|
||||
}
|
||||
|
||||
/* The file stager's two buffers, each the largest routed layer's file-tier units at the
|
||||
|
||||
@@ -480,9 +480,10 @@ int FileStager::start(int32_t li, RadStream s) {
|
||||
}
|
||||
const int rc = mover_->stage_file_units(layers_[(size_t)li].units, buf_[b], cap_,
|
||||
free_rec_[b] ? free_[b] : nullptr, done_[b],
|
||||
&staged_[b], &skipped_[b], ecnt, n_expert);
|
||||
&staged_[b], &skipped_[b], ecnt, n_expert,
|
||||
&promoted_[b]);
|
||||
if (rc < 0) return rc;
|
||||
if (!staged_[b].empty()) holds_[b] = li;
|
||||
if (!staged_[b].empty() || !promoted_[b].empty()) holds_[b] = li;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
@@ -495,6 +496,9 @@ int FileStager::finish(int32_t b, RadStream s) {
|
||||
mover_->unstage_units(skipped_[b]); /* the dummy publications go to null too */
|
||||
skipped_[b].clear();
|
||||
}
|
||||
/* Hot-cache units are NOT unstaged: their publications name their slots, which outlive
|
||||
* the buffer. The layer's copies into them landed before its ops ran (the done_ wait). */
|
||||
promoted_[b].clear();
|
||||
holds_[b] = -1;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
@@ -274,6 +274,10 @@ private:
|
||||
int32_t* scratch_ = nullptr; /* pinned, for the trigger's blocking counts copy */
|
||||
int64_t scratch_n_ = 0;
|
||||
std::vector<int32_t> skipped_[2]; /* per buffer: units not read, nulled at release */
|
||||
/* Per buffer: units the stager read into hot-cache slots. Unlike the
|
||||
* staged ones they keep their publications when the buffer is released — the slot is
|
||||
* their address from here on, until heat evicts one. */
|
||||
std::vector<int32_t> promoted_[2];
|
||||
RadEvent done_[2] = { nullptr, nullptr }; /* behind a buffer's copies, on the mover stream */
|
||||
RadEvent free_[2] = { nullptr, nullptr }; /* behind the ops that read a buffer's layer */
|
||||
bool free_rec_[2] = { false, false };
|
||||
|
||||
@@ -461,6 +461,11 @@ HttpResponse Server::handle_stats(const HttpRequest&) {
|
||||
l["d2h_bytes"] = s.link.d2h_bytes;
|
||||
l["ssd_reads"] = s.link.ssd_reads;
|
||||
l["ssd_bytes"] = s.link.ssd_bytes;
|
||||
l["ssd_staging_bytes"] = s.link.ssd_staging_bytes;
|
||||
l["ssd_promoted_bytes"] = s.link.ssd_promoted_bytes;
|
||||
l["ssd_deposits"] = s.link.ssd_deposits;
|
||||
l["ssd_deposit_bytes"] = s.link.ssd_deposit_bytes;
|
||||
l["pool_evictions"] = s.link.pool_evictions;
|
||||
l["prefetched"] = s.link.prefetched;
|
||||
l["prefetch_bytes"] = s.link.prefetch_bytes;
|
||||
l["staged_bytes"] = s.link.staged_bytes;
|
||||
@@ -1876,6 +1881,12 @@ const linkSegs = segs("linkbar", "linkrows");
|
||||
* own mapping, read in place -- so it is the one that is not a grey. */
|
||||
const TIER_INK = ["#f5f5f5", "#9a9a9a", "#5e5e5e", "#2b2b2b", "#3f6fa8"];
|
||||
const INK_AR = "#60a5fa", INK_UP = "#4ade80", INK_DOWN = "#fbbf24", INK_SSD = "#a78bfa";
|
||||
const INK_SSD_STAGE = "#f9a8d4", INK_SSD_PROMOTE = "#86efac", INK_SSD_DEPOSIT = "#c4b5fd";
|
||||
/* The Expert SSD rows take their inks from where their bytes come from or go: staging is a
|
||||
* lighter Expert streaming -- it is that traffic's own second leg, the same extents copied
|
||||
* host to GPU after the drive read them; deposits wear a light tier violet, the kept copy in
|
||||
* host RAM that lands just short of VRAM; promotions are a lighter Promotions (#4ade80), the
|
||||
* same keep-forever copy heat's is, one tier further down. */
|
||||
const INK_STREAM = "#f472b6", INK_PREFETCH = "#2dd4bf", INK_KV = "#fb923c";
|
||||
/* The plane is painted as raw pixels, so the same inks are wanted as RGB triples. Parsed from
|
||||
* TIER_INK rather than written out a second time: two lists of five colours is one list that
|
||||
@@ -2490,8 +2501,16 @@ function update(s, dt) {
|
||||
$("layv").textContent = !lu.length ? DASH
|
||||
: wf >= 0.999 ? "all resident"
|
||||
: pct(sum / lu.length) + " mean · worst L" + worst + " " + pct(wf);
|
||||
/* Residency, not capability: every bucket says where units are, and the buckets add up to
|
||||
* the plan. The old "N movable" read as if cold disk experts could not move -- deposits and
|
||||
* the stager move them constantly; what they lack is an address heat can relocate without
|
||||
* reading the container. Tier names come from the engine; the page only phrases the two
|
||||
* common ones. */
|
||||
const rest = (ex.tiers || []).slice(1).filter(t => t.units > 0).map(t =>
|
||||
cnt(t.units) + " " + (t.name === "pinned" ? "in host pool"
|
||||
: t.name === "ssd" ? "on the file tier" : t.name));
|
||||
$("planev").textContent = cnt(res) + " of " + cnt(ex.n_units) + " in VRAM" +
|
||||
(ex.movable ? " · " + cnt(ex.movable) + " movable" : " · none movable");
|
||||
(rest.length ? " · " + rest.join(" · ") : " · fully resident");
|
||||
|
||||
/* ---- the plane itself.
|
||||
*
|
||||
@@ -2532,10 +2551,20 @@ function update(s, dt) {
|
||||
const pre = (f) => lk[f] || 0;
|
||||
const dP = (f) => prev.link[f] == null ? 0 : Math.max(0, (pre(f) - prev.link[f]) / dt);
|
||||
const ar = d("ar_bytes"), dn = d("d2h_bytes"), sd = d("ssd_bytes"), st = d("stream_bytes");
|
||||
const sg = d("ssd_staging_bytes");
|
||||
const sp = d("ssd_promoted_bytes");
|
||||
const wp = d("ssd_deposits");
|
||||
/* Null-safe until a server reports it: an older one, or the switch off, reads as zero. */
|
||||
const kv = lk.kv_streaming ? dP("kv_stream_bytes") : 0;
|
||||
const pf = dP("staged_bytes") + dP("prefetch_bytes");
|
||||
const up = Math.max(0, d("h2d_bytes") - pf);
|
||||
/* Promotions is a residual: every host-to-device byte that is not prefill prefetch.
|
||||
* Under the file tier the biggest such bytes are the SSD tier's staging leg -- the same
|
||||
* extents ssd_bytes read from the container, copied window to staging buffer -- which
|
||||
* would otherwise make Promotions read as the streaming it is spent on, not heat's churn.
|
||||
* The counter pairs with ssd_bytes (two legs of the same extents). The hot cache's
|
||||
* promotions are the third leg: extents copied into a slab slot that
|
||||
* stays, which get their own row and come out of the residual too. */
|
||||
const up = Math.max(0, d("h2d_bytes") - d("ssd_staging_bytes") - sp - pf);
|
||||
const pfAll = pre("staged_bytes") + pre("prefetch_bytes");
|
||||
const upAll = Math.max(0, lk.h2d_bytes - pfAll);
|
||||
/* AN IDLE LINK STILL HAS A COMPOSITION, and an empty bar is not it. Between two polls of a
|
||||
@@ -2563,8 +2592,6 @@ function update(s, dt) {
|
||||
* fault when the page is not there. Neither goes past this counter, and neither crosses
|
||||
* the link this panel is about. A zero here means no expert was fetched from the SSD tier;
|
||||
* it does not mean the process touched no disk. */
|
||||
{ name: "Expert SSD tier", ink: INK_SSD, w: w(sd, lk.ssd_bytes),
|
||||
a: rate(sd), b: hb(lk.ssd_bytes) },
|
||||
{ name: "Expert streaming", ink: INK_STREAM, w: w(st, lk.stream_bytes),
|
||||
a: rate(st), b: hb(lk.stream_bytes) },
|
||||
/* KV STREAMING, --kv-resident (core/kvstream): each step's resolve copies the blocks a
|
||||
@@ -2577,6 +2604,18 @@ function update(s, dt) {
|
||||
...(lk.kv_streaming ? [{ name: "KV streaming", ink: INK_KV,
|
||||
w: w(kv, pre("kv_stream_bytes")),
|
||||
a: rate(kv), b: hb(pre("kv_stream_bytes")) }] : []),
|
||||
/* THE HOT CACHE'S OWN ROW: SSD-tier reads whose destination was a
|
||||
* slab slot -- the expert stays resident -- read above the deposits row, whose bytes
|
||||
* stop in host RAM. A server from before the hot cache reports none, which reads as
|
||||
* zero. Ink: a lighter Promotions, the same keep-forever copy one tier further down. */
|
||||
{ name: "Expert SSD promotions", ink: INK_SSD_PROMOTE, w: w(sp, pre("ssd_promoted_bytes")),
|
||||
a: rate(sp), b: hb(pre("ssd_promoted_bytes")) },
|
||||
{ name: "Expert SSD deposits", ink: INK_SSD_DEPOSIT, w: w(wp, pre("ssd_deposit_bytes")),
|
||||
a: rate(wp), b: hb(pre("ssd_deposit_bytes")) },
|
||||
{ name: "Expert SSD staging", ink: INK_SSD_STAGE, w: w(sg, lk.ssd_staging_bytes),
|
||||
a: rate(sg), b: hb(lk.ssd_staging_bytes) },
|
||||
{ name: "Expert SSD tier", ink: INK_SSD, w: w(sd, lk.ssd_bytes),
|
||||
a: rate(sd), b: hb(lk.ssd_bytes) },
|
||||
]);
|
||||
/* THE HEADLINE IS THE PCIe TOTAL, which is the all-reduce plus the moves. The SSD tier is
|
||||
* left out of it on purpose: those bytes come off a disk into host memory and only the ones
|
||||
|
||||
@@ -111,6 +111,18 @@ struct LinkStat {
|
||||
int64_t ar_calls = 0, ar_bytes = 0;
|
||||
int64_t h2d_bytes = 0, d2h_bytes = 0;
|
||||
int64_t ssd_reads = 0, ssd_bytes = 0;
|
||||
/* The SSD tier's staging leg: the file stager's copies of those same extents from its
|
||||
* pinned windows into the VRAM staging buffer. Moves out of h2d_bytes so Promotions shows
|
||||
* heat's churn, not the streaming it is spent on. */
|
||||
int64_t ssd_staging_bytes = 0;
|
||||
/* The hot VRAM cache's leg: the same extents, copied into a slab slot
|
||||
* the unit keeps. With ssd_staging_bytes, the two PCIe legs of ssd_bytes; the split is
|
||||
* the hot cache's progress — staging decays as promotions grow. */
|
||||
int64_t ssd_promoted_bytes = 0;
|
||||
/* The SSD tier's deposit leg: SSD-tier reads whose bytes
|
||||
* stayed in a pool slot; evictions relabel a cold pool unit -- native or deposited -- back
|
||||
* to the file tier, copyless (pool_*: the pool's ledger, not SSD traffic). */
|
||||
int64_t ssd_deposits = 0, ssd_deposit_bytes = 0, pool_evictions = 0;
|
||||
/* The MoE GEMM reading a routed expert that was not resident: the traffic promotions aim to
|
||||
* remove. */
|
||||
int64_t stream_bytes = 0;
|
||||
|
||||
+3
-3
@@ -10256,10 +10256,10 @@ extern "C" int rad_kernel_count(void) {
|
||||
return (int)(sizeof(kKernels) / sizeof(kKernels[0])) + (int)host_twins().size();
|
||||
}
|
||||
extern "C" const RadKernelInfo* rad_kernel_at(int i) {
|
||||
const int base = (int)(sizeof(kKernels) / sizeof(kKernels[0]));
|
||||
if (i < 0 || i >= rad_kernel_count()) return nullptr;
|
||||
if (i < base) return &kKernels[i];
|
||||
return &host_twins()[(size_t)(i - base)].info;
|
||||
const int n = (int)(sizeof(kKernels) / sizeof(kKernels[0]));
|
||||
if (i < n) return &kKernels[(size_t)i];
|
||||
return &host_twins()[(size_t)(i - n)].info;
|
||||
}
|
||||
|
||||
/* Which rows touch nothing but their operands and scratch (rad_abi.h). The exceptions keep state
|
||||
|
||||
@@ -529,13 +529,15 @@ TEST(deterministic_mode_pins_placement_to_static) {
|
||||
TEST(planner_reads_routed_experts_it_cannot_hold_from_the_container) {
|
||||
/* Two routed layers of eight 1.5 MiB experts, a VRAM budget for a few and a host pool for
|
||||
* two. With the file tier on, the rest go there and the plan still fits: they are served by
|
||||
* reading the whole layer into one of two buffers charged to the same VRAM budget. */
|
||||
* reading the whole layer into one of two buffers charged to the same VRAM budget. The
|
||||
* budget also carries the unconditional hot cache — each resident expert may hold a shadow
|
||||
* slot (up to the cap) — so it is sized for residents plus their shadow slots. */
|
||||
Fixture f;
|
||||
build_moe_layers(f, 2, 8, 1 * MiB, MiB / 2);
|
||||
|
||||
Config c = base_config();
|
||||
c.placement = "expert_tiered";
|
||||
c.vram_weights_mib = 24;
|
||||
c.vram_weights_mib = 26;
|
||||
/* The file staging reserve (four slots of the widest unit plus the read windows) and room
|
||||
* for two pooled experts. */
|
||||
const int64_t reserve = 4 * (MiB + MiB / 2) + RAD_PLACE_FILE_WINDOWS * RAD_PLACE_FILE_WINDOW_BYTES;
|
||||
@@ -1448,9 +1450,9 @@ TEST(the_file_stager_reads_each_routed_layer_from_the_container) {
|
||||
}
|
||||
/* Three layers per pass, each at least two reads (the resident expert between the file-tier
|
||||
* ones is skipped, not read), and every unit read once. */
|
||||
CHECK_EQ(m.stats().file_layers, (uint64_t)(2 * L));
|
||||
CHECK_EQ(m.stats().file_units, (uint64_t)(2 * L * 2));
|
||||
CHECK(m.stats().file_preads >= (uint64_t)(2 * L * 2));
|
||||
CHECK_EQ(m.stats().ssd_layers, (uint64_t)(2 * L));
|
||||
CHECK_EQ(m.stats().ssd_units, (uint64_t)(2 * L * 2));
|
||||
CHECK(m.stats().ssd_preads >= (uint64_t)(2 * L * 2));
|
||||
rad_stream_sync(m.transfer_stream());
|
||||
rad_stream_destroy(s);
|
||||
std::remove(path.c_str());
|
||||
|
||||
Reference in new issue
Block a user