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/engine_gen.cpp
T
Deadcode 816e24bd46 radiance 1.8.1
- MiniMax-H3 and FastH3 no longer stop the server on a prompt longer than 16 tokens (FastH3) or
  128 tokens (MiniMax-H3)
- latent upscaling for the MiniMax-H3 containers: with LBH-123-AI's latent upscaler in the
  container, `latent_upscale` runs the first steps at a smaller size and refines the latent at the
  full size; `upscale_refine_steps` sets how many steps refine, and the video object reports both
- rad-convert --in-place extends a container whose weights the plugin has regrouped since
- plugin ABI 22: out-of-tree plugins must be rebuilt
2026-10-18 15:41:44 +02:00

91 lines
3.7 KiB
C++

/* engine_gen.cpp -- a generator's loop: the driver's passes (core/gen/pass.h; driver.h for
* images, audio_driver.h for audio, video_driver.h for video) run on the ranks like token steps, one at a time, each drained
* before the next.
*
* Draining is cheap: a pass is tens to thousands of milliseconds of device work, and the next
* pass depends only on the driver's host bookkeeping, so the wait costs the microseconds of
* building it. Issuing ahead would need a second staging region and a commit protocol.
*/
#include "engine_priv.h"
#include "gen/pass.h"
#include <chrono>
#include <thread>
namespace rad {
/* A generator pass's kind, for the buffer probe's lines. */
static const char* pass_name(int gen) {
switch (gen) {
case RAD_GEN_PASS_COND: return "cond";
case RAD_GEN_PASS_DENOISE: return "denoise";
case RAD_GEN_PASS_DECODE: return "decode";
case RAD_GEN_PASS_PROMPT: return "prompt";
case RAD_GEN_PASS_FRAME: return "frame";
case RAD_GEN_PASS_WINDOW: return "window";
case RAD_GEN_PASS_VOCODE: return "vocode";
case RAD_GEN_PASS_VCOND: return "vcond";
case RAD_GEN_PASS_VSTEP: return "vstep";
case RAD_GEN_PASS_ADECODE: return "adecode";
case RAD_GEN_PASS_VDECODE: return "vdecode";
case RAD_GEN_PASS_VUPSCALE: return "vupscale";
default: return "";
}
}
int Engine::gen_loop() {
if (rad_dev_set(ranks_[0]->device) < 0)
RAD_ERR("generator loop: could not bind rank 0's device");
int step = 0, idle = 0;
/* An error ends the driver's requests, then the loop. */
auto stop = [&](int st) {
gen_->shutdown("the engine stopped on an error and is not serving", st);
return fail_loop(st);
};
while (!stopping_.load(std::memory_order_acquire)) {
const RadBatch* b = gen_->next(step);
if (!b) {
step_batch_.store(nullptr, std::memory_order_release);
if (idle < 200) ++idle;
std::this_thread::sleep_for(std::chrono::microseconds(idle * 50));
continue;
}
idle = 0;
if (const int ps = prepare_release(b); ps < 0) return stop(ps);
issue_what_.store(kIssueModel, std::memory_order_release);
step_batch_.store(b, std::memory_order_release);
barrier_->arrive_and_wait(); /* release the ranks */
barrier_->arrive_and_wait(); /* wait for them */
int st = step_status_.load(std::memory_order_acquire);
if (st < 0) {
RAD_ERR("generator pass %d failed: %s -- the engine cannot continue", step,
rad_strerror(st));
return stop(st);
}
/* What the pass leaves for the host (an image, a window's samples, the frames' status),
* copied behind it on rank 0's stream; every rank holds the same values. */
for (const gen::IPassDriver::Readback& r : gen_->readbacks()) {
if (st < 0 || r.bytes <= 0) continue;
const void* src = ranks_[0]->ctx.buf_ptr(r.buf);
if (!src) {
RAD_ERR("the generator's output buffer '%s' was declared but never planned",
ranks_[0]->program.buffers[r.buf].name.c_str());
return stop(RAD_E_STATE);
}
st = rad_memcpy_async(r.host, src, r.bytes, ranks_[0]->ctx.stream());
}
for (auto& rk : ranks_)
if (st >= 0) st = rad_stream_sync(rk->ctx.stream());
if (st < 0) {
RAD_ERR("generator pass %d: the device failed: %s", step, rad_strerror(st));
return stop(st);
}
dump_buffers(ranks_[0]->ctx, step, pass_name(b->gen));
gen_->done();
++step;
}
return RAD_OK;
}
} /* namespace rad */