prefill: key recordings by live split geometry

This commit is contained in:
Constantin authored and StillDeadcode committed 2026-11-03 19:05:30 +01:00
1 parent 61e275e30f
commit ded64c0bd3
16 files changed
+204 -16

No files matched your search

+10 -1
View File
@@ -31,11 +31,15 @@ int Ctx::init(const CtxDesc& d) {
registry_ = d.registry;
kv_ = d.kv;
arch_step_ = d.arch_step;
arch_pass_key_ = d.arch_pass_key;
profiling_ = d.profile_ops;
/* The rank owns one device. Set it here so allocation lands on the right card, and again from
* the rank thread in bind_thread() because the backend's current device is thread-local. */
RAD_TRY(rad_dev_set(device_));
RadDeviceProps props{};
if (rad_dev_props(device_, &props) >= 0 && !props.is_host_backend && props.n_cu > 0)
wgp_count_ = props.n_cu;
if (d.stream) {
stream_ = d.stream;
@@ -944,7 +948,7 @@ int Ctx::lane_join(int from, int to) {
* field added to RadBatch changes its size: decide whether the key must read it, then update the
* size here. `agen_b`, `vgen_b` and `sgen_b` are set only on generator passes, which are never
* recorded (below). */
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 416,
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 424,
"RadBatch changed: check that Ctx::pass_key reads every new field a pass depends on");
static_assert(sizeof(void*) != 8 || sizeof(RadKVGroupBatch) == 80,
"RadKVGroupBatch changed: check that Ctx::pass_key reads every new field");
@@ -989,6 +993,11 @@ uint64_t Ctx::pass_key(const RadBatch* b) const {
/* A streamed group's view by the memory it names, never its address (kvstream_view_key). */
mix(kvstream_view_key(k.stream));
}
if (arch_pass_key_) {
const uint64_t geometry = arch_pass_key_(const_cast<Ctx*>(this), b, b->kv_used_max_h);
if (!geometry) return 0;
mix(geometry);
}
mix((uint64_t)level_);
mix(dense_epoch_);
mix(domain_epoch_.load(std::memory_order_relaxed));
+4
View File
@@ -192,6 +192,7 @@ struct CtxDesc {
RadStream stream = nullptr; /* null: the Ctx creates its own compute stream */
ResidencyTable* residency = nullptr; /* null in the all-in-VRAM case */
ArchStepFn arch_step = nullptr; /* the architecture plugin's rad_arch_step */
uint64_t (*arch_pass_key)(RadCtx*, const RadBatch*, const int32_t*) = nullptr;
bool profile_ops = false; /* spec §16, and it changes what you measure */
/* Whether a repeated pass may be recorded and played back. False for a caller whose pass
* issues work the batch does not describe (e.g. a test driving another component through
@@ -256,6 +257,7 @@ public:
}
/* This rank's device ordinal, for the calls that name a card rather than a stream. */
int device() const { return device_; }
int wgp_count() const { return wgp_count_; }
int world_size() const { return world_size_; }
RadStream stream() const { return stream_; }
Program* program() const { return program_; }
@@ -653,6 +655,8 @@ private:
bool staging_ = false; /* the stager armed for the pass being issued */
int issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n);
ArchStepFn arch_step_ = nullptr;
uint64_t (*arch_pass_key_)(RadCtx*, const RadBatch*, const int32_t*) = nullptr;
int wgp_count_ = 32;
/* The expert prefetch's state (xp_state.h), null while it is off. */
std::unique_ptr<XpState> xp_;
+3
View File
@@ -1280,6 +1280,9 @@ int rad_kv_layer_index(RadCtx* c, rad_kvgroup group, int layer) {
}
int rad_rank(RadCtx* c) { return c ? static_cast<rad::Ctx*>(c)->rank() : 0; }
int rad_world_size(RadCtx* c) { return c ? static_cast<rad::Ctx*>(c)->world_size() : 1; }
int rad_ctx_wgp_count(RadCtx* c) {
return c ? static_cast<rad::Ctx*>(c)->wgp_count() : 32;
}
RadStream rad_stream(RadCtx* c) { return c ? static_cast<rad::Ctx*>(c)->stream() : nullptr; }
/* The second lane. `rad_lane` selects the lane subsequent issues launch on; `rad_lane_join`