Merge branch 'pr1-device' into pr2-engine

This commit is contained in:
C_Tamas committed 2026-10-25 17:19:16 +07:00
commit 06172e98de
49 files changed
+2100 -205

No files matched your search

+1
View File
@@ -199,6 +199,7 @@ private:
/* init() for every surviving instance, after the whole graph has resolved, so a failing init
* cannot abort declare before the miss report is assembled. */
void finish_instances();
void fill_tune_instances();
int32_t find_kv_consumer(rad_kvgroup g);
void finish_layouts();
void finish_kv_groups();
+25
View File
@@ -501,6 +501,7 @@ void Builder::record_tune_request(const Resolved& r) {
req.geom = r.geom;
req.geom_key = r.geom_key;
req.info = r.row->info;
req.instance = r.instance;
prog_.tune_requests.push_back(std::move(req));
}
@@ -611,6 +612,29 @@ void Builder::finish_instances() {
}
}
}
/* The instances are made in finish_instances(), after record_tune_request ran, so the requests
* now carry the instance their kernel will launch with. A collective's launch cannot be formed
* without it -- the peer bundle (scratch, flags, sequence counters) is what init() builds and
* RadArgs reaches the exchange through nothing else -- so the tuner forms its launches from this.
* Keyed exactly as record_tune_request keyed. */
void Builder::fill_tune_instances() {
for (size_t i = 1; i < prog_.ops.size(); ++i) {
const OpInfo& oi = prog_.ops[i];
for (const Band& b : oi.bands)
for (int d = 0; d < RAD_N_DOMAINS; ++d) {
const Resolved& r = b.dom[d];
if (!r || !r.row || !r.row->info) continue;
const std::string key = r.row->info->name + std::string("\x1f") + r.row->plugin +
std::string("\x1f") + r.geom_key;
for (auto& t : prog_.tune_requests)
if (t.kernel + std::string("\x1f") + t.plugin + std::string("\x1f") +
t.geom_key == key)
t.instance = r.instance;
}
}
}
rad_op Builder::decl_op(const char* opname, const RadParam* p, int n_p,
const rad_weight* w, int n_w) {
if (finished_) return err(RAD_E_STATE, "decl_op('%s') after declare finished", opname ? opname : "");
@@ -2410,6 +2434,7 @@ int Builder::finish() {
}
if (instances_) finish_instances();
fill_tune_instances();
finish_weight_uses();
finish_layouts();
finish_kv_groups();
+1
View File
@@ -535,6 +535,7 @@ int dev_code_runs(size_t from, size_t to, int device, std::string* why) {
extern "C" {
int rad_dev_peer_access(int self, int peer) { return rad::dev_peer_access(self, peer); }
int rad_event_create_as(RadEvent* out, unsigned flags) {
const int s = dev()->event_create(out, flags);
+4
View File
@@ -425,6 +425,10 @@ int Engine::step_loop() {
/* The next step's forward pass when already issued behind the previous step, before its
* readback (Scheduler::step_next). */
const RadBatch* ahead = nullptr;
/* Names where the step loop waits when nothing has been logged for a while: a freeze reports
* the blocked thread, its syscall and its stack; long quiet generations report sparsely (the
* silence doubles) and the reports read as the ordinary GPU wait. */
rad::StallWatch step_watch("step", 20000);
while (!stopping_.load(std::memory_order_acquire)) {
lora_epoch_.fetch_add(1, std::memory_order_acq_rel);
phase_t_ = std::chrono::steady_clock::now();
+7
View File
@@ -508,6 +508,13 @@ public:
Geometry geom;
std::string geom_key;
const RadKernelInfo* info = nullptr;
/* The instance init() produced for this instantiation, null for a kernel with no init.
* A collective's launch cannot be formed without it: the peer bundle -- the scratch, the
* flags and the sequence counters, published to every rank and made peer-accessible at
* init -- is what makes the exchange addressable, and RadArgs carries no other route to
* it. The instance belongs to the rank this Program was declared for (Program::ctx), and
* the Registry that made it must outlive the launch (spec §1, §15). */
void* instance = nullptr;
};
std::vector<TuneRequest> tune_requests;
+7 -3
View File
@@ -595,8 +595,12 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
: "has no device kernel for this band");
/* The second lane's window (rad_lane1_window_begin): its concurrent buffers are live only across
* it, so lane 1 runs nothing outside it, and lane 0 joins lane 1 before it runs an op outside
* it, on either side: a transient of such an op may share bytes with a concurrent buffer. */
if (program_ && program_->lane1_w1 >= 0) {
* it, on either side: a transient of such an op may share bytes with a concurrent buffer. An op
* that names no buffer (a weight read into the cache, prefetch_beside) touches nothing the window
* keeps live and has no transient: it runs on lane 1 anywhere and leaves no window work to join. */
bool names_buf = false;
for (int i = 0; i < n_opd && !names_buf; ++i) names_buf = opd[i].kind == RAD_OPK_BUF;
if (program_ && program_->lane1_w1 >= 0 && names_buf) {
const bool outside = p.order < program_->lane1_w0 || p.order > program_->lane1_w1;
if (lane_ == 1 && outside)
return abort_step_msg(h, RAD_E_STATE,
@@ -610,7 +614,7 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
return abort_step_msg(h, js, "joining the second lane outside its window failed");
}
}
if (lane_ == 1) lane1_pending_ = true;
if (lane_ == 1 && names_buf) lane1_pending_ = true;
/* The row's DIV on the ranged parameter held at the band's upper bound, maybe not here. */
if (ip.ranged_div > 1 && n % ip.ranged_div != 0)
+17 -8
View File
@@ -13,6 +13,13 @@
namespace rad {
/* How many steps of the following prompt the PLE read-ahead queue stages (RadBatch::n_ahead):
* the arch's reader thread drains the queue at disk speed, off the step path, so a prefill
* chunk's table rows are already cached when its gather runs. Keep in step with rad_block_ple.h
* (kAheadChunks), which clamps to the buffer it declared; a mismatch degrades to a smaller queue,
* never an overflow. */
static constexpr int64_t k_ahead_chunks = 8;
/* Alignment of each staging array carved from a set's slab. One slab per set means a couple of
* allocations at init instead of two dozen, with every array sharing one mapping. */
static const int64_t k_carve_align = 256;
@@ -98,9 +105,10 @@ void BatchBuilder::carve(Set& s, char* h) {
*ph = ::rad::carve<int32_t>(h, oh, n);
*pd = ::rad::carve<int32_t>(d, od, n);
};
/* Twice the step: its own tokens, then up to a step of the following prompt
* (RadBatch::n_ahead). */
pair(&s.h_tok, &s.d_tok, 2 * T);
/* The step's tokens, then the PLE read-ahead queue -- k_ahead_chunks steps of the following
* prompt (RadBatch::n_ahead), which the arch's reader thread prefetches off the step path
* (rad_block_ple.h, which clamps to the same count). */
pair(&s.h_tok, &s.d_tok, (1 + k_ahead_chunks) * T);
pair(&s.h_pos, &s.d_pos, T);
pair(&s.h_parent, &s.d_parent, T);
pair(&s.h_cu, &s.d_cu, S + 1);
@@ -1052,17 +1060,18 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
}
}
/* Up to a step of the last sequence's following tokens, after this step's own
* (RadBatch::n_ahead). Only on a trunk pass whose last entry is a prefill chunk, bounded by
* the tokens the request has; like token_at, a re-prefill after preemption continues into its
* own output. */
/* Up to the read-ahead queue's worth of the last sequence's following tokens, after this
* step's own (RadBatch::n_ahead). Only on a trunk pass whose last entry is a prefill chunk,
* bounded by the tokens the request has; like token_at, a re-prefill after preemption
* continues into its own output. The arch clamps to the rows it declared. */
int64_t n_ahead = 0;
if (n_seq > 0 && plan.draft_pass == 0 && plan.tok_shift == 0) {
const StepEntry& e = plan.e[(size_t)(n_seq - 1)];
if (e.req && e.is_prefill) {
const int64_t next = (int64_t)e.ctx_len + e.n_tokens;
const int64_t have = (int64_t)e.req->prompt.size() + (int64_t)e.req->output.size();
n_ahead = std::min<int64_t>(std::max<int64_t>(have - next, 0), max_tok_);
n_ahead = std::min<int64_t>(std::max<int64_t>(have - next, 0),
k_ahead_chunks * max_tok_);
for (int64_t j = 0; j < n_ahead; ++j) s.h_tok[n_tok + j] = token_at(e, next + j);
}
}