This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/core/mem/hostarena.cpp
T
Deadcode 82b5835c02 radiance 1.1.0
- The VRAM split has no ratio: --expert-vs-cache-ratio is gone (now an unknown option). The
  experts keep what the pinned host pool cannot hold, the KV cache takes the rest and lends idle
  blocks to the experts. Flash-Next at tp2: 7.9 GiB of KV a card, up from 4.7. Startup, /stats,
  /metrics and the dashboard report the most the cache can hold.
- Linear-state snapshots live in pinned host memory, not VRAM (--checkpoint-slots sizes the
  store). Prefix-cache misses on agent sessions fixed; a published conversation is no longer
  trimmed away.
- Any world size from the shipped container (baKon): --tp 3 on Flash-Next with no padded
  checkpoint -- the attention world, uneven delta-net heads, the fill op.
- Kernels (keptn42): moe_gemm_q decode loads and one-trip run search, hc_read's prefill form
  (+3.7% prefill at 18K), hc_up row groups up to eight, the fused router launch. Each is the rule
  where it was measured faster; no environment switches.
- Tool calls: a typed argument is always JSON (Python True/None no longer leak into arguments --
  Codeberg #21); nine further reply-parser fixes; the reply path inside a call is ~12x cheaper on
  the host.
- The kernel changes: prefill +2-3% and decode -2% a step on 2x R9700 at tp2, identical text.
2026-10-06 14:04:49 +02:00

89 lines
3.0 KiB
C++

/* hostarena.cpp -- see hostarena.h. */
#include "mem/hostarena.h"
#include "rad_internal.h"
namespace rad {
HostArena::~HostArena() { close(); }
int HostArena::open(int64_t slot_bytes, int64_t cap_bytes) {
close();
if (slot_bytes <= 0 || cap_bytes < slot_bytes) return RAD_E_INVAL;
const int64_t n = cap_bytes / slot_bytes;
/* PINNED, and the allocation is refused rather than downgraded. A pageable host buffer on
* this path does not fail, it just collapses -- an async copy to pageable memory serialises
* against the stream and the whole point of moving instead of dropping is gone. Better to
* start without the store and say so than to run it at a tenth of the rate it was budgeted
* at. */
base_ = rad_dev_alloc(n * slot_bytes, RAD_MEM_HOST_PINNED);
if (!base_) return RAD_E_NOMEM;
slot_bytes_ = slot_bytes;
used_ = 0;
cap_slots_ = n;
cursor_ = 0;
bits_.assign((size_t)((n + 63) / 64), 0ull);
return RAD_OK;
}
void HostArena::close() {
if (base_) rad_dev_free(base_, RAD_MEM_HOST_PINNED);
base_ = nullptr;
slot_bytes_ = 0;
used_ = 0;
cap_slots_ = 0;
cursor_ = 0;
bits_.clear();
}
int32_t HostArena::alloc() {
int32_t got = 0;
return alloc_run(1, &got);
}
/* THE FIRST FREE RUN AT OR AFTER THE CURSOR, wrapping once. A whole word of used slots is skipped
* in one compare, so a nearly full arena costs a scan of its bitmap -- a few thousand words at the
* sizes an operator gives this -- and an arena with room costs nothing. The cursor makes
* consecutive calls hand out consecutive slots, which is what lets a batch be one copy a run. */
int32_t HostArena::alloc_run(int32_t want, int32_t* got) {
*got = 0;
if (want <= 0 || !base_ || full()) return -1;
int64_t s = -1;
for (int pass = 0; pass < 2 && s < 0; ++pass) {
const int64_t lo = pass == 0 ? cursor_ : 0;
const int64_t hi = pass == 0 ? cap_slots_ : cursor_;
for (int64_t i = lo; i < hi;) {
const uint64_t w = bits_[(size_t)(i >> 6)];
if ((i & 63) == 0 && w == ~0ull) { i += 64; continue; }
if (!is_used(i)) { s = i; break; }
++i;
}
}
if (s < 0) return -1;
int64_t n = 0;
while (n < want && s + n < cap_slots_ && !is_used(s + n)) {
bits_[(size_t)((s + n) >> 6)] |= 1ull << ((s + n) & 63);
++n;
}
used_ += n;
cursor_ = s + n >= cap_slots_ ? 0 : s + n;
*got = (int32_t)n;
return (int32_t)s;
}
void HostArena::free(int32_t slot) {
if (slot < 0 || slot >= cap_slots_) return;
/* A slot that is already free is refused rather than counted twice: the used count is what the
* sessions view reports and what `full` answers, and a negative one hides the next leak. */
if (!is_used(slot)) return;
bits_[(size_t)(slot >> 6)] &= ~(1ull << (slot & 63));
--used_;
}
void* HostArena::at(int32_t slot) const {
if (!base_ || slot < 0 || slot >= cap_slots_) return nullptr;
return (char*)base_ + (int64_t)slot * slot_bytes_;
}
} /* namespace rad */