Archived
device and plugin boundary: kv_resolve, the streamed store rows, ABI 30
This commit is contained in:
1 parent
5a9ce4912b
commit
cce687bf2c
34 files changed
+3643
-29
No files matched your search
+44
-5
@@ -2668,9 +2668,10 @@ int64_t a_gate_room(RadStream rs) {
|
||||
|
||||
/* Waits for the mark, then for the card's link gate if a collective has ever held it (under TP
|
||||
* the all-reduce shares the link and the step waits on it, not on these copies), copies, writes
|
||||
* `done`, then the list's number. */
|
||||
* `done`, then the list's number. RAD_XP_NO_YIELD skips the gate: a list the compute stream waits on
|
||||
* cannot outlast a hold whose release is behind that wait (core/kvstream/stage.cpp). */
|
||||
int a_xp_list(int ord, void* mark, int n, const uint64_t* src, const uint64_t* dst, const uint64_t* bytes,
|
||||
uint32_t* done, uint32_t done_val) {
|
||||
uint32_t* done, uint32_t done_val, unsigned flags) {
|
||||
DmaQueue* dq = xp_queue(ord);
|
||||
if (!dq) return RAD_E_UNSUPPORTED;
|
||||
Sig* in = (Sig*)mark;
|
||||
@@ -2684,7 +2685,8 @@ int a_xp_list(int ord, void* mark, int n, const uint64_t* src, const uint64_t* d
|
||||
10u /* interval */ | (0xfffu << 16) /* retry forever */ };
|
||||
rc = dma_put(dq, poll, 6);
|
||||
}
|
||||
if (rc == RAD_OK && n > 0 && lane && lane->ever_held && lane->gate.handle) {
|
||||
if (rc == RAD_OK && n > 0 && lane && lane->ever_held && lane->gate.handle &&
|
||||
!(flags & RAD_XP_NO_YIELD)) {
|
||||
const uint64_t ga = (uint64_t)lane->gate.handle + offsetof(amd_signal_t, value);
|
||||
const uint32_t gate[6] = { kSdmaPoll | (3u << 28) /* equal */ | (1u << 31) /* memory */,
|
||||
(uint32_t)ga, (uint32_t)(ga >> 32), 0u, 1u /* the low bit */,
|
||||
@@ -2719,6 +2721,34 @@ int a_xp_list(int ord, void* mark, int n, const uint64_t* src, const uint64_t* d
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* An event the DMA engine completes (rad_event_dma): a fresh completion word for the event, which
|
||||
* a rad_xp_list writes 0 to as its `done` once its bytes have landed, so a stream that waits on the
|
||||
* event stops until the copy is done.
|
||||
*
|
||||
* The word comes back at 0 and the *caller* arms it with a write of 1 on the stream, because the arm
|
||||
* must be ordered: a host store here would land ahead of a wait still queued for the group's previous
|
||||
* copy (which would then block on this 1 and never see its 0), and an event record would not do
|
||||
* either -- a record completes by decrementing its signal to 0, which is the value the wait is
|
||||
* looking for. A fresh signal each time keeps two uses of one word from overlapping at all. */
|
||||
int a_event_dma(RadEvent re, RadStream rs, uint32_t** word) {
|
||||
if (!word) { device_set_error("rad_event_dma: null word"); return RAD_E_INVAL; }
|
||||
if (capturing()) {
|
||||
device_set_error("rad_event_dma: a tape cannot record a DMA list; the caller must re-run "
|
||||
"this call with the tape paused");
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
Event* e = ev_of(re);
|
||||
Stream* s = ours(rs);
|
||||
if (!e || !s) { device_set_error("rad_event_dma: null or foreign argument"); return RAD_E_INVAL; }
|
||||
Sig* g = sig_get(e->host);
|
||||
if (!g) { device_set_error("rad_event_dma: no signal could be made"); return RAD_E_DEVICE; }
|
||||
hsa_signal_silent_store_relaxed(g->h, 0);
|
||||
g->agent = s->agent;
|
||||
record_adopt(e, g);
|
||||
*word = (uint32_t*)(uintptr_t)sig_value_addr(g);
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int64_t a_xp_behind(int ord) {
|
||||
DmaQueue* dq = (ord >= 0 && ord < kMaxDevices) ? &g_dma_xp[ord] : nullptr;
|
||||
if (!dq || !dq->tried.load(std::memory_order_acquire) || !dq->ok) return 0;
|
||||
@@ -3376,9 +3406,17 @@ void* pin_pieces(int64_t bytes) {
|
||||
char* const p = (char*)at;
|
||||
|
||||
prefer_numa_node(p, len, current_card_numa_node());
|
||||
/* RADIANCE_NO_HUGE_PAGES asks for small pages, before the pin faults them in: the KV mirror's
|
||||
* scattered 2 KiB reads are the case page size is supposed to matter for, and this is how that
|
||||
* is measured rather than assumed (core/kvstream/mirror.cpp). Not a supported mode. */
|
||||
const bool small_pages = std::getenv("RADIANCE_NO_HUGE_PAGES") != nullptr;
|
||||
if (len >= ((int64_t)2 << 20)) {
|
||||
::madvise(p, (size_t)len, MADV_HUGEPAGE);
|
||||
warn_if_no_huge_pages();
|
||||
if (small_pages) {
|
||||
::madvise(p, (size_t)len, MADV_NOHUGEPAGE);
|
||||
} else {
|
||||
::madvise(p, (size_t)len, MADV_HUGEPAGE);
|
||||
warn_if_no_huge_pages();
|
||||
}
|
||||
}
|
||||
(void)::madvise(p, (size_t)len, MADV_DONTFORK);
|
||||
|
||||
@@ -3604,6 +3642,7 @@ const DeviceBackend* aql_backend_if_present(void) {
|
||||
g_aql.stream_gate = a_stream_gate;
|
||||
g_aql.gate_open = a_gate_open;
|
||||
g_aql.gate_room = a_gate_room;
|
||||
g_aql.event_dma = a_event_dma;
|
||||
return &g_aql;
|
||||
}();
|
||||
return b;
|
||||
|
||||
+20
-2
@@ -113,13 +113,27 @@ extern "C" void* rad_link_gate(RadStream s);
|
||||
* counts lists handed over and not yet finished. The prefetch ring is uncached device memory
|
||||
* (rad_dev_alloc_uncached): the engine writes it and kernels read it, so no cache may hold a
|
||||
* slot's previous contents. */
|
||||
/* An event the DMA engine completes instead of a dispatch: it is recorded on `s` (a write of 1 to
|
||||
* its completion word, in stream order) and `*word` returns that word for `rad_xp_list` to write 0
|
||||
* to as the list's `done`, once the list's bytes have landed. `rad_event_wait(s, ev)` then stops `s`
|
||||
* until the copy is done, device-side: no host round trip on the step path. The caller waits for
|
||||
* the group's previous copy before arming the next, so the word's older 0 cannot release a later
|
||||
* wait. RAD_E_STATE while a tape is recording: a list is not a queue packet, so a recorded pass
|
||||
* must re-run the call with the tape paused (core/kvstream/stage.cpp). */
|
||||
extern "C" int rad_event_dma(RadEvent ev, RadStream s, uint32_t** word);
|
||||
extern "C" int rad_xp_supported(int device);
|
||||
extern "C" int rad_xp_stream_create(RadStream* out);
|
||||
extern "C" int rad_ride(RadStream s, void** token);
|
||||
extern "C" int rad_ride_wait(RadStream s, void* token);
|
||||
extern "C" void rad_ride_release(void* token, RadStream after, int64_t packets);
|
||||
/* `flags` RAD_XP_NO_YIELD: the list does not give way to a link a stream of this card holds. A copy
|
||||
* the compute stream itself waits on must set it -- a yield it cannot outlast is a deadlock (the
|
||||
* hold's release is behind the wait) -- at the cost of taking its share of the link in one piece
|
||||
* (core/kvstream/stage.cpp). The expert prefetch passes 0: nothing waits for it. */
|
||||
#define RAD_XP_NO_YIELD 1u
|
||||
extern "C" int rad_xp_list(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst,
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val);
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val,
|
||||
unsigned flags);
|
||||
extern "C" int64_t rad_xp_behind(int device);
|
||||
extern "C" void* rad_dev_alloc_uncached(int64_t bytes);
|
||||
extern "C" void rad_dev_free_uncached(void* p);
|
||||
@@ -316,7 +330,7 @@ struct DeviceBackend {
|
||||
int (*ride_wait)(RadStream s, void* token);
|
||||
void (*ride_release)(void* token, RadStream after, int64_t packets);
|
||||
int (*xp_list)(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst,
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val);
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val, unsigned flags);
|
||||
int64_t (*xp_behind)(int device);
|
||||
void* (*alloc_uncached)(int64_t bytes);
|
||||
void (*free_uncached)(void* p);
|
||||
@@ -325,6 +339,10 @@ struct DeviceBackend {
|
||||
int (*stream_gate)(RadStream s, void** gate);
|
||||
int (*gate_open)(void* gate);
|
||||
int64_t (*gate_room)(RadStream s);
|
||||
|
||||
/* ---- an event a DMA list completes: see rad_event_dma. Null (unsupported) on a backend with
|
||||
* no DMA queue that writes a completion word. */
|
||||
int (*event_dma)(RadEvent e, RadStream s, uint32_t** word);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -549,6 +549,11 @@ void rad_event_destroy(RadEvent e) {
|
||||
dev()->event_destroy(e);
|
||||
}
|
||||
int rad_event_record(RadEvent e, RadStream s) { return dev()->event_record(e, s); }
|
||||
int rad_event_dma(RadEvent e, RadStream s, uint32_t** w) {
|
||||
if (const auto f = dev()->event_dma) return f(e, s, w);
|
||||
rad::device_set_error("rad_event_dma: the device backend has no DMA queue to complete an event");
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
int rad_event_wait(RadStream s, RadEvent e) { return dev()->event_wait(s, e); }
|
||||
int rad_event_query(RadEvent e) { return dev()->event_query(e); }
|
||||
int rad_event_sync(RadEvent e) {
|
||||
@@ -630,8 +635,8 @@ void rad_ride_release(void* token, RadStream after, int64_t packets) {
|
||||
if (const auto f = dev()->ride_release) f(token, after, packets);
|
||||
}
|
||||
int rad_xp_list(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst, const uint64_t* bytes,
|
||||
uint32_t* done, uint32_t done_val) {
|
||||
if (const auto f = dev()->xp_list) return f(device, mark, n, src, dst, bytes, done, done_val);
|
||||
uint32_t* done, uint32_t done_val, unsigned flags) {
|
||||
if (const auto f = dev()->xp_list) return f(device, mark, n, src, dst, bytes, done, done_val, flags);
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
int64_t rad_xp_behind(int device) {
|
||||
|
||||
@@ -816,6 +816,7 @@ const DeviceBackend g_host = {
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
|
||||
h_stream_gate, h_gate_open, h_gate_room,
|
||||
nullptr, /* no DMA queue, so no event it could complete */
|
||||
};
|
||||
|
||||
} /* namespace */
|
||||
|
||||
+17
-3
@@ -3,6 +3,8 @@
|
||||
*/
|
||||
#include <vector>
|
||||
#include "ctx.h"
|
||||
#include "kvstream/bind.h"
|
||||
#include "kvstream/stage.h"
|
||||
#include "xp_state.h"
|
||||
#include "../device/device.h"
|
||||
|
||||
@@ -921,7 +923,7 @@ int Ctx::lane_join(int from, int to) {
|
||||
* (below). */
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 360,
|
||||
"RadBatch changed: check that Ctx::pass_key reads every new field a pass depends on");
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadKVGroupBatch) == 72,
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadKVGroupBatch) == 80,
|
||||
"RadKVGroupBatch changed: check that Ctx::pass_key reads every new field");
|
||||
|
||||
uint64_t Ctx::pass_key(const RadBatch* b) const {
|
||||
@@ -957,6 +959,11 @@ uint64_t Ctx::pass_key(const RadBatch* b) const {
|
||||
mix((uint64_t)k.group); ptr(k.slot_mapping); ptr(k.block_table);
|
||||
mix((uint64_t)k.block_table_pitch); ptr(k.seqused); ptr(k.state_index);
|
||||
mix((uint64_t)k.state_index_pitch); mix((uint64_t)k.block_size); mix((uint64_t)k.max_blocks);
|
||||
/* Null on a fully resident group, a fixed set of addresses on a streamed one. Two groups
|
||||
* that differ here hand a kernel different memory, so they are different passes -- and the
|
||||
* view's *address* must not enter the key: the builder's Out slot rotates every step, which
|
||||
* would make every streamed pass a new one (kvstream/bind.h, kvstream_view_key). */
|
||||
mix(kvstream_view_key(k.stream));
|
||||
}
|
||||
mix((uint64_t)level_);
|
||||
mix(dense_epoch_);
|
||||
@@ -1229,6 +1236,12 @@ int Ctx::play_pass(PassTape& t) {
|
||||
rc = xp_ ? xp_step_run(st.a) : RAD_OK;
|
||||
lane_ = l0;
|
||||
break;
|
||||
case kTapeKvStage:
|
||||
case kTapeKvStageAfter:
|
||||
lane_ = st.lane;
|
||||
rc = kvstage_run(this, st.a, st.b, st.kind == kTapeKvStageAfter);
|
||||
lane_ = l0;
|
||||
break;
|
||||
}
|
||||
if (rc < 0) {
|
||||
if (step_status_ >= 0) step_status_ = rc;
|
||||
@@ -1254,7 +1267,8 @@ int Ctx::run_pass(const RadBatch* b) {
|
||||
/* A pass the stager armed for is issued live: see runtime/stager.h. */
|
||||
if (!tape_on_ || staging_) { bump(pc_unkeyed_); arch_step_(this, b); return RAD_OK; }
|
||||
const uint64_t key = pass_key(b);
|
||||
if (key == 0) { bump(pc_unkeyed_); arch_step_(this, b); return RAD_OK; }
|
||||
if (key == 0) { bump(pc_unkeyed_); arch_step_(this, b);
|
||||
return RAD_OK; }
|
||||
if (std::find(tape_refused_.begin(), tape_refused_.end(), key) != tape_refused_.end()) {
|
||||
bump(pc_refused_);
|
||||
arch_step_(this, b);
|
||||
@@ -1320,7 +1334,6 @@ int Ctx::run_pass(const RadBatch* b) {
|
||||
}
|
||||
|
||||
int Ctx::run_step(const RadBatch* b) {
|
||||
|
||||
if (!b) return RAD_E_INVAL;
|
||||
if (!arch_step_) {
|
||||
RAD_WARN("Ctx::run_step: no architecture step function was installed");
|
||||
@@ -1337,6 +1350,7 @@ int Ctx::run_step(const RadBatch* b) {
|
||||
step_status_ = RAD_OK;
|
||||
step_fail_.clear();
|
||||
prof_n_ = 0;
|
||||
kvstream_enter(this, b);
|
||||
{
|
||||
const int rc = run_pass(b);
|
||||
if (rc < 0 && step_status_ >= 0) step_status_ = rc;
|
||||
|
||||
+57
-1
@@ -141,6 +141,18 @@ struct RouteSlot {
|
||||
* LINEAR [n_states, n_head_kv, state_dim[0], state_dim[1]]
|
||||
* CONV [n_states, n_head_kv * head_dim, conv_slots] channel-major, then time
|
||||
*/
|
||||
/* One of the two views a streamed group's allocation is addressed through. `depth` is the number
|
||||
* of layer stripes the view presents: the ring keeps the group's `n_layers`, the stage presents
|
||||
* one and every layer aliases offset 0. The field is a depth and NOT a rewritten `layer_slot`:
|
||||
* that table is also the host mirror's row (rad_kv_layer_index), so collapsing it would write all
|
||||
* layers into one mirror row (docs/KV-STREAMING.md §3.5.1). */
|
||||
struct KVViewState {
|
||||
int64_t layer_stride = 0;
|
||||
int64_t bytes = 0;
|
||||
int64_t depth = 0; /* 0: n_layers; 1: every layer at offset 0 */
|
||||
int64_t shape0 = 0; /* the operand's [blocks] extent for this view */
|
||||
};
|
||||
|
||||
struct KVPoolBinding {
|
||||
void* base = nullptr;
|
||||
int64_t layer_stride = 0; /* bytes between one layer's cache and the next */
|
||||
@@ -152,8 +164,26 @@ struct KVPoolBinding {
|
||||
std::vector<int32_t> layer_slot;
|
||||
uint32_t rank = 0; /* 0 when the group has no plan: the operand stays a flat span */
|
||||
int64_t shape[RAD_MAX_RANK] = {0};
|
||||
/* The active view's stripe count: 0 is n_layers, 1 is the one-layer prefill stage. */
|
||||
int64_t depth = 0;
|
||||
/* Both fixed views over the group's one allocation. The ring is always present; the stage only
|
||||
* for a group whose plan depth is 1 (its ring is smaller than its context). The active fields
|
||||
* above are set from one of these before each pass (kvstream_enter), so a recorded pass that
|
||||
* used a view replays against it: the pass key already carries the phase, which selects it. */
|
||||
KVViewState ring;
|
||||
KVViewState stage;
|
||||
bool has_stage = false;
|
||||
/* Bytes of one layer's mirror row a staged pass must copy, from the block manager's highest
|
||||
* held block (kvstream/stage.h). 0 copies the whole row, which is always correct and is what a
|
||||
* caller with no manager (a test, a harness) leaves it at. Set once per step, before the pass,
|
||||
* because the bound grows as a prefill appends blocks. */
|
||||
int64_t stage_live_bytes = 0;
|
||||
};
|
||||
|
||||
/* The KV stage's driver, run again where a recorded pass made it (kvstream/stage.cpp). `after` is
|
||||
* the call the architecture makes after a layer's attention instead of before it. */
|
||||
int kvstage_run(Ctx* c, int group, int layer, bool after);
|
||||
|
||||
struct CtxDesc {
|
||||
Program* program = nullptr;
|
||||
int rank = 0;
|
||||
@@ -213,6 +243,20 @@ public:
|
||||
int rank() const { return rank_; }
|
||||
/* Whether repeated passes are recorded and played back (prepare() says when they are not). */
|
||||
bool records_passes() const { return tape_on_; }
|
||||
/* Whether the pass being issued is being recorded. Work a tape cannot record -- a DMA
|
||||
* submission -- must be re-run where the pass made it instead (tape_kv_stage). */
|
||||
bool recording() const { return rec_ != nullptr; }
|
||||
/* While recording: a KV stage call becomes a host step that re-runs at every play, because the
|
||||
* DMA list it hands the engine and the stream wait on the list's completion word are neither of
|
||||
* them queue packets (kvstream/stage.cpp; xprefetch.cpp does the same for the prefetch). */
|
||||
int tape_kv_stage(bool after, int group, int layer) {
|
||||
TapeStep st;
|
||||
st.kind = (uint8_t)(after ? kTapeKvStageAfter : kTapeKvStage);
|
||||
st.a = group;
|
||||
st.b = layer;
|
||||
return tape_host(st, [&] { return kvstage_run(this, group, layer, after); });
|
||||
} /* This rank's device ordinal, for the calls that name a card rather than a stream. */
|
||||
int device() const { return device_; }
|
||||
int world_size() const { return world_size_; }
|
||||
RadStream stream() const { return stream_; }
|
||||
Program* program() const { return program_; }
|
||||
@@ -230,6 +274,17 @@ public:
|
||||
|
||||
void* weight_ptr(rad_weight w);
|
||||
void* buf_ptr(rad_buf b);
|
||||
/* The group-local position of absolute model layer `layer` in the binding's layer_slot, or -1.
|
||||
* rad_kv_layer_index (rad_runtime.h) exposes it to a plugin, which needs it for the host
|
||||
* mirror: that is laid out by the group's layers, not by model layer numbers. */
|
||||
int64_t kv_layer_index(rad_kvgroup g, int layer) const;
|
||||
/* The group's pool binding, for the view switch and the stage copy. */
|
||||
const KVPoolBinding* kv_binding(rad_kvgroup g) const {
|
||||
return g < kv_.size() ? &kv_[(size_t)g] : nullptr;
|
||||
}
|
||||
KVPoolBinding* kv_binding(rad_kvgroup g) {
|
||||
return g < kv_.size() ? &kv_[(size_t)g] : nullptr;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- routing (spec §5.5) */
|
||||
int route_report(int layer, const RadRouting* r);
|
||||
@@ -435,7 +490,8 @@ private:
|
||||
* issue. A difference means the key misses a dependency; the step fails, naming the first
|
||||
* differing dispatch. */
|
||||
enum TapeKind : uint8_t { kTapePlay = 0, kTapeTable = 1, kTapeHost = 2, kTapeRoute = 3,
|
||||
kTapeXp = 4, kTapeXpMark = 5, kTapeXpStep = 6 };
|
||||
kTapeXp = 4, kTapeXpMark = 5, kTapeXpStep = 6,
|
||||
kTapeKvStage = 7, kTapeKvStageAfter = 8 };
|
||||
/* A prefetch call (Ctx::xp_predict), run again where the pass made it. */
|
||||
struct TapeXp {
|
||||
RadPrefetchNext next{};
|
||||
|
||||
+14
-1
@@ -19,6 +19,7 @@
|
||||
#include <cstdlib>
|
||||
#include "ctx.h"
|
||||
#include "device/device.h"
|
||||
#include "kvstream/bind.h"
|
||||
#include "wtab.h"
|
||||
|
||||
#include <cstring>
|
||||
@@ -802,7 +803,7 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
|
||||
const int64_t layer = (o.offset >= 0 && (size_t)o.offset < b.layer_slot.size())
|
||||
? b.layer_slot[(size_t)o.offset]
|
||||
: -1;
|
||||
const int64_t off = layer * b.layer_stride;
|
||||
const int64_t off = kv_binding_offset(b, layer);
|
||||
if (layer < 0 || (b.bytes && off + b.layer_stride > b.bytes))
|
||||
return abort_step_msg(h, RAD_E_INVAL,
|
||||
fmt("operand %d asks KV group %u for layer %lld, which is "
|
||||
@@ -1044,6 +1045,7 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
|
||||
g_iss_lau_p = g_iss_lau;
|
||||
}
|
||||
} else {
|
||||
/* The launch alone, split from the band scan and operand resolution `own` covers above. */
|
||||
s = ip.launch(la, cur_stream());
|
||||
}
|
||||
if (hold) {
|
||||
@@ -1251,6 +1253,17 @@ int rad_step_fail(RadCtx* c, const char* what) {
|
||||
}
|
||||
|
||||
const RadBatch* rad_batch(RadCtx* c) { return c ? static_cast<rad::Ctx*>(c)->batch() : nullptr; }
|
||||
|
||||
int64_t rad::Ctx::kv_layer_index(rad_kvgroup g, int layer) const {
|
||||
if (g >= kv_.size() || !kv_[g].base || layer < 0) return -1;
|
||||
const std::vector<int32_t>& ls = kv_[g].layer_slot;
|
||||
if ((size_t)layer >= ls.size()) return -1;
|
||||
return ls[(size_t)layer];
|
||||
}
|
||||
|
||||
int rad_kv_layer_index(RadCtx* c, rad_kvgroup group, int layer) {
|
||||
return c ? (int)static_cast<rad::Ctx*>(c)->kv_layer_index(group, layer) : -1;
|
||||
}
|
||||
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; }
|
||||
RadStream rad_stream(RadCtx* c) { return c ? static_cast<rad::Ctx*>(c)->stream() : nullptr; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* kvbind.cpp -- see kvbind.h. */
|
||||
#include "kvbind.h"
|
||||
|
||||
#include "kvstream/bind.h"
|
||||
#include "mem/kv.h"
|
||||
|
||||
namespace rad {
|
||||
@@ -12,6 +13,8 @@ void bind_kv_pools(const Program& p, const std::function<const KVGroupPlan*(int3
|
||||
const KVGroupPlan* gp = plan_of((int32_t)g);
|
||||
if (!gp) continue;
|
||||
KVPoolBinding& b = (*out)[g];
|
||||
/* Stateful groups keep these as they always were; a paged group's are overwritten by
|
||||
* kv_bind_views with the active view's arithmetic. */
|
||||
b.base = gp->base;
|
||||
b.layer_stride = gp->layer_stride();
|
||||
b.bytes = gp->pool_bytes;
|
||||
@@ -34,10 +37,15 @@ void bind_kv_pools(const Program& p, const std::function<const KVGroupPlan*(int3
|
||||
case RAD_KV_WINDOW:
|
||||
case RAD_KV_RING:
|
||||
b.rank = 4;
|
||||
b.shape[0] = gp->n_blocks;
|
||||
/* `shape[0]` follows the view and is filled by kv_bind_views below: the resident
|
||||
* window's depth for the ring, the group's context for the prefill stage
|
||||
* (docs/KV-STREAMING.md §3.1, §4.1). */
|
||||
b.shape[0] = gp->pool_blocks();
|
||||
b.shape[1] = d.n_head_kv;
|
||||
b.shape[2] = gp->block_size;
|
||||
b.shape[3] = 2 * d.head_dim;
|
||||
/* Both fixed views over the group's one allocation, with the ring active. */
|
||||
kv_bind_views(*gp, &b);
|
||||
break;
|
||||
case RAD_KV_LINEAR:
|
||||
b.rank = 4;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "runtime/tierexec.h"
|
||||
|
||||
#include "rad_internal.h"
|
||||
#include "kvstream/plan.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
@@ -31,12 +32,18 @@ int TierExec::configure(Registry* reg, KVManager* kv, IdleTiers* tiers,
|
||||
for (int32_t g : groups) {
|
||||
const KVGroupPlan* p = kv->plan(g);
|
||||
if (!p || !p->paged()) continue;
|
||||
/* A streamed group's pool is one layer of its context, so a gather of layer L would copy
|
||||
* the last staged layer n_layers times. Its mirror is the tier and the residency map
|
||||
* restores a block on the next resolve (docs/KV-STREAMING.md §4.1). */
|
||||
if (!kv_tier_cached(*p)) continue;
|
||||
GroupInfo gi;
|
||||
gi.g = g;
|
||||
gi.n_layers = p->n_layers;
|
||||
gi.frag = p->layer_bytes_per_block();
|
||||
gi.layer_stride = p->layer_stride();
|
||||
gi.n_blocks = p->n_blocks;
|
||||
/* The pool's depth: a streamed group backs fewer blocks than it addresses, and the tier
|
||||
* gathers fragments of the blocks that are here (docs/KV-STREAMING.md §3.1). */
|
||||
gi.n_blocks = p->pool_blocks();
|
||||
gi.base = p->base;
|
||||
gi.replicated = p->replicated;
|
||||
if (p->zero) {
|
||||
@@ -109,6 +116,12 @@ int TierExec::slot_layout(const std::vector<const KVManager*>& ranks,
|
||||
for (int32_t g : groups) {
|
||||
const KVGroupPlan* p0 = ranks[0]->plan(g);
|
||||
if (!p0 || !p0->paged()) continue;
|
||||
/* A streamed group is not part of a tier entry: its pool is one layer deep, so a gather
|
||||
* of layer L would copy the last staged layer n_layers times, and its host mirror is the
|
||||
* tier (docs/KV-STREAMING.md §4.1). TierExec::stage skips the same groups, so this
|
||||
* arithmetic and its gather offsets agree. A streamed group is never replicated, so
|
||||
* leaving it out of the replicated window too is the safe rule. */
|
||||
if (!kv_tier_cached(*p0)) continue;
|
||||
bool replicated = false;
|
||||
for (size_t i = 0; i < ranks.size(); ++i) {
|
||||
const KVGroupPlan* p = ranks[i]->plan(g);
|
||||
|
||||
@@ -202,7 +202,7 @@ void Ctx::xp_serve(XpState& x) {
|
||||
if (r.mark) rad_ride_release(r.mark, r.ms, kXpMarkHold);
|
||||
continue;
|
||||
}
|
||||
if (rad_xp_list(x.device, r.mark, n, src, dst, bytes, x.done + r.g, r.seq) == RAD_OK) {
|
||||
if (rad_xp_list(x.device, r.mark, n, src, dst, bytes, x.done + r.g, r.seq, 0) == RAD_OK) {
|
||||
++x.lists;
|
||||
if (r.mark) x.marks.emplace_back(r.mark, x.lists);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user