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/xp_state.h
T
Deadcode dc339b4cd2 radiance 1.4.0
- Qwen3.8-Flash-Next on one card: the heat engine moves 64 experts a step (was 8), its copies and
  the prefill's expert staging run on the card's DMA engines instead of as copy kernels, and at
  decode the next layer's likeliest experts are copied onto the card ahead of its GEMMs. Against
  1.3.0 at --tp 1: prefill +17-20% from 8K tokens up, throughput under load +16-20%
- deploy/compose/flashnext-tp1.yaml: Qwen3.8-Flash-Next on one card and 64 GB of host RAM
  (4096-token prefill steps, 4 sequences, a 301K-token cache)
- #61: --busy-prefill-chunk (default auto): a long prefill leaves the rest of the step to the
  requests decoding beside it and to new arrivals, instead of taking all of it (baKon)
- LiquidAI's LFM2 and LFM2-VL, and d1's /v1/systemone (after zivius's PR #50)
- a startup report: every option with its value and where it came from, the hardware, and what
  on it costs speed with the fix; /diagnostics serves it (behind the API key; without one, only
  to the same machine)
- #69: a GPU memory fault names the buffer and kernel argument behind it and ends the server at
  once (exit status 70), instead of hanging or writing a core of tens of gigabytes
- #64: a card without Resizable BAR is refused at startup, naming what to turn on, instead of
  crashing at the first launch
- the image is built with ROCm 10.1 (the host's amdgpu driver must support it), with ROCm's
  libLLVM rebuilt so the same source compiles to the same kernels every time; a source build
  takes ROCm 10.1 or 7.2
- #71: the image ships curl, jq and a CA bundle, so --model <HF repo id> works in the container,
  and hfget.sh runs under its busybox (baKon)
- --profile-ops shows how long each op's lane sat idle before it; cardclock.py skips an
  integrated GPU instead of stopping
2026-10-12 11:46:14 +02:00

83 lines
3.7 KiB
C++

/* xp_state.h -- the expert prefetch's host state, held by the Ctx (Ctx::xp_). See xprefetch.h. */
#pragma once
#include "xprefetch.h"
#include "rad_runtime.h"
#include "../device/device.h"
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <deque>
#include <mutex>
#include <string>
#include <thread>
#include <utility>
#include <vector>
namespace rad {
/* A routed layer as the prefetch knows it: the next-layer description a plugin hands over, and the
* device map from expert to its table entries, built at the first call after the layer's tables are
* bound. `want` is the request made for it this pass, which its step patches in. */
struct XpLayer {
RadPrefetchNext next{};
void** map = nullptr; /* device [kXpMaxNe][kXpParts]: entry addresses, null for none */
int32_t* place = nullptr; /* device [kXpMaxNe]: the expert's place in the routing counts */
bool bound = false;
bool want = false;
int g = 0;
uint32_t seq = 0;
};
/* A request: the group's mailbox the plan writes, and the mark the DMA list waits for. */
struct XpReq {
int g = 0;
uint32_t seq = 0;
void* mark = nullptr;
RadStream ms = nullptr; /* the stream the mark rides */
bool valid = false;
};
struct XpState {
int device = 0;
RadStream stream = nullptr; /* logits and plan, behind rides on the compute stream */
RadEvent tail = nullptr; /* the pass start waits for the stream's work of the last */
RadEvent sync = nullptr; /* the router input's readiness, where a ride is refused */
bool tail_live = false;
char* ring = nullptr; /* uncached: kXpGroups x kXpSlots slots of `slot` bytes */
uint64_t slot = 0;
XpPools pools{};
XpRec* rec = nullptr; /* [kXpGroups][kXpSlots] */
int32_t* nrec = nullptr; /* [kXpGroups] */
XpBox* box = nullptr; /* [kXpGroups], pinned host */
uint32_t* done = nullptr; /* [kXpGroups], pinned host: the last request whose copies landed */
XpStats* stats = nullptr; /* device */
XpStats* stats_h = nullptr; /* pinned host, read at the end */
float* logits = nullptr; /* [kXpGroups][kXpMaxRows][kXpMaxNe] */
void** maps = nullptr; /* [layers][kXpMaxNe][kXpParts] */
int32_t* places = nullptr; /* [layers][kXpMaxNe] */
std::vector<XpLayer> layers;
uint32_t seq[kXpGroups] = {};
int last_layer = -1; /* the last layer predicted for: a lower one starts a pass */
/* WHETHER IT PAYS: the share of its copies the steps use, judged every kXpWindow predictions from
* the counters (stats_h, one window on their way to the host); under kXpMinUse it rests. */
int64_t passes = 0, rest_until = 0, rests = 0;
int64_t calls = 0;
uint32_t snap_copied = 0, snap_routed = 0;
bool have_snap = false, judge = false;
int restore_g = -1; /* the group the next step puts back */
XpReq pend; /* made at a router, waiting for its mark */
/* The host thread: each mailbox, once the plan has written it, to the DMA queue. */
std::thread thr;
std::mutex mu;
std::condition_variable cv;
std::deque<XpReq> q;
std::atomic<bool> stop{false};
std::deque<std::pair<void*, int64_t>> marks; /* thread only: a mark and the list that polls it */
int64_t lists = 0; /* thread only: lists handed over */
std::atomic<int64_t> dropped{0}; /* requests the queue was too far behind for */
};
} /* namespace rad */