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/runtime/arena.h
T
Deadcode 1e968f6e1d radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
2026-10-16 18:25:18 +02:00

73 lines
3.3 KiB
C++

/* arena.h -- one contiguous allocation, sized by the buffer plan at load and never allocated from
* at runtime.
*
* There is deliberately no allocate(): an allocator on the step path is the dynamic behaviour this
* engine exists to remove (spec §3.1). Offsets come from the buffer plan, which computes liveness
* over the declared op list for the worst step; the arena only owns the block they index into.
*
* Scratch sits at the tail and is shared by every op on a stream, which is safe because launches
* on one stream execute in order. A context's second lane is a second stream, so a program that
* declares one gets a second region per lane (Program::scratch_regions). A lane used without that
* declaration shares region 0, and Ctx::issue orders a scratch user behind an unordered one on the
* other lane. Program::scratch_bytes is the largest single kernel's requirement; a kernel asking
* for more is refused by name in prepare.
*/
#pragma once
#include "../rad_core.h"
namespace rad {
class Arena {
public:
Arena() = default;
~Arena() { release(); }
Arena(const Arena&) = delete;
Arena& operator=(const Arena&) = delete;
/* `kind` is a RAD_MEM_* class: RAD_MEM_DEVICE for the device arena, RAD_MEM_HOST for the
* second arena a program with RAD_DOMAIN_HOST buffers gets. `regions` scratch regions of
* `scratch_bytes` each sit at the tail, one per lane. */
int init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions = 1);
void release();
char* base() const { return base_; }
/* Region `r`, or region 0 when the arena holds fewer. */
void* scratch(int r = 0) const {
if (!base_) return nullptr;
return base_ + scratch_off_ + (r > 0 && r < scratch_regions_ ? r * scratch_pitch_ : 0);
}
int64_t scratch_bytes() const { return scratch_bytes_; }
int scratch_regions() const { return scratch_regions_; }
int64_t bytes() const { return bytes_; }
bool live() const { return base_ != nullptr; }
private:
char* base_ = nullptr;
int kind_ = RAD_MEM_DEVICE;
int64_t bytes_ = 0;
int64_t scratch_off_ = 0;
int64_t scratch_bytes_ = 0;
int64_t scratch_pitch_ = 0; /* scratch_bytes_ padded to RAD_ALIGN_UNIT */
int scratch_regions_ = 1;
};
/* The arena's size, computed without allocating it. Shared by Ctx::bind_arena (allocates at the
* end of startup) and the VRAM budget resolver (subtracts it before the pools are allocated), so
* the two cannot drift apart and overcommit the card.
*
* `dev_out` is the plan_bytes the device arena's init() receives; `total_out` is what it
* allocates, plan and scratch both padded to RAD_ALIGN_UNIT as Arena::init pads them.
* Returns the total. */
int64_t arena_plan_bytes(const Program& P, int64_t* dev_out, int64_t* total_out);
/* The host activation arena's size (the RAD_DOMAIN_HOST buffers), which Ctx::bind_arena pins and
* maps at the end of startup; 0 when the program declares none. */
int64_t arena_host_bytes(const Program& P);
/* The arena level a step of `rows` tokens runs at: the smallest level that holds it, or 0 (the
* full plan) when none does. `level_rows[k]` is the largest step level k serves; entry 0 is the
* full plan and is never chosen by size. */
int arena_level_for(const std::vector<int64_t>& level_rows, int64_t rows);
} /* namespace rad */