Archived
radiance 1.0.5
- Answers no longer stop partway through. A request without max_tokens got 512 tokens, and a reasoning model can think for thousands before it answers, so the reply ended inside the reasoning with finish_reason "length", which chat clients do not show. It now gets whatever the context leaves after the prompt, as in vLLM. --default-max-tokens N sets a number, and --max-tokens-cap bounds every request. - Qwen3.8-Flash-Next in Docker without --security-opt seccomp=unconfined is refused at startup, in about a second, with a message naming that option. It used to load the whole model and then fail every request as "unsupported", and a restart policy reloaded it over and over. The n-gram table is read through io_uring, which Docker's default seccomp profile refuses. - A request the engine fails says what failed, in the 500 or the stream's error event. It read "the engine failed this request: ok". - Flash-Next no longer crashes at startup about one start in seven (a race between the parallel declares that size the activation arena). - rad-convert no longer needs io_uring, so it converts in a sandbox that forbids it.
This commit is contained in:
1 parent
09fb41735b
commit
6c11671bdd
30 files changed
+541
-120
No files matched your search
@@ -165,6 +165,14 @@ public:
|
||||
* laid over the real ones. */
|
||||
void set_reference(const Program* ref) { ref_ = ref; }
|
||||
|
||||
/* WITHOUT INSTANCES: finish() selects every kernel and initialises none. For a caller that
|
||||
* launches nothing -- rad-convert plans a container's stored form, which is the kernels'
|
||||
* layouts and not their setup. A kernel's init is about the process it runs in (a ring, a
|
||||
* peer's buffers) and the conversion is often not that process: libavx's n-gram gather
|
||||
* refuses a process that may not make an io_uring ring, and a sandbox that forbids one still
|
||||
* has to be able to convert the model. */
|
||||
void set_instances(bool on) { instances_ = on; }
|
||||
|
||||
Program& program() { return prog_; }
|
||||
const Program& program() const { return prog_; }
|
||||
|
||||
@@ -195,6 +203,7 @@ private:
|
||||
Registry& reg_;
|
||||
Program prog_;
|
||||
const Program* ref_ = nullptr;
|
||||
bool instances_ = true;
|
||||
|
||||
std::vector<std::string> errors_;
|
||||
int status_ = RAD_OK;
|
||||
|
||||
@@ -1498,7 +1498,7 @@ int Builder::finish() {
|
||||
w.source.c_str(), rad_dtype_name(w.decl.dtype));
|
||||
}
|
||||
|
||||
finish_instances();
|
||||
if (instances_) finish_instances();
|
||||
finish_weight_uses();
|
||||
finish_layouts();
|
||||
finish_kv_groups();
|
||||
|
||||
@@ -319,7 +319,7 @@ std::vector<std::string> CheckpointSources::refused() const {
|
||||
|
||||
int rad_tools_declare(const LoadedPlugins& lp, const RadModelMeta& meta, const RadBuildCtx& ctx,
|
||||
Program* out, const std::function<int(RadBuilder*, int64_t)>& also,
|
||||
const Program* ref, const WeightSourceFn& sources) {
|
||||
const Program* ref, const WeightSourceFn& sources, bool instances) {
|
||||
if (!out) return RAD_E_INVAL;
|
||||
|
||||
Registry& r = rad_tools_registry();
|
||||
@@ -334,6 +334,7 @@ int rad_tools_declare(const LoadedPlugins& lp, const RadModelMeta& meta, const R
|
||||
Builder b(r, meta, ctx);
|
||||
if (ref) b.set_reference(ref);
|
||||
if (sources) b.set_sources(sources);
|
||||
b.set_instances(instances);
|
||||
|
||||
int s = ap->arch_declare(&b, &meta, &ctx);
|
||||
if (s < 0) {
|
||||
|
||||
@@ -88,10 +88,13 @@ const RadChatFormat* rad_tools_chat_format(const LoadedPlugins& plugins, const R
|
||||
* or initialised. The Program that comes back is for its buffers and nothing else. */
|
||||
/* `sources` answers rad_weight_encoding (Builder::set_sources): a container's entries, a
|
||||
* checkpoint's tensors, or a recipe. Empty, every weight is read as plain in its declared dtype. */
|
||||
/* `instances` false selects every kernel and initialises none (Builder::set_instances): for a
|
||||
* caller that launches nothing, such as rad-convert planning a container's stored form. */
|
||||
int rad_tools_declare(const LoadedPlugins& plugins, const RadModelMeta& meta,
|
||||
const RadBuildCtx& ctx, Program* out,
|
||||
const std::function<int(RadBuilder*, int64_t logits_width)>& also = {},
|
||||
const Program* ref = nullptr, const WeightSourceFn& sources = {});
|
||||
const Program* ref = nullptr, const WeightSourceFn& sources = {},
|
||||
bool instances = true);
|
||||
|
||||
/* A container's entries as the source of every declaration's encoding. `f` must outlive the
|
||||
* declare. */
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ static const Flag g_flags[] = {
|
||||
{ "--dry-sequence-breakers", "JSON", "default dry_sequence_breakers, a JSON array of at most 16 strings" },
|
||||
{ "--xtc-probability", "F", "default xtc_probability, [0, 1]" },
|
||||
{ "--xtc-threshold", "F", "default xtc_threshold, [0, 1]" },
|
||||
{ "--default-max-tokens", "N", "max_tokens for requests that do not set one (default 512). `auto` is\n"
|
||||
{ "--default-max-tokens", "N", "max_tokens for requests that do not set one: N, or `auto` (default),\n"
|
||||
" whatever the context leaves after the prompt" },
|
||||
{ "--max-tokens-cap", "N", "the most any request may generate. A larger max_tokens is cut to it rather\n"
|
||||
" than refused, and the reply ends with finish_reason \"length\". 0 is none\n"
|
||||
|
||||
+6
-5
@@ -383,7 +383,7 @@ void Engine::phase_mark(int p) {
|
||||
int Engine::fail_loop(int st) {
|
||||
stopping_.store(true, std::memory_order_release);
|
||||
if (barrier_) barrier_->abort();
|
||||
sched_.shutdown("the engine stopped on an error and is not serving");
|
||||
sched_.shutdown("the engine stopped on an error and is not serving", st < 0 ? st : RAD_E_STATE);
|
||||
loop_status_.store(st < 0 ? st : RAD_E_STATE, std::memory_order_release);
|
||||
return st;
|
||||
}
|
||||
@@ -2027,12 +2027,13 @@ int Engine::run_server() {
|
||||
o.default_reasoning_effort = cfg_.reasoning_effort;
|
||||
o.default_sampling = resolve_sampling_defaults(meta_, file_ != nullptr, cfg_);
|
||||
o.default_dry_breakers_set = cfg_.sample_dry_seq_breakers.has_value();
|
||||
/* -1 leaves ServerOptions' own default. `auto` (0) is resolved per request against the
|
||||
* context, so it needs one to resolve against. */
|
||||
/* -1 leaves ServerOptions' own default, which is `auto` (0). That is resolved per request
|
||||
* against the context, so it needs one to resolve against. */
|
||||
if (cfg_.default_max_tokens >= 0) o.default_max_tokens = cfg_.default_max_tokens;
|
||||
if (o.default_max_tokens == 0 && o.max_ctx <= 0) {
|
||||
RAD_ERR("--default-max-tokens auto is what the context leaves, and this model states no "
|
||||
"context; pass --max-model-len");
|
||||
RAD_ERR("a request that names no max_tokens gets what the context leaves after its prompt "
|
||||
"(--default-max-tokens auto), and this model states no context; pass "
|
||||
"--max-model-len, or --default-max-tokens N");
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
o.max_tokens_cap = cfg_.max_tokens_cap;
|
||||
|
||||
+3
-2
@@ -687,8 +687,9 @@ struct Config {
|
||||
sample_dry_penalty_last_n;
|
||||
std::optional<std::vector<std::string>> sample_dry_seq_breakers;
|
||||
|
||||
/* --default-max-tokens: what a request that names no max_tokens may generate. -1 is unset
|
||||
* (the server's 512), 0 is `auto` (whatever the context leaves after the prompt). */
|
||||
/* --default-max-tokens: what a request that names no max_tokens may generate. -1 is unset,
|
||||
* which is the server's default, `auto`; 0 is `auto` stated (whatever the context leaves after
|
||||
* the prompt). */
|
||||
int64_t default_max_tokens = -1;
|
||||
/* --max-tokens-cap: the most any request may generate. A larger max_tokens is clamped to it,
|
||||
* the way the context clamps one, and the reply ends with finish_reason "length". 0 is none. */
|
||||
|
||||
+28
-19
@@ -100,40 +100,46 @@ class Geometry {
|
||||
public:
|
||||
Geometry() = default;
|
||||
|
||||
/* The cached RadParam view holds char* into THIS object's own strings. An implicit copy would
|
||||
* carry those pointers into the copy along with dirty_ = false, so the copy would hand a
|
||||
* kernel pointers that dangle the moment the source dies -- and every Resolved holds a
|
||||
* Geometry while every Band holds two, so this type is copied constantly. A copy therefore
|
||||
* takes the storage and NOT the view, and rebuilds on first use.
|
||||
/* THE RadParam VIEW IS KEPT CURRENT BY EVERY WRITE, never built on first read. It holds char*
|
||||
* into this object's own strings, and a view rebuilt lazily from a const reader is a write
|
||||
* that two readers can make at once: the sizing declares of one rank all read the real
|
||||
* program's geometries side by side (Engine::probe_arena_levels), and one clearing the view
|
||||
* while another filled it is the heap corruption that crashed startup. So params() writes
|
||||
* nothing, and a Geometry nobody is writing can be read from any number of threads.
|
||||
*
|
||||
* The move is the same rule for a different reason: a moved-from vector's buffer may be
|
||||
* stolen, so the view's pointers stop meaning anything even though nothing was destroyed. */
|
||||
* A copy takes the storage and builds its own view, because the source's points into the
|
||||
* source. A move takes the view along with the storage: the vectors hand over their arrays,
|
||||
* so every string stays where it was and every pointer stays good. The moved-from object is
|
||||
* emptied, view included, so it is a valid empty geometry rather than one whose view names
|
||||
* strings it no longer owns. */
|
||||
Geometry(const Geometry& o)
|
||||
: keys_(o.keys_), svals_(o.svals_), ivals_(o.ivals_), dvals_(o.dvals_), kinds_(o.kinds_) {}
|
||||
: keys_(o.keys_), svals_(o.svals_), ivals_(o.ivals_), dvals_(o.dvals_), kinds_(o.kinds_) {
|
||||
rebuild();
|
||||
}
|
||||
|
||||
Geometry& operator=(const Geometry& o) {
|
||||
if (this != &o) {
|
||||
keys_ = o.keys_; svals_ = o.svals_; ivals_ = o.ivals_; dvals_ = o.dvals_;
|
||||
kinds_ = o.kinds_;
|
||||
view_.clear(); dirty_ = true;
|
||||
rebuild();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Geometry(Geometry&& o) noexcept
|
||||
: keys_(std::move(o.keys_)), svals_(std::move(o.svals_)),
|
||||
ivals_(std::move(o.ivals_)), dvals_(std::move(o.dvals_)),
|
||||
kinds_(std::move(o.kinds_)) {
|
||||
o.view_.clear(); o.dirty_ = true;
|
||||
view_(std::move(o.view_)), ivals_(std::move(o.ivals_)),
|
||||
dvals_(std::move(o.dvals_)), kinds_(std::move(o.kinds_)) {
|
||||
o.clear();
|
||||
}
|
||||
|
||||
Geometry& operator=(Geometry&& o) noexcept {
|
||||
if (this != &o) {
|
||||
keys_ = std::move(o.keys_); svals_ = std::move(o.svals_);
|
||||
view_ = std::move(o.view_);
|
||||
ivals_ = std::move(o.ivals_); dvals_ = std::move(o.dvals_);
|
||||
kinds_ = std::move(o.kinds_);
|
||||
view_.clear(); dirty_ = true;
|
||||
o.view_.clear(); o.dirty_ = true;
|
||||
o.clear();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -149,17 +155,20 @@ public:
|
||||
const char* get_s(std::string_view k) const;
|
||||
bool has(std::string_view k) const;
|
||||
|
||||
/* A view suitable for RadArgs.p. Valid while this object lives. */
|
||||
const RadParam* params() const;
|
||||
int n_params() const;
|
||||
/* A view suitable for RadArgs.p. Valid while this object lives and is not written. */
|
||||
const RadParam* params() const { return view_.data(); }
|
||||
int n_params() const { return (int)view_.size(); }
|
||||
|
||||
std::string str() const; /* "M=64 N=8192 K=5120 dtype=w4a8", for diagnostics */
|
||||
|
||||
private:
|
||||
std::vector<std::string> keys_, svals_;
|
||||
std::vector<RadParam> view_;
|
||||
mutable bool dirty_ = true;
|
||||
void rebuild() const;
|
||||
void rebuild();
|
||||
void clear() noexcept {
|
||||
keys_.clear(); svals_.clear(); view_.clear(); ivals_.clear(); dvals_.clear();
|
||||
kinds_.clear();
|
||||
}
|
||||
std::vector<long long> ivals_;
|
||||
std::vector<double> dvals_;
|
||||
std::vector<int> kinds_;
|
||||
|
||||
@@ -98,6 +98,7 @@ int Scheduler::init(Program& prog, const Config& cfg, IKVManager* kv, IPrefixCac
|
||||
ctx_limit_ = builder_.max_ctx();
|
||||
n_deferred_ = 0;
|
||||
closed_ = false;
|
||||
closed_status_ = RAD_E_STATE;
|
||||
|
||||
/* Everything the step path touches is reserved here. A vector that grows during a step is an
|
||||
* allocator call on the path this whole component exists to keep clear. */
|
||||
@@ -152,7 +153,7 @@ int Scheduler::add_locked(std::unique_ptr<Request> r) {
|
||||
* listening to -- and the refusal says why. */
|
||||
if (closed_) {
|
||||
RAD_WARN("request %llu refused: %s", (unsigned long long)r->id, closed_reason_);
|
||||
server::sink_fail(r->sink, RAD_E_STATE);
|
||||
server::sink_fail(r->sink, closed_status_, closed_reason_);
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
|
||||
@@ -312,7 +313,7 @@ void Scheduler::trim_prefix_cache() {
|
||||
}
|
||||
|
||||
void Scheduler::close_request(SchedReq& s, ReqState st, const char* reason, bool defer_free,
|
||||
bool publish) {
|
||||
bool publish, int status, const char* why) {
|
||||
/* PUBLISH BEFORE FREEING. This is the only moment the sequence's whole prefix is both
|
||||
* computed and still owned, and it is what makes the cache a cache rather than a permanently
|
||||
* empty lookup: insert() takes its own KV references, so the blocks survive the free below.
|
||||
@@ -359,7 +360,8 @@ void Scheduler::close_request(SchedReq& s, ReqState st, const char* reason, bool
|
||||
/* Terminal, and idempotent on the sink's side: the first call wins, so a cancel racing a
|
||||
* natural stop does not produce two finish reasons. This is the last thing the producer does
|
||||
* to the sink, and the HTTP thread is waiting on exactly it. */
|
||||
server::sink_finish(s.req->sink, finish_of(st, s.req->finish_reason));
|
||||
if (st == ReqState::Failed && status < 0) server::sink_fail(s.req->sink, status, why);
|
||||
else server::sink_finish(s.req->sink, finish_of(st, s.req->finish_reason));
|
||||
}
|
||||
|
||||
int Scheduler::cancel(uint64_t id) {
|
||||
@@ -467,10 +469,11 @@ void Scheduler::release_deferred() {
|
||||
sweep_deferred();
|
||||
}
|
||||
|
||||
void Scheduler::shutdown(const char* reason) {
|
||||
void Scheduler::shutdown(const char* reason, int status) {
|
||||
std::lock_guard<std::mutex> lk(mu_);
|
||||
closed_ = true;
|
||||
closed_reason_ = reason ? reason : "the engine has stopped";
|
||||
closed_status_ = status < 0 ? status : RAD_E_STATE;
|
||||
/* Copied first: close_request erases from both queues. */
|
||||
std::vector<int32_t> live(running_);
|
||||
live.insert(live.end(), waiting_.begin(), waiting_.end());
|
||||
@@ -478,7 +481,7 @@ void Scheduler::shutdown(const char* reason) {
|
||||
SchedReq& s = *reqs_[(size_t)slot];
|
||||
if (!s.req) continue;
|
||||
close_request(s, ReqState::Failed, closed_reason_, /*defer_free=*/false,
|
||||
/*publish=*/false);
|
||||
/*publish=*/false, closed_status_, closed_reason_);
|
||||
++m_.failed;
|
||||
completed_.push_back(s.req->id);
|
||||
}
|
||||
@@ -944,7 +947,8 @@ const RadBatch* Scheduler::step() {
|
||||
kv_->can_ever_fit(r.n_computed + want)
|
||||
? " and nothing lower-priority is left to preempt"
|
||||
: " at any occupancy");
|
||||
close_request(s, ReqState::Failed, "kv_exhausted");
|
||||
close_request(s, ReqState::Failed, "kv_exhausted", false, true, RAD_E_FULL,
|
||||
"the KV pool cannot hold it");
|
||||
++m_.failed;
|
||||
completed_.push_back(r.id);
|
||||
failed = true;
|
||||
@@ -1035,7 +1039,8 @@ const RadBatch* Scheduler::step() {
|
||||
RAD_WARN("request %llu failed: %lld tokens leave no room in a %lld-token context",
|
||||
(unsigned long long)s.req->id, (long long)s.seq_len(),
|
||||
(long long)ctx_limit_);
|
||||
close_request(s, ReqState::Failed, "context_length_exceeded");
|
||||
close_request(s, ReqState::Failed, "context_length_exceeded", false, true,
|
||||
RAD_E_FULL, "it leaves no room in the context");
|
||||
++m_.failed;
|
||||
completed_.push_back(s.req->id);
|
||||
continue;
|
||||
|
||||
+10
-4
@@ -238,8 +238,9 @@ public:
|
||||
|
||||
/* THE ENGINE HAS STOPPED AND WILL RUN NO MORE STEPS. Every request still queued or running is
|
||||
* failed with `reason` so its connection is answered rather than left waiting on a step that
|
||||
* will never come, and any request submitted afterwards is refused the same way. */
|
||||
void shutdown(const char* reason);
|
||||
* will never come, and any request submitted afterwards is refused the same way. `status` is
|
||||
* what stopped it, and what each of those requests reports. */
|
||||
void shutdown(const char* reason, int status = RAD_E_STATE);
|
||||
|
||||
/* The waiting queue in SERVICE order, by request id -- what the live view shows and what a
|
||||
* test asserts a preempted request re-entered at the front of. Returns how many were written. */
|
||||
@@ -522,6 +523,7 @@ private:
|
||||
/* Set by shutdown(); add() refuses from then on. */
|
||||
bool closed_ = false;
|
||||
const char* closed_reason_ = "";
|
||||
int closed_status_ = RAD_E_STATE;
|
||||
|
||||
/* THE LONGEST SEQUENCE THIS DEPLOYMENT CAN ADDRESS, prompt and output together. The batch
|
||||
* builder sizes its block tables for it and the rotary tables are this long, so no position
|
||||
@@ -631,9 +633,13 @@ private:
|
||||
|
||||
/* lifecycle */
|
||||
/* `publish` is false only when the engine is shutting down: a sequence the device may have
|
||||
* left half-computed is not worth indexing, and nothing will ever hit it. */
|
||||
* left half-computed is not worth indexing, and nothing will ever hit it.
|
||||
*
|
||||
* A FAILED REQUEST SAYS WHAT FAILED: its sink is failed with `status` and `why`, which the
|
||||
* server puts in the error the client gets. RAD_OK leaves a sink that has failed already (an
|
||||
* overflow) as it is. */
|
||||
void close_request(SchedReq& s, ReqState st, const char* reason, bool defer_free = false,
|
||||
bool publish = true);
|
||||
bool publish = true, int status = RAD_OK, const char* why = nullptr);
|
||||
/* What reap() does once nothing points at the slot any more: give the blocks back, forget the
|
||||
* id, destroy the Request and return the slot. Called by reap() directly, or by the sweep in
|
||||
* commit() for a request whose reap arrived while something still pointed at it. */
|
||||
|
||||
+7
-2
@@ -109,8 +109,13 @@ struct OaiLimits {
|
||||
std::string model_id = "radiance";
|
||||
int64_t max_ctx = 0; /* 0 = unknown, no length check */
|
||||
/* What a request that names no max_tokens may generate. 0 is "whatever the context leaves",
|
||||
* resolved against the prompt in clamp_max_tokens. */
|
||||
int64_t default_max_tokens = 512;
|
||||
* resolved against the prompt in clamp_max_tokens, which needs max_ctx to resolve against.
|
||||
*
|
||||
* 0 BY DEFAULT, as vLLM's is: many clients send no max_tokens, and a reasoning model spends
|
||||
* the first thousands of tokens of an answer thinking. A fixed default of 512 ended those
|
||||
* answers inside the reasoning, with finish_reason "length" that a chat client does not show,
|
||||
* so they read as a model that stops at random. */
|
||||
int64_t default_max_tokens = 0;
|
||||
/* The most any request may generate; a larger max_tokens is clamped, not refused. 0 = none. */
|
||||
int64_t max_tokens_cap = 0;
|
||||
int max_n = 8;
|
||||
|
||||
+13
-4
@@ -412,6 +412,16 @@ bool Server::pump(std::vector<Generation>& gens, const OaiRequest& r) {
|
||||
|
||||
/* ------------------------------------------------------------------ metrics bookkeeping */
|
||||
|
||||
/* WHAT FAILED, for the client: the sentence the failing component gave, and the status. A failed
|
||||
* request always carries a status -- an engine that stopped carries the one that stopped it -- so
|
||||
* this never reads "ok". */
|
||||
static std::string engine_failure(const Sink& s) {
|
||||
const int st = s.status() < 0 ? s.status() : RAD_E_STATE;
|
||||
const char* why = s.why();
|
||||
return why ? fmt("the engine failed this request: %s (%s)", why, rad_strerror(st))
|
||||
: fmt("the engine failed this request: %s", rad_strerror(st));
|
||||
}
|
||||
|
||||
static SuccessReason to_reason(Finish f) {
|
||||
switch (f) {
|
||||
case Finish::Length: return SuccessReason::Length;
|
||||
@@ -536,14 +546,14 @@ HttpResponse Server::blocking_completion(const HttpRequest& req, OaiRequest& r)
|
||||
/* An engine-side failure is not a 200 with an empty answer. */
|
||||
for (auto& g : gens) {
|
||||
if (g.finish == Finish::Error) {
|
||||
int st = g.sink->status();
|
||||
const std::string why = engine_failure(*g.sink);
|
||||
retire(gens);
|
||||
release(r.n_choices());
|
||||
record(r, gens, Finish::Error);
|
||||
ApiError e;
|
||||
e.status = 500;
|
||||
e.type = "internal_server_error";
|
||||
e.message = std::string("the engine failed this request: ") + rad_strerror(st);
|
||||
e.message = why;
|
||||
return error_response(e);
|
||||
}
|
||||
}
|
||||
@@ -689,8 +699,7 @@ HttpResponse Server::streaming_completion(const HttpRequest& req, OaiRequest& r)
|
||||
ApiError e;
|
||||
e.status = 500;
|
||||
e.type = "internal_server_error";
|
||||
e.message = std::string("the engine failed this request: ") +
|
||||
rad_strerror(g.sink->status());
|
||||
e.message = engine_failure(*g.sink);
|
||||
out += sse_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ struct ServerOptions {
|
||||
int retry_after_s = 1;
|
||||
|
||||
int64_t max_ctx = 0;
|
||||
int64_t default_max_tokens = 512; /* 0: what the context leaves (OaiLimits) */
|
||||
int64_t default_max_tokens = 0; /* 0: what the context leaves (OaiLimits) */
|
||||
int64_t max_tokens_cap = 0; /* 0: none */
|
||||
int max_n = 8;
|
||||
int64_t max_stops = 64;
|
||||
|
||||
@@ -89,8 +89,9 @@ void Sink::finish(Finish f) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sink::fail(int rad_status) {
|
||||
void Sink::fail(int rad_status, const char* why) {
|
||||
status_.store(rad_status, std::memory_order_release);
|
||||
why_.store(why, std::memory_order_release);
|
||||
finish(Finish::Error);
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -79,7 +79,9 @@ public:
|
||||
/* Terminal. Idempotent -- the first call wins, so a cancel racing a natural stop does not
|
||||
* produce two finish reasons. */
|
||||
void finish(Finish f);
|
||||
void fail(int rad_status);
|
||||
/* `why` says what failed, in a sentence a client can read; a string that outlives the sink
|
||||
* (a literal), or null. */
|
||||
void fail(int rad_status, const char* why = nullptr);
|
||||
|
||||
/* The scheduler polls this to learn that the client hung up, and frees the blocks (spec §14).
|
||||
* It is also told by IScheduler::cancel(); this is the cheap path that needs no lookup. */
|
||||
@@ -100,6 +102,7 @@ public:
|
||||
bool done() const { return finish_.load(std::memory_order_acquire) != (int)Finish::None; }
|
||||
Finish finish_reason() const { return (Finish)finish_.load(std::memory_order_acquire); }
|
||||
int status() const { return status_.load(std::memory_order_acquire); }
|
||||
const char* why() const { return why_.load(std::memory_order_acquire); }
|
||||
bool overflowed() const { return overflow_.load(std::memory_order_acquire); }
|
||||
|
||||
/* The HTTP thread calls this when the peer disappears. It does NOT free anything itself --
|
||||
@@ -135,6 +138,7 @@ private:
|
||||
|
||||
std::atomic<int> finish_{(int)Finish::None};
|
||||
std::atomic<int> status_{RAD_OK};
|
||||
std::atomic<const char*> why_{nullptr};
|
||||
std::atomic<bool> overflow_{false};
|
||||
std::atomic<bool> cancel_{false};
|
||||
std::atomic<bool> quiesced_{false}; /* the producer will not touch this object again */
|
||||
@@ -159,8 +163,8 @@ inline bool sink_push(void* s, int32_t token, float logprob = 0.0f) {
|
||||
inline void sink_finish(void* s, Finish f) {
|
||||
if (s) static_cast<Sink*>(s)->finish(f);
|
||||
}
|
||||
inline void sink_fail(void* s, int rad_status) {
|
||||
if (s) static_cast<Sink*>(s)->fail(rad_status);
|
||||
inline void sink_fail(void* s, int rad_status, const char* why = nullptr) {
|
||||
if (s) static_cast<Sink*>(s)->fail(rad_status, why);
|
||||
}
|
||||
inline bool sink_cancelled(const void* s) {
|
||||
return s && static_cast<const Sink*>(s)->cancel_requested();
|
||||
|
||||
+13
-15
@@ -156,35 +156,35 @@ std::vector<std::string_view> split_ws(std::string_view s) {
|
||||
* touches this at declare, not per step. A hash map here would be slower and less predictable. */
|
||||
void Geometry::set_i(std::string_view k, long long v) {
|
||||
for (size_t i = 0; i < keys_.size(); ++i)
|
||||
if (keys_[i] == k) { kinds_[i] = RAD_P_INT; ivals_[i] = v; dirty_ = true; return; }
|
||||
if (keys_[i] == k) { kinds_[i] = RAD_P_INT; ivals_[i] = v; rebuild(); return; }
|
||||
keys_.emplace_back(k);
|
||||
svals_.emplace_back();
|
||||
ivals_.push_back(v);
|
||||
dvals_.push_back(0.0);
|
||||
kinds_.push_back(RAD_P_INT);
|
||||
dirty_ = true;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void Geometry::set_f(std::string_view k, double v) {
|
||||
for (size_t i = 0; i < keys_.size(); ++i)
|
||||
if (keys_[i] == k) { kinds_[i] = RAD_P_F64; dvals_[i] = v; dirty_ = true; return; }
|
||||
if (keys_[i] == k) { kinds_[i] = RAD_P_F64; dvals_[i] = v; rebuild(); return; }
|
||||
keys_.emplace_back(k);
|
||||
svals_.emplace_back();
|
||||
ivals_.push_back(0);
|
||||
dvals_.push_back(v);
|
||||
kinds_.push_back(RAD_P_F64);
|
||||
dirty_ = true;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void Geometry::set_s(std::string_view k, std::string_view v) {
|
||||
for (size_t i = 0; i < keys_.size(); ++i)
|
||||
if (keys_[i] == k) { kinds_[i] = RAD_P_STR; svals_[i] = std::string(v); dirty_ = true; return; }
|
||||
if (keys_[i] == k) { kinds_[i] = RAD_P_STR; svals_[i] = std::string(v); rebuild(); return; }
|
||||
keys_.emplace_back(k);
|
||||
svals_.emplace_back(v);
|
||||
ivals_.push_back(0);
|
||||
dvals_.push_back(0.0);
|
||||
kinds_.push_back(RAD_P_STR);
|
||||
dirty_ = true;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
bool Geometry::get_i(std::string_view k, long long* out) const {
|
||||
@@ -210,10 +210,12 @@ bool Geometry::has(std::string_view k) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Geometry::rebuild() const {
|
||||
auto* self = const_cast<Geometry*>(this);
|
||||
self->view_.clear();
|
||||
self->view_.reserve(keys_.size());
|
||||
/* Every key and every string value may have moved: an append can reallocate keys_ and svals_, and
|
||||
* a short string lives inside its element. So the whole view is redone, which is the same handful
|
||||
* of entries the setter's scan already walked. */
|
||||
void Geometry::rebuild() {
|
||||
view_.clear();
|
||||
view_.reserve(keys_.size());
|
||||
for (size_t i = 0; i < keys_.size(); ++i) {
|
||||
RadParam p{};
|
||||
p.key = keys_[i].c_str();
|
||||
@@ -221,14 +223,10 @@ void Geometry::rebuild() const {
|
||||
p.ival = ivals_[i];
|
||||
p.dval = dvals_[i];
|
||||
p.sval = kinds_[i] == RAD_P_STR ? svals_[i].c_str() : nullptr;
|
||||
self->view_.push_back(p);
|
||||
view_.push_back(p);
|
||||
}
|
||||
dirty_ = false;
|
||||
}
|
||||
|
||||
const RadParam* Geometry::params() const { if (dirty_) rebuild(); return view_.data(); }
|
||||
int Geometry::n_params() const { if (dirty_) rebuild(); return (int)view_.size(); }
|
||||
|
||||
std::string Geometry::str() const {
|
||||
std::string s;
|
||||
for (size_t i = 0; i < keys_.size(); ++i) {
|
||||
|
||||
Reference in new issue
Block a user