Archived
merge 1.12.0: gemma4 E2B/E4B and Nemotron Bolt E4B arrive; the ref2va audio, rows and ABI work carried across
conv1d keeps both stride forms: upstream's causal codec downsample with cu_div (Fish Audio) and the port's explicit-pad non-causal one (the H3 audio encoder's), in libref, libavx and libr4d alike; the ABI takes upstream's 27 on top of the port's RadVideoGenBatch growth.
This commit is contained in:
commit
7c3b5ab7d5
285 files changed
+30500
-2898
No files matched your search
+12
-5
@@ -5,15 +5,18 @@
|
||||
|
||||
namespace rad {
|
||||
|
||||
int Arena::init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions) {
|
||||
int Arena::init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions,
|
||||
int64_t scratch_bytes1) {
|
||||
release();
|
||||
if (plan_bytes < 0 || scratch_bytes < 0 || regions < 1) return RAD_E_INVAL;
|
||||
if (scratch_bytes1 < 0 || scratch_bytes1 > scratch_bytes) scratch_bytes1 = scratch_bytes;
|
||||
|
||||
/* Scratch starts on a page boundary, so a workspace gets 4 KiB alignment for at most one
|
||||
* page of padding. */
|
||||
const int64_t off = align_up(plan_bytes, RAD_ALIGN_UNIT);
|
||||
const int64_t pitch = align_up(scratch_bytes, RAD_ALIGN_UNIT);
|
||||
const int64_t tail = pitch * regions;
|
||||
const int64_t pitch = align_up(scratch_bytes, RAD_ALIGN_UNIT);
|
||||
const int64_t pitch1 = align_up(scratch_bytes1, RAD_ALIGN_UNIT);
|
||||
const int64_t tail = pitch + pitch1 * (regions - 1);
|
||||
int64_t total = off + tail;
|
||||
|
||||
/* Never zero bytes: a null base would turn a plan bug into an anonymous segfault. */
|
||||
@@ -33,6 +36,8 @@ int Arena::init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions
|
||||
scratch_off_ = off;
|
||||
scratch_bytes_ = scratch_bytes;
|
||||
scratch_pitch_ = pitch;
|
||||
scratch_bytes1_ = regions > 1 ? scratch_bytes1 : 0;
|
||||
scratch_pitch1_ = regions > 1 ? pitch1 : 0;
|
||||
scratch_regions_ = regions;
|
||||
return RAD_OK;
|
||||
}
|
||||
@@ -87,8 +92,10 @@ int64_t arena_plan_bytes(const Program& P, int64_t* dev_out, int64_t* total_out)
|
||||
/* The staging region sits above every buffer, so it is a separate term. */
|
||||
if (P.arena_stage_bytes > 0 && P.arena_stage_off >= 0)
|
||||
dev_bytes = std::max(dev_bytes, P.arena_stage_off + P.arena_stage_bytes);
|
||||
int64_t total = align_up(dev_bytes, RAD_ALIGN_UNIT) +
|
||||
align_up(P.scratch_bytes, RAD_ALIGN_UNIT) * std::max<int64_t>(P.scratch_regions, 1);
|
||||
const int64_t s1 = P.scratch_bytes_lane1 < 0 || P.scratch_bytes_lane1 > P.scratch_bytes
|
||||
? P.scratch_bytes : P.scratch_bytes_lane1;
|
||||
int64_t total = align_up(dev_bytes, RAD_ALIGN_UNIT) + align_up(P.scratch_bytes, RAD_ALIGN_UNIT) +
|
||||
align_up(s1, RAD_ALIGN_UNIT) * (std::max<int64_t>(P.scratch_regions, 1) - 1);
|
||||
if (total == 0) total = RAD_ALIGN_UNIT; /* Arena::init's floor, for the same reason */
|
||||
if (dev_out) *dev_out = dev_bytes;
|
||||
if (total_out) *total_out = total;
|
||||
|
||||
+13
-4
@@ -25,18 +25,25 @@ public:
|
||||
Arena& operator=(const Arena&) = delete;
|
||||
|
||||
/* `kind` is a RAD_MEM_* class: RAD_MEM_DEVICE for the device arena, RAD_MEM_HOST for the
|
||||
* second arena a program with RAD_DOMAIN_HOST buffers gets. `regions` scratch regions of
|
||||
* `scratch_bytes` each sit at the tail, one per lane. */
|
||||
int init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions = 1);
|
||||
* second arena a program with RAD_DOMAIN_HOST buffers gets. `regions` scratch regions sit at the
|
||||
* tail, one per lane: region 0 of `scratch_bytes`, the others of `scratch_bytes1` (-1: the same;
|
||||
* Program::scratch_bytes_lane1). */
|
||||
int init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions = 1,
|
||||
int64_t scratch_bytes1 = -1);
|
||||
void release();
|
||||
|
||||
char* base() const { return base_; }
|
||||
/* Region `r`, or region 0 when the arena holds fewer. */
|
||||
void* scratch(int r = 0) const {
|
||||
if (!base_) return nullptr;
|
||||
return base_ + scratch_off_ + (r > 0 && r < scratch_regions_ ? r * scratch_pitch_ : 0);
|
||||
return base_ + scratch_off_ +
|
||||
(r > 0 && r < scratch_regions_ ? scratch_pitch_ + (r - 1) * scratch_pitch1_ : 0);
|
||||
}
|
||||
/* Region 0's size (the program's largest kernel), or region `r`'s. */
|
||||
int64_t scratch_bytes() const { return scratch_bytes_; }
|
||||
int64_t scratch_bytes(int r) const {
|
||||
return r > 0 && r < scratch_regions_ ? scratch_bytes1_ : scratch_bytes_;
|
||||
}
|
||||
int scratch_regions() const { return scratch_regions_; }
|
||||
int64_t bytes() const { return bytes_; }
|
||||
bool live() const { return base_ != nullptr; }
|
||||
@@ -48,6 +55,8 @@ private:
|
||||
int64_t scratch_off_ = 0;
|
||||
int64_t scratch_bytes_ = 0;
|
||||
int64_t scratch_pitch_ = 0; /* scratch_bytes_ padded to RAD_ALIGN_UNIT */
|
||||
int64_t scratch_bytes1_ = 0; /* each region past 0 */
|
||||
int64_t scratch_pitch1_ = 0;
|
||||
int scratch_regions_ = 1;
|
||||
};
|
||||
|
||||
|
||||
+17
-5
@@ -153,13 +153,20 @@ int Ctx::bind_arena() {
|
||||
int64_t dev_bytes = 0, total = 0;
|
||||
arena_plan_bytes(P, &dev_bytes, &total);
|
||||
|
||||
RAD_TRY(arena_.init(dev_bytes, P.scratch_bytes, RAD_MEM_DEVICE, std::max(P.scratch_regions, 1)));
|
||||
RAD_TRY(arena_.init(dev_bytes, P.scratch_bytes, RAD_MEM_DEVICE, std::max(P.scratch_regions, 1),
|
||||
P.scratch_bytes_lane1));
|
||||
/* The arena is in no pool and scales with max_tok, so core/mem/vram_budget.cpp charges it by
|
||||
* name rather than leaving it to --gpu-headroom-mib. This log line must agree with that
|
||||
* charge. */
|
||||
RAD_INFO("arena: %s device + %d x %s scratch = %s, charged to the VRAM budget before it was "
|
||||
"split", humanb(dev_bytes).c_str(), arena_.scratch_regions(),
|
||||
humanb(P.scratch_bytes).c_str(), humanb(total).c_str());
|
||||
if (arena_.scratch_regions() > 1)
|
||||
RAD_INFO("arena: %s device + %s scratch + %s for the second lane = %s, charged to the VRAM "
|
||||
"budget before it was split", humanb(dev_bytes).c_str(),
|
||||
humanb(P.scratch_bytes).c_str(), humanb(arena_.scratch_bytes(1)).c_str(),
|
||||
humanb(total).c_str());
|
||||
else
|
||||
RAD_INFO("arena: %s device + %s scratch = %s, charged to the VRAM budget before it was "
|
||||
"split", humanb(dev_bytes).c_str(), humanb(P.scratch_bytes).c_str(),
|
||||
humanb(total).c_str());
|
||||
|
||||
if (host_hw > 0) {
|
||||
/* RAD_MEM_HOST_MAPPED, not RAD_MEM_HOST: nothing copies between the two arenas, so device
|
||||
@@ -333,6 +340,8 @@ int Ctx::bind_ops() {
|
||||
p.billed = (oi.op == "all_reduce");
|
||||
p.collective = p.billed;
|
||||
p.lora_site = oi.lora_site;
|
||||
p.order = oi.anchor > 0 && (size_t)oi.anchor < P.ops.size() ? P.ops[(size_t)oi.anchor].index
|
||||
: oi.index;
|
||||
|
||||
for (const Band& b : oi.bands) band_table_.push_back(b.hi);
|
||||
|
||||
@@ -908,6 +917,7 @@ int Ctx::lane_join(int from, int to) {
|
||||
RAD_TRY(rad_event_record(lane_ev_[from], fs));
|
||||
RAD_TRY(rad_event_wait(ts, lane_ev_[from]));
|
||||
scratch_open_[from] = false; /* `to` is now behind every scratch user `from` issued */
|
||||
if (from == 1 && to == 0) lane1_pending_ = false;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
@@ -918,7 +928,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` and `vgen_b` are set only on generator passes, which are never recorded
|
||||
* (below). */
|
||||
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 336,
|
||||
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,
|
||||
"RadKVGroupBatch changed: check that Ctx::pass_key reads every new field");
|
||||
@@ -949,6 +959,8 @@ uint64_t Ctx::pass_key(const RadBatch* b) const {
|
||||
/* Null on a step with no adapter row, which then issues no adapter op (Ctx::issue_lora): the
|
||||
* two are different passes. The slots themselves are read on the card. */
|
||||
ptr(b->lora_slot);
|
||||
/* Zero issues no projection op (RadBatch::control_vector). */
|
||||
mix((uint64_t)b->control_vector);
|
||||
for (int g = 0; g < b->n_kv_groups; ++g) {
|
||||
const RadKVGroupBatch& k = b->kv[g];
|
||||
mix((uint64_t)k.group); ptr(k.slot_mapping); ptr(k.block_table);
|
||||
|
||||
+13
-2
@@ -94,6 +94,9 @@ struct OpPlan {
|
||||
bool billed = false;
|
||||
/* Runtime LoRA: this gemm's row in Program::lora_sites, -1 for every op that is not one. */
|
||||
int32_t lora_site = -1;
|
||||
/* Its position in the declared order, or its anchor's for a core-appended op: what the second
|
||||
* lane's window (Program::lane1_w0..lane1_w1) is checked against. */
|
||||
int32_t order = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ routing handoff */
|
||||
@@ -294,6 +297,8 @@ public:
|
||||
void dump_profile() const; /* spec §16, opt-in, with its caveat printed */
|
||||
const char* step_error() const { return step_fail_.c_str(); }
|
||||
int64_t stream_waits() const { return n_stream_waits_; }
|
||||
/* Lane 1 has work lane 0 has not joined (lane1_pending_). */
|
||||
bool lane1_pending() const { return lane1_pending_; }
|
||||
/* Host synchronisations on the step path. Always zero unless per-op timing is on (spec §16);
|
||||
* tests read it. Teardown's drain is not counted. */
|
||||
int64_t host_syncs() const { return n_host_syncs_; }
|
||||
@@ -552,6 +557,9 @@ public:
|
||||
/* Backs rad_step_fail(): stops the step like an operand rejection, with the caller's
|
||||
* message. */
|
||||
int step_fail(const char* what);
|
||||
/* The device kernel `h` resolved to on this rank ("?" if it resolved none). For log
|
||||
* attribution only. */
|
||||
const char* ip_kernel_name(rad_op h) const;
|
||||
private:
|
||||
[[noreturn]] void fatal_issue(rad_op h, int64_t n, const char* why) const;
|
||||
|
||||
@@ -578,7 +586,6 @@ private:
|
||||
* byte-compares the two results, finding kernels that are not a function of their inputs,
|
||||
* which a host-vs-device comparison cannot detect. */
|
||||
void oracle_repeat(rad_op h, const IssuePlan& dip, int64_t seq, int n_opd);
|
||||
const char* ip_kernel_name(rad_op h) const;
|
||||
/* The reference library's host plan for (op, band): the band's own host plan when a reference
|
||||
* library won it, else one resolved from `registry_` on first use. Null when none exists. */
|
||||
const IssuePlan* oracle_reference(rad_op h, int band);
|
||||
@@ -625,7 +632,8 @@ private:
|
||||
* 3. The buffer planner packs from one linear order, so two lanes can alias arena bytes
|
||||
* through buffers with disjoint declared lifetimes. The architecture passes every buffer
|
||||
* its second lane touches to `rad_buf_concurrent`, which makes it live for the whole
|
||||
* program.
|
||||
* program, or, where the architecture declares the second lane's window
|
||||
* (rad_lane1_window_begin / _end), across the window and its own declared uses.
|
||||
*
|
||||
* 4. A slice must land in the same bucket-table band as the whole, or it picks a kernel with
|
||||
* a different summation order and silently changes output. `--debug-graph` prints a model's
|
||||
@@ -647,6 +655,9 @@ private:
|
||||
bool own_lane1_ = false;
|
||||
int lane_ = 0;
|
||||
RadEvent lane_ev_[2] = { nullptr, nullptr };
|
||||
/* An op was issued on lane 1 since lane 1 was last joined into lane 0; lane 0 joins it before
|
||||
* an op outside the second lane's window (Ctx::issue_body). */
|
||||
bool lane1_pending_ = false;
|
||||
/* The last device op on each lane that touched host-domain memory. A host op runs at issue on
|
||||
* this thread and must be ordered behind every earlier device op that touched the host arena;
|
||||
* on each lane those complete no later than the last one. So a device op with a host-domain
|
||||
|
||||
+32
-2
@@ -592,6 +592,25 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
|
||||
? "has no host kernel for this band, and the placement planner put "
|
||||
"it on the host anyway"
|
||||
: "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) {
|
||||
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,
|
||||
fmt("issued on the second lane outside its declared window (ops "
|
||||
"%d..%d, this one %d): the buffers it may touch there are "
|
||||
"live only across the window",
|
||||
(int)program_->lane1_w0, (int)program_->lane1_w1, (int)p.order));
|
||||
if (lane_ == 0 && lane1_pending_ && outside) {
|
||||
const int js = lane_join(1, 0);
|
||||
if (js < 0)
|
||||
return abort_step_msg(h, js, "joining the second lane outside its window failed");
|
||||
}
|
||||
}
|
||||
if (lane_ == 1) 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)
|
||||
return abort_step_msg(h, RAD_E_SHAPE,
|
||||
@@ -884,7 +903,18 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
|
||||
* correctness. That also covers lane 0 before lane 1 exists, since a lane built later has
|
||||
* nothing ordering it behind lane 0's earlier work. */
|
||||
if (ip.args.scratch_bytes > 0 && dom != RAD_DOMAIN_HOST && arena_.scratch_regions() > 1) {
|
||||
/* Per-lane regions: nothing to order. */
|
||||
/* Per-lane regions: nothing to order. Region 1 holds what an op the second lane may issue
|
||||
* asked for at declare (Program::scratch_bytes_lane1); a larger request there comes from an
|
||||
* op with a transient buffer outside rad_buf_concurrent, which breaks Ctx::lane1_'s rule 3
|
||||
* in its buffers too, so it is refused by name rather than let overrun the region. */
|
||||
if (ip.args.scratch_bytes > arena_.scratch_bytes(lane_)) {
|
||||
return abort_step_msg(h, RAD_E_SCRATCH,
|
||||
fmt("kernel %s at n=%lld asks for %lld bytes of scratch on lane %d, whose region "
|
||||
"holds %lld: an op on the second lane may touch only buffers named to "
|
||||
"rad_buf_concurrent (Ctx::lane1_ rule 3)",
|
||||
ip.row && ip.row->info ? ip.row->info->name : "?", (long long)n,
|
||||
(long long)ip.args.scratch_bytes, lane_, (long long)arena_.scratch_bytes(lane_)));
|
||||
}
|
||||
ip.args.scratch = scratch_take(lane_, ip.args.scratch_bytes);
|
||||
} else if (ip.args.scratch_bytes > 0 && dom != RAD_DOMAIN_HOST) {
|
||||
ip.args.scratch = scratch_take(0, ip.args.scratch_bytes);
|
||||
@@ -1058,7 +1088,7 @@ void* Ctx::scratch_take(int region, int64_t bytes) {
|
||||
constexpr int64_t kAlign = 256;
|
||||
const int64_t need = (bytes + kAlign - 1) / kAlign * kAlign;
|
||||
int64_t off = scratch_cur_[region];
|
||||
if (off + need > arena_.scratch_bytes()) off = 0;
|
||||
if (off + need > arena_.scratch_bytes(region)) off = 0;
|
||||
scratch_cur_[region] = off + need;
|
||||
return (char*)arena_.scratch(region) + off;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ void bind_kv_pools(const Program& p, const std::function<const KVGroupPlan*(int3
|
||||
switch (gp->kind) {
|
||||
case RAD_KV_FULL:
|
||||
case RAD_KV_WINDOW:
|
||||
case RAD_KV_RING:
|
||||
b.rank = 4;
|
||||
b.shape[0] = gp->n_blocks;
|
||||
b.shape[1] = d.n_head_kv;
|
||||
|
||||
@@ -226,8 +226,18 @@ int TierExec::device_init() {
|
||||
bool ev = rad_event_create(&ev_compute_) == RAD_OK && rad_event_create(&ev_copy_) == RAD_OK &&
|
||||
rad_event_create(&ev_restore_) == RAD_OK;
|
||||
for (int i = 0; i < kRing && ev; ++i) ev = rad_event_create(&ring_ev_[i]) == RAD_OK;
|
||||
if (verify_rep_) vrep_ = (char*)rad_dev_alloc(copy_idx_ * rep_bytes_, RAD_MEM_HOST_PINNED);
|
||||
if (!stage_ || !idx_dev_ || !idx_host_ || !ev || (verify_rep_ && !vrep_)) {
|
||||
/* The verify scratch is a diagnostic's: without it the replicated groups go unchecked, and
|
||||
* the tiers run as they would without RADIANCE_DEBUG_TIER_VERIFY. */
|
||||
if (verify_rep_) {
|
||||
vrep_ = (char*)rad_dev_alloc(copy_idx_ * rep_bytes_, RAD_MEM_HOST_PINNED);
|
||||
if (!vrep_) {
|
||||
RAD_WARN("kv tiers: RADIANCE_DEBUG_TIER_VERIFY: no pinned host memory (%s) for this "
|
||||
"rank's copy of the replicated groups, so they are not compared",
|
||||
humanb(copy_idx_ * rep_bytes_).c_str());
|
||||
verify_rep_ = false;
|
||||
}
|
||||
}
|
||||
if (!stage_ || !idx_dev_ || !idx_host_ || !ev) {
|
||||
release_device();
|
||||
return RAD_E_NOMEM;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user