From 72624973ad039916fce53487898e07047d26a29b Mon Sep 17 00:00:00 2001 From: gearwave00001 Date: Mon, 19 Oct 2026 12:25:53 -0500 Subject: [PATCH] ref2va: merged-cell modulation lifts the reference-photo ceiling from five to nine A modulation cell is a pure function of a segment's kind -- (modality ada, timestep block) -- so all reference photos share one cell. Runs of consecutive same-cell segments collapse to a group; group boundaries are a subset of the fine segment boundaries and the merge is sequence-length independent (the key is kind alone). The modulated norm now reads COARSER group boundaries via a new trailing RadVideoGenBatch::mod_cu while attention keeps the fine seg_cu, and the fixed-width table is pitched by GROUP count. Nine photos therefore occupy four groups (prompt / all-photos / soundtrack / video); buffer sizes and the arena are unchanged (kMaxSegs stays 8, no kernel change, no re-convert). No regression for <=5 photos: each photo cell already filled its own column from the same input rows and weights, so it was bit-identical to the others; merging issues it once instead of N times and yields the same per-row value. Only the previously-rejected sixth through ninth photos change, by being allowed. Driver: rad_arch_video_mod_segs (trailing plugin export) computes the merged groups host-side; the driver stages them into R_MOD, guards the GROUP count against max_ref_segs at submit (a clean refusal beats a step-loop fault), and the plain path stages the fine table into both operands. Device-verified on dual gfx1201 / TP2 with a CONTROLLED same-seed battery (task=ref2va, seed fixed on every job, so neither the seed nor the token count is a confounder): same prompt, same seed, same ref-count, DIFFERENT image content give DIFFERENT outputs -- the reference is genuinely consumed. Nine photos complete (the case the pinned build refused at submit), whole-run fault scan clean. Adds docs/NOTE-REF2VA.md: what this port reproduces of the DaSiWa workflow and what it does not -- the residual 8-group ceiling under heavy interleaved mixed refs, the reference-token / row budget, continuity tail (unimplemented), the video/audio reference paths (plumbed, not yet device-verified), references x latent-upscale exclusion, and open conditioned-step parity. Co-Authored-By: Claude --- abi/rad_builder.h | 17 ++-- abi/rad_runtime.h | 12 +++ arch/minimaxh3/minimaxh3.cpp | 105 +++++++++++++++-------- arch/minimaxh3/rad_ref2va_pack.cpp | 38 +++++++++ arch/minimaxh3/rad_ref2va_pack.h | 21 +++++ core/build/startup.cpp | 5 ++ core/build/startup.h | 6 ++ core/engine.cpp | 2 +- core/gen/video_driver.cpp | 53 +++++++++--- core/gen/video_driver.h | 22 ++++- core/plugin/loader.cpp | 6 ++ core/plugin/registry.h | 6 ++ docs/NOTE-REF2VA.md | 130 +++++++++++++++++++++++++++++ tests/ref2va_pack_test.cpp | 85 +++++++++++++++++++ tests/video_gen_test.cpp | 5 +- 15 files changed, 454 insertions(+), 59 deletions(-) create mode 100644 docs/NOTE-REF2VA.md diff --git a/abi/rad_builder.h b/abi/rad_builder.h index 0028695d..45f59c87 100644 --- a/abi/rad_builder.h +++ b/abi/rad_builder.h @@ -958,12 +958,17 @@ typedef struct RadVideoGenDecl { * denoiser reads `ref_tab`, so this flag is what makes staging and consumption flip together. */ int32_t ref_rows; - /* The largest segment count this generator's modulation table holds: its denoiser lays out one - * modulation cell per pack segment, and the table is sized `kMaxSegs` columns. A conditioned - * pack whose segments exceed this cannot be built -- the step would abort the engine. The driver - * refuses such a request at submit (it lays the pack out itself, so it knows the count before - * dispatch) rather than letting the arch fail mid-generation. 0 = no reference consumption, so - * no such limit. Trailing since ABI 23: an older plugin declares none and keeps the 0 default. */ + /* The largest MODULATION-GROUP count this generator's modulation table holds -- its denoiser's + * `kMaxSegs`. A modulation cell is a pure function of a segment's KIND (its modality and its + * timestep-embedding block), so runs of consecutive segments that share a cell collapse into one + * group and the table is sized by the GROUP count, not the reference count: nine reference photos + * pack into four groups (prompt, all-photos, soundtrack, video). The attention still takes the + * FINE per-segment table (which may hold far more segments than this), so this is not a limit on + * how many references ride -- only on how many DISTINCT cells the sequence changes through. The + * driver refuses a request whose merged group count exceeds it at submit (it lays the pack out and + * merges it itself, via `rad_arch_video_mod_segs`, so it knows before dispatch) rather than letting + * the arch abort mid-generation. 0 = no reference consumption, so no such limit. Trailing since + * ABI 23: an older plugin declares none and keeps the 0 default. */ int32_t max_ref_segs; } RadVideoGenDecl; diff --git a/abi/rad_runtime.h b/abi/rad_runtime.h index 101ca765..096da749 100644 --- a/abi/rad_runtime.h +++ b/abi/rad_runtime.h @@ -506,6 +506,18 @@ typedef struct RadVideoGenBatch { * latent frames and its audio latents, 0 where the kind carries neither. A batch without * the field laid out is one an older engine built: no references. Trailing since ABI 23. */ const int32_t* ref_tab; + + /* ---- The modulated-norm's segment boundaries, device i32. The denoiser's attention reads the + * FINE `seg_cu` -- one segment per reference block, which the block-sparse attention needs to + * give each reference its own prefix sink -- but the modulated norm reads a COARSER table: + * consecutive segments that share a modulation cell (the same modality and the same + * timestep-embedding block) merge into one, because a cell is a pure function of a segment's + * kind. This is that merged table's boundaries, a subset of `seg_cu`'s -- every fine boundary + * that is also a cell change. Sizing the modulation table by the GROUP count, not the reference + * count, is what lets a wide reference request (up to nine photos, which pack into four groups) + * ride a fixed table. On a plain request (or one that merges nothing) it is exactly `seg_cu`; a + * driver stages the same bytes into both. Trailing since ABI 23. */ + const int32_t* mod_cu; } RadVideoGenBatch; /* RadVideoGenBatch::enc_kind: which reference media an encode pass carries. A plugin's latent diff --git a/arch/minimaxh3/minimaxh3.cpp b/arch/minimaxh3/minimaxh3.cpp index ef96ca50..c40f9707 100644 --- a/arch/minimaxh3/minimaxh3.cpp +++ b/arch/minimaxh3/minimaxh3.cpp @@ -2877,9 +2877,12 @@ static int declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* c * consumption all move together behind this one constant; a request with no reference * table stays on the byte-identical plain path (step_dit's refc gate is `V->ref_tab`). */ d.ref_rows = kRefConsume; - /* The denoiser's modulation table is one cell per pack segment, `kMaxSegs` columns; a - * pack that lays out more aborts the step. The driver builds the pack itself, so it - * reads this cap and refuses an over-wide request at submit -- the model's ceilings + /* The denoiser's modulation table is one cell per modulation GROUP, `kMaxSegs` columns. + * A cell is a pure function of a segment's kind, so a run of consecutive same-cell + * segments -- nine reference photos, say -- shares one cell and the table is pitched by + * the group count, not the reference count; a pack that MERGES to more groups than this + * aborts the step. The driver builds and merges the pack itself (rad_arch_video_mod_segs) + * and reads this cap, refusing an over-wide request at submit -- the model's ceilings * (max_ref_images & co.) stay the model's, this is the build's table. */ d.max_ref_segs = kRefConsume ? kMaxSegs : 0; } @@ -2922,23 +2925,14 @@ static minimaxh3::Ref2VAPack ref_pack_of(const RadVideoGeom* g, const int32_t* r return p; } -/* A segment's modulation cell: the modality's ada projection (0 video, 1 text, 2 audio) and the - * timestep-embedding block it reads, over the four blocks [0,S) video, [S,2S) audio, [2S,3S) - * video-pinned, [3S,4S) audio-pinned. The two target streams read their own schedule; every - * reference block reads its modality's clamped block, whose row s is embed(max(t_s, pin)) -- bit- - * identical to the reference's pinned embedding at every step, so one M=S projection fills the - * cell for all S steps, with no per-step schedule-vs-pin choice to make. */ -static void ref_cell_of(int kind, int64_t S, int* md, int64_t* r0) { - switch (kind) { - case minimaxh3::kR2VAudio: *md = 2; *r0 = S; break; /* audio schedule */ - case minimaxh3::kR2VCondAudio: - case minimaxh3::kR2VRefAudio: *md = 2; *r0 = 2 * S; break; /* audio-pinned block */ - case minimaxh3::kR2VText: *md = 1; *r0 = 0; break; /* video schedule */ - case minimaxh3::kR2VCond: - case minimaxh3::kR2VRefImg: *md = 0; *r0 = 2 * S; break; /* video-pinned block */ - default: *md = 0; *r0 = 0; break; /* video target */ - } -} +/* A segment's modulation cell -- its modality's ada projection (0 video, 1 text, 2 audio) and the + * timestep-embedding block it reads over [0,S) video, [S,2S) audio, [2S,3S) video-pinned, + * [3S,4S) audio-pinned -- is a pure function of the segment's kind. That rule lives in one place, + * `cell_of_kind` inside ref2va_mod_groups (rad_ref2va_pack.cpp), which merges consecutive same-cell + * segments and hands step_cond the group cells directly; step_cond therefore needs no cell map of + * its own. The pinned blocks sit at [2S,3S)/[3S,4S) so one M=S projection fills a reference cell + * for all S steps (its row is embed(max(t, pin)), bit-identical to the reference's pinned + * embedding), with no per-step schedule-vs-pin choice to make. */ /* Which encoder slot each reference part's latents sit in, in the order ref2va_build lays the * reference segments down -- a standalone soundtrack alone; a clip its soundtrack (when it carries @@ -3068,12 +3062,15 @@ static void step_cond(RadCtx* c, const RadBatch* batch, const Model& m) { const bool refc = kRefConsume && V->ref_tab; std::vector> cell; if (refc) { + /* One cell per modulation GROUP, not per fine segment. A cell is fixed by a segment's kind + * (its modality's ada projection and its timestep-embedding block), so consecutive + * same-cell segments -- every reference photo, say, all video-pinned -- collapse into one. + * The table is written at the group's column and the norm is handed the group boundaries + * (V->mod_cu), so a wide reference request rides a table pitched by its GROUP count. */ const minimaxh3::Ref2VAPack p = ref_pack_of(&V->geom, V->ref_tab); - for (const minimaxh3::Ref2VASeg& s : p.segs) { - int md; int64_t r0; - ref_cell_of(s.kind, S, &md, &r0); - cell.emplace_back(md, r0); - } + minimaxh3::Ref2VAModGroups grp; + minimaxh3::ref2va_mod_groups(p, S, &grp); + for (size_t i = 0; i < grp.md.size(); ++i) cell.emplace_back(grp.md[i], grp.r0[i]); } else { for (int e = 0; e < kSegs; ++e) cell.emplace_back(kSegMod[e], e == kSegAudio ? S : 0); @@ -3118,14 +3115,21 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) { * segments and lands every offset exactly as before. */ const bool refc = kRefConsume && V->ref_tab; minimaxh3::Ref2VAPack pk; + int64_t ng = kSegs; /* modulation groups: the norm table's width */ int64_t vrows, aseg, vseg; if (refc) { pk = ref_pack_of(&V->geom, V->ref_tab); - if ((int64_t)pk.segs.size() > kMaxSegs || pk.segs.size() < 2 || + /* The table is pitched by the merged GROUP count (a cell is fixed by a segment's kind, so + * consecutive same-cell segments collapse), while the attention keeps the fine per-segment + * layout. Checked against the table width is the merged count, not the reference count. */ + minimaxh3::Ref2VAModGroups grp; + minimaxh3::ref2va_mod_groups(pk, m.S, &grp); + ng = (int64_t)grp.md.size(); + if (ng > kMaxSegs || pk.segs.size() < 2 || pk.segs.back().kind != minimaxh3::kR2VVideo || pk.segs[pk.segs.size() - 2].kind != minimaxh3::kR2VAudio) { - rad_step_fail(c, "minimaxh3: the reference conditioning did not lay out a video/audio " - "target pair within the table"); + rad_step_fail(c, "minimaxh3: the reference conditioning did not merge to a video/audio " + "target pair within the modulation table"); return; } const minimaxh3::Ref2VASeg& vid = pk.segs.back(); @@ -3137,7 +3141,7 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) { aseg = nt; vseg = nt + arows; } - const int64_t ncell = refc ? (int64_t)pk.segs.size() : (int64_t)kSegs; + const int64_t nfine = refc ? (int64_t)pk.segs.size() : (int64_t)kSegs; if (V->step == 0) { RAD_ISSUE_N(c, m.op_rnd_v, vrows, praw(V->first_d, RAD_I32, 1), praw(V->seed, RAD_U32, 2), @@ -3201,7 +3205,11 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) { } } - const RadOperand segs = praw(V->seg_cu, RAD_I32, ncell + 1); + const RadOperand segs = praw(V->seg_cu, RAD_I32, nfine + 1); + /* The modulated norm's boundaries: the merged GROUP table, a subset of `segs` -- attention + * selects its per-reference prefix sinks from the fine `segs`, the norm selects its per-cell + * modulation from `mod_segs`. On the plain path the driver stages identical bytes to both. */ + const RadOperand mod_segs = praw(V->mod_cu, RAD_I32, ng + 1); const RadOperand geom = praw(V->geom_d, RAD_I32, RAD_VGEOM_N); const RadOperand cu = praw(batch->cu_seqlens, RAD_I32, 2); const RadOperand pos = praw2(V->pos, RAD_F32, 3, R); @@ -3210,7 +3218,7 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) { auto mod = [&](int64_t l, int k, int chunks) { const int64_t r = k / per; return bcol_at(m.b_modg, r * L * kMaxSegs + l * kMaxSegs, m.Ws, (k % per) * D, chunks * D, - ncell); + ng); }; /* Two halves of the rows with more than one rank. Everything between two attentions is * row-local, so a half computes exactly the bits the whole would, and each half's all-reduces @@ -3224,11 +3232,11 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) { const int64_t cut = split ? vseg + vrows / 2 : R; const int64_t hr0[2] = { 0, cut }, hn[2] = { cut, R - cut }; const int nh = split ? 2 : 1; - const RadOperand segh[2] = { segs, cu }; + const RadOperand segh[2] = { mod_segs, cu }; auto modh = [&](int h, int64_t l, int k, int chunks) { if (h == 0) return mod(l, k, chunks); const int64_t r = k / per; - return bcol_at(m.b_modg, r * L * kMaxSegs + l * kMaxSegs + (ncell - 1), m.Ws, (k % per) * D, + return bcol_at(m.b_modg, r * L * kMaxSegs + l * kMaxSegs + (ng - 1), m.Ws, (k % per) * D, chunks * D, 1); }; /* A half's partial sums across the ranks, kArRows rows a message, on lane 1 when split. */ @@ -3298,9 +3306,9 @@ static void step_dit(RadCtx* c, const RadBatch* batch, const Model& m) { } wait_ar(); const char* nout = (const char*)rad_buf_ptr(c, m.b_nout) + - (lane * m.S + V->step) * ncell * 2 * D * (int64_t)sizeof(uint16_t); + (lane * m.S + V->step) * ng * 2 * D * (int64_t)sizeof(uint16_t); RAD_ISSUE_N(c, m.op_nout, R, brows(m.b_ao, R), mod(L - 1, 5, 1), - RAD_P_T2(nout, RAD_BF16, ncell, 2 * D), RAD_W(m.w_no_n), segs, brows(m.b_h, R), + RAD_P_T2(nout, RAD_BF16, ng, 2 * D), RAD_W(m.w_no_n), mod_segs, brows(m.b_h, R), brows(m.b_hn, R)); /* The heads, in f32 over parts of the rows. */ @@ -3870,4 +3878,31 @@ extern "C" int64_t rad_arch_video_pack(const RadVideoGeom* g, const int32_t* ref if (pos) std::copy(p.pos.begin(), p.pos.end(), pos); return p.rows; } + +/* The merged modulation-group boundaries: a SUBSET of rad_arch_video_pack's segment boundaries, + * with the boundaries that fall inside a run of consecutive same-cell segments dropped. The + * denoiser's attention reads the fine pack boundaries (each reference needs its own prefix sink), + * but the modulated norm reads these coarser ones -- a modulation cell is fixed by a segment's kind, + * so a run of reference photos shares one cell and one table column, letting nine photos ride the + * fixed `kMaxSegs`-wide table that the twelve fine segments would overrun. The merge is independent + * of the sampler's step count (whether two neighbours share a cell depends only on their kinds), so + * S is passed as 1 here purely to keep the timestep-embedding blocks distinct; the boundaries it + * yields are the ones step_cond/step_dit derive at the real S. A plain geometry collapses to the + * fine table: it is the same pack, and the driver then stages identical bytes to both operands. Call + * with mod = nullptr for the number of int32s needed. */ +extern "C" int64_t rad_arch_video_mod_segs(const RadVideoGeom* g, const int32_t* ref_tab, + int32_t* mod, int64_t cap) { + if (!g || g->n_text < 1 || g->n_text > minimaxh3::kMaxText) return RAD_E_INVAL; + if (g->lat_frames < 1 || g->lat_h < minimaxh3::kPatch || g->lat_w < minimaxh3::kPatch || + g->n_audio < 1) + return RAD_E_INVAL; + const minimaxh3::Ref2VAPack p = minimaxh3::ref_pack_of(g, ref_tab); + minimaxh3::Ref2VAModGroups grp; + minimaxh3::ref2va_mod_groups(p, 1, &grp); + const int64_t n = (int64_t)grp.bound.size(); + if (!mod) return n; + if (cap < n) return RAD_E_INVAL; + for (size_t k = 0; k < grp.bound.size(); ++k) mod[k] = (int32_t)grp.bound[k]; + return n; +} #endif diff --git a/arch/minimaxh3/rad_ref2va_pack.cpp b/arch/minimaxh3/rad_ref2va_pack.cpp index 32e7ac8a..d1bbcf68 100644 --- a/arch/minimaxh3/rad_ref2va_pack.cpp +++ b/arch/minimaxh3/rad_ref2va_pack.cpp @@ -271,6 +271,44 @@ int ref2va_mod_rows(const Ref2VAPack& p, double t_v, double t_a, std::vectorbound.clear(); out->md.clear(); out->r0.clear(); + /* Walk the segments in sequence order, opening a new group whenever the cell changes or a gap + * would otherwise appear. Empty segments carry no rows: they neither extend nor split a group, + * so a run of photos with an empty cond between them still rides one cell. */ + int cur_md = 0; int64_t cur_r0 = 0; bool open = false; + int64_t prev_end = 0; + for (const Ref2VASeg& s : p.segs) { + if (s.end <= s.start) continue; + int md; int64_t r0; + cell_of_kind(s.kind, S, &md, &r0); + if (!open || md != cur_md || r0 != cur_r0 || s.start != prev_end) { + if (open) out->bound.push_back(s.start); /* close the previous group at this start */ + else out->bound.push_back(0); + cur_md = md; cur_r0 = r0; open = true; + out->md.push_back(md); out->r0.push_back(r0); + } + prev_end = s.end; + } + if (open) out->bound.push_back(p.rows); /* the last group runs to the end of the sequence */ +} + void ref2va_ada_cell(const Ref2VAPack& p, double t_v, double t_a, std::vector* md, std::vector* trow) { md->resize(p.segs.size()); diff --git a/arch/minimaxh3/rad_ref2va_pack.h b/arch/minimaxh3/rad_ref2va_pack.h index d498debb..531affb5 100644 --- a/arch/minimaxh3/rad_ref2va_pack.h +++ b/arch/minimaxh3/rad_ref2va_pack.h @@ -108,6 +108,27 @@ enum Ref2VATRow { kR2VTVideo = 0, kR2VTAudio = 1, kR2VTPinVideo = 2, kR2VTPinAud void ref2va_ada_cell(const Ref2VAPack& p, double t_v, double t_a, std::vector* md, std::vector* trow); +/* ---- merged modulation groups ---- + * The denoiser lays out one modulation cell per fine segment, but a cell is a pure function of a + * segment's KIND (see the arch's ref_cell_of: `md` the modality's ada projection, `r0` the + * timestep-embedding block), so every reference photo reads ONE cell, every reference soundtrack + * another, and so on -- independent of how many there are. The modulated-norm kernel reads a row's + * cell from a segment-boundary operand (its `cu`), used ONLY to select the modulation/gate row: it + * is not otherwise segment-sensitive. So runs of CONSECUTIVE segments that share a cell collapse + * into one group, and the norm is handed the coarser group boundaries while attention keeps the + * fine per-reference segments. The modulation table is then sized by the group count, not the + * reference count -- which is what lets a wide reference request (up to nine photos) ride a fixed + * table. Groups cover the whole sequence: boundaries start at 0 and end at `rows`. Empty segments + * (end <= start) carry no rows and open no boundary. `md`/`r0` are per group, for the table writer. */ +struct Ref2VAModGroups { + std::vector bound; /* [count + 1]: cumulative row boundaries, [0 .. rows] */ + std::vector md; /* [count]: the group's ada projection (0 video, 1 text, 2 audio) */ + std::vector r0; /* [count]: the timestep-embedding block the group's cell reads */ +}; +/* `S` is the sampler's step count (the embedding's per-schedule row span); it fixes the pinned + * blocks at [2S,3S) video / [3S,4S) audio, exactly as the arch's ref_cell_of does. */ +void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, Ref2VAModGroups* out); + /* Lay the sequence out. Returns 0, or -1 on a negative dimension (the driver has already bounded * media against the arch's ceilings; this only refuses nonsense). */ int ref2va_build(int text_len, const Ref2VAGeom& g, const std::vector& keyframes, diff --git a/core/build/startup.cpp b/core/build/startup.cpp index f737a086..416eb0eb 100644 --- a/core/build/startup.cpp +++ b/core/build/startup.cpp @@ -294,6 +294,11 @@ VideoPackFn rad_tools_video_pack(const LoadedPlugins& lp) { return ap ? ap->arch_video_pack : nullptr; } +VideoModSegsFn rad_tools_video_mod_segs(const LoadedPlugins& lp) { + const Plugin* ap = rad_tools_registry().plugin(lp.arch_plugin); + return ap ? ap->arch_video_mod_segs : nullptr; +} + EncodeGeomFn rad_tools_encode_geom(const LoadedPlugins& lp) { const Plugin* ap = rad_tools_registry().plugin(lp.arch_plugin); return ap ? ap->arch_encode_geom : nullptr; diff --git a/core/build/startup.h b/core/build/startup.h index e4ce7930..f9d93f17 100644 --- a/core/build/startup.h +++ b/core/build/startup.h @@ -110,6 +110,12 @@ using VideoPackFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, i int64_t); VideoPackFn rad_tools_video_pack(const LoadedPlugins& plugins); +/* The architecture plugin's merged modulation-group boundaries (rad_arch_video_mod_segs), or null + * when it exports none -- the driver then stages the fine segment table into the norm operand, which + * is correct for any pack that merges nothing (plain or single-reference). */ +using VideoModSegsFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t); +VideoModSegsFn rad_tools_video_mod_segs(const LoadedPlugins& plugins); + /* The architecture plugin's encode-pass geometry (rad_arch_encode_geom), or null when it * exports none -- the driver then runs no encode pass. */ using EncodeGeomFn = int64_t (*)(int32_t, const int64_t*, int32_t*, int64_t); diff --git a/core/engine.cpp b/core/engine.cpp index f23afcb3..984c0ce3 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -1518,7 +1518,7 @@ int Engine::serve(std::unique_ptr watch) { auto d = std::make_unique(); RAD_TRY(d->init(ranks_[0]->program, rad_tools_video_positions(plugins_), gio, rad_tools_video_segs(plugins_), rad_tools_video_pack(plugins_), - rad_tools_encode_geom(plugins_))); + rad_tools_video_mod_segs(plugins_), rad_tools_encode_geom(plugins_))); vid_gen_ = d.get(); gen_ = std::move(d); RAD_TRY(rad_dev_set(ranks_[0]->device)); diff --git a/core/gen/video_driver.cpp b/core/gen/video_driver.cpp index fe0a3269..ca28057d 100644 --- a/core/gen/video_driver.cpp +++ b/core/gen/video_driver.cpp @@ -181,6 +181,7 @@ int64_t carve(const RadVideoGenDecl& d, int64_t max_tok, int64_t ep, int64_t pd, d.max_enc_frames * d.max_enc_side * d.max_enc_side * 3 * 4, /* R_ENCPX: [f,h,w,3] f32 */ d.max_enc_samples * d.audio_channels * 4, /* R_ENCSM: [ch,n] f32 */ 25 * 4, /* R_ENCG: rad_arch_encode_geom's 25 i32 (the video geom) */ + kSegCap * 4, /* R_MOD: the merged modulation-group boundaries (<= R_SEG) */ }; int64_t off = 0; for (int r = 0; r < n; ++r) { @@ -223,7 +224,7 @@ int64_t VideoDriver::device_bytes(const Program& prog) { int VideoDriver::init(const Program& prog, PositionsFn positions, const std::vector& ranks, SegsFn segs, PackFn pack, - EncodeGeomFn enc_geom) { + ModSegsFn mod_segs, EncodeGeomFn enc_geom) { fini(); if (!prog.is_video_generator()) return RAD_E_STATE; decl_ = prog.video_gen; @@ -234,6 +235,7 @@ int VideoDriver::init(const Program& prog, PositionsFn positions, positions_ = positions; segs_ = segs; pack_ = pack; + mod_segs_ = mod_segs; enc_geom_ = enc_geom; max_tok_ = prog.ctx.max_tok; encoder_bounds(prog, &max_enc_, &patch_dim_); @@ -430,18 +432,32 @@ int VideoDriver::submit(std::unique_ptr r, std::string* why) { return no("the reference conditioning layout has no closing segment boundary"); j->seg.resize((size_t)nseg); j->nseg = nseg; - /* The denoiser lays out one modulation cell per segment and its table is a fixed width the - * arch declares; a pack wider than it would abort the step mid-generation and take the - * engine with it. Refuse here, at submit, where a clean answer is still possible. */ - const int nsegs = nseg - 1; /* `seg` is boundaries: one more than the segments */ - if (d.max_ref_segs > 0 && nsegs > d.max_ref_segs) { - const int nrefs = j->ref_tab.empty() ? 0 : j->ref_tab[0]; - const int64_t fit = (int64_t)d.max_ref_segs - (nsegs - nrefs); /* the fixed non-ref cells */ - return no("these references lay the conditioning out in " + std::to_string(nsegs) + - " sequence segments but this deployment's conditioning table holds " + - std::to_string(d.max_ref_segs) + ", so at most " + - std::to_string(fit < 0 ? 0 : (int)fit) + " fit -- ask for fewer references"); + /* The modulation groups. A modulation cell is fixed by a segment's kind, so the denoiser + * merges runs of consecutive same-cell segments and pitches its fixed-width table by the + * GROUP count, not the reference count -- which is how nine reference photos (four groups: + * prompt, all-photos, soundtrack, video) ride a table the fine layout (twelve segments) + * would overrun. The plugin merges for us (rad_arch_video_mod_segs); one that exports none + * merges nothing, so the group table is the fine one and the older per-segment ceiling + * applies. Refuse over-wide merges here, at submit, where a clean answer is still possible. */ + int nmod = -1; + if (mod_segs_) { + j->mod_seg.assign((size_t)kSegCap, 0); + nmod = (int)mod_segs_(&j->geom, j->ref_tab.data(), j->mod_seg.data(), kSegCap); + if (nmod < 0 || nmod > kSegCap) + return no("the model could not merge the reference conditioning into its " + "modulation groups"); + j->mod_seg.resize((size_t)nmod); + } else { + nmod = nseg; /* nothing merges: the groups are the fine segments */ + j->mod_seg = j->seg; } + j->nmod = nmod; + const int ngroups = nmod - 1; /* `mod_seg` is boundaries: one more than the groups */ + if (d.max_ref_segs > 0 && ngroups > d.max_ref_segs) + return no("these references change the conditioning's modulation cell " + + std::to_string(ngroups) + " times, but this deployment's modulation table holds " + + std::to_string(d.max_ref_segs) + " cells -- ask for references that share their " + "modalities and target, or fewer of them"); /* `rows` stays the plain text+audio+video count: every non-step pass (encode, decode, * audio, upscale) stages its own segment table and target counts from it and must see the * bytes it sees today. Only build_step runs at the widened `step_rows`. */ @@ -677,6 +693,18 @@ void VideoDriver::stage_geom(const Job& j, const RadVideoGeom& g0, int64_t rows, } reg_[R_SEG].used = 4 * 4; } + /* The norm's merged boundaries. On a widened step that is the plugin's merged group table (a + * subset of the fine one just staged into R_SEG); on the plain path and every non-step pass it + * is the fine table verbatim -- nothing merges there, so the norm reads the same bytes as the + * attention and the generated output is exactly what it was before this operand split. */ + int32_t* mod = hptr(R_MOD); + if (wide && j.nmod > 0) { + std::memcpy(mod, j.mod_seg.data(), j.mod_seg.size() * sizeof(int32_t)); + reg_[R_MOD].used = (int64_t)j.mod_seg.size() * 4; + } else { + std::memcpy(mod, seg, reg_[R_SEG].used); + reg_[R_MOD].used = reg_[R_SEG].used; + } int32_t* lat = hptr(R_LAT); lat[0] = 0; lat[1] = (int32_t)video_rows; @@ -710,6 +738,7 @@ void VideoDriver::base_batches(const Job& j, const RadVideoGeom& g, int64_t n_to V.lane_d = dptr(ri, R_LANE); V.first_d = dptr(ri, R_FIRST); V.seg_cu = dptr(ri, R_SEG); + V.mod_cu = dptr(ri, R_MOD); V.lat_cu = dptr(ri, R_LAT); V.n_steps = j.sched.steps; V.t_video = dptr(ri, R_TV); diff --git a/core/gen/video_driver.h b/core/gen/video_driver.h index d0df7671..cc89aa27 100644 --- a/core/gen/video_driver.h +++ b/core/gen/video_driver.h @@ -39,15 +39,19 @@ public: using SegsFn = int64_t (*)(const RadVideoGeom*, int32_t*, int64_t); using PackFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t, float*, int64_t); + using ModSegsFn = int64_t (*)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t); using EncodeGeomFn = int64_t (*)(int32_t, const int64_t*, int32_t*, int64_t); /* `positions` is the plugin's rad_arch_video_positions; `segs`, optional, is its * rad_arch_video_segs (null = the driver stages the plain segment table itself); `pack`, * optional, is its rad_arch_video_pack (null = reference-conditioned sequences cannot be - * laid out and such requests are refused); `enc_geom`, optional, is its + * laid out and such requests are refused); `mod_segs`, optional, is its + * rad_arch_video_mod_segs (null = the driver stages the fine segment table into the norm's + * operand too, correct for any pack that merges nothing); `enc_geom`, optional, is its * rad_arch_encode_geom (null = no encode pass runs). */ int init(const Program& prog, PositionsFn positions, const std::vector& ranks, - SegsFn segs = nullptr, PackFn pack = nullptr, EncodeGeomFn enc_geom = nullptr); + SegsFn segs = nullptr, PackFn pack = nullptr, ModSegsFn mod_segs = nullptr, + EncodeGeomFn enc_geom = nullptr); void fini(); ~VideoDriver() override { fini(); } @@ -94,6 +98,13 @@ private: bool ref_wide = false; int32_t nseg = 0; std::vector seg; + /* The same layout merged to modulation groups: consecutive segments sharing a cell collapse, + * so `mod_seg` holds a SUBSET of `seg`'s boundaries and `nmod` (its count) is what the + * modulation table -- `nmod - 1` cells -- is pitched by. The attention still runs on the fine + * `seg`; only the norm reads `mod_seg`. Empty on the plain path (there the driver stages the + * plain table into both operands). */ + std::vector mod_seg; + int32_t nmod = 0; int64_t lat_v = 0, lat_a = 0; /* The denoising step's row count: the widened total once references ride, otherwise equal * to `rows`. Only build_step uses it -- the encode, decode, audio and upscale passes keep @@ -144,9 +155,13 @@ private: /* R_ENCPX/R_ENCSM/R_ENCG stage one media item for a Vencode/Aencode pass: the encoder-ready * pixels ([frames,h,w,3] f32) or samples ([ch,n] f32) and the encode geometry the plugin's * rad_arch_encode_geom returned, staged verbatim as device i32 for the kernels to read. */ + /* R_MOD is the norm's segment boundaries: the merged modulation-group table (a subset of + * R_SEG's), which the modulated norm reads for its per-cell modulation while the attention + * reads the fine R_SEG. The step stages the merged table; every other pass, and the plain + * path, stages R_SEG's bytes into it as well. */ enum { R_TOK, R_POS, R_CU, R_ROPE, R_GEOM, R_SCHED, R_TV, R_TA, R_SEED, R_LANE, R_FIRST, R_SEG, R_LAT, R_UP, R_MMROW, R_ENCPIX, R_ENCCRD, R_ENCCU, - R_ENCPX, R_ENCSM, R_ENCG, R_N }; + R_ENCPX, R_ENCSM, R_ENCG, R_MOD, R_N }; template T* hptr(int r) const { return reinterpret_cast(host_ + reg_[r].off); } template T* dptr(int rank, int r) const { @@ -182,6 +197,7 @@ private: PositionsFn positions_ = nullptr; SegsFn segs_ = nullptr; PackFn pack_ = nullptr; + ModSegsFn mod_segs_ = nullptr; EncodeGeomFn enc_geom_ = nullptr; int64_t max_tok_ = 0; /* The conditioning's encoder view: the tower's per-patch width and the patches one pass diff --git a/core/plugin/loader.cpp b/core/plugin/loader.cpp index d20a9362..03481650 100644 --- a/core/plugin/loader.cpp +++ b/core/plugin/loader.cpp @@ -234,6 +234,12 @@ int Registry::commit_(Staged& s, int order) { p.arch_video_pack = dl_fn(s.handle, "rad_arch_video_pack"); + /* Optional: the merged modulation-group boundaries the norm reads (a subset of the pack's + * fine segment boundaries). Absent, the driver stages the fine table into the norm operand + * -- fine whenever nothing merges. */ + p.arch_video_mod_segs = + dl_fn( + s.handle, "rad_arch_video_mod_segs"); /* Optional: the encode passes' geometry; absent means the driver runs no encode pass. */ p.arch_encode_geom = dl_fn( diff --git a/core/plugin/registry.h b/core/plugin/registry.h index e5089547..cfd54315 100644 --- a/core/plugin/registry.h +++ b/core/plugin/registry.h @@ -101,6 +101,12 @@ struct Plugin { * out and refuses requests that carry VAE references. */ int64_t (*arch_video_pack)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t, float*, int64_t) = nullptr; + /* Optional (rad_builder.h); the merged modulation-group boundaries a conditioned pack collapses + * to (rad_arch_video_mod_segs). Null with arch_video_pack present means the driver stages the + * fine table into the norm operand too -- correct whenever nothing merges (a plain or a + * single-reference sequence), and refused at submit only when a wide pack would need it. */ + int64_t (*arch_video_mod_segs)(const RadVideoGeom*, const int32_t*, int32_t*, int64_t) = + nullptr; /* Optional (rad_builder.h); null means the driver runs no encode pass. */ int64_t (*arch_encode_geom)(int32_t, const int64_t*, int32_t*, int64_t) = nullptr; diff --git a/docs/NOTE-REF2VA.md b/docs/NOTE-REF2VA.md new file mode 100644 index 00000000..1bd97339 --- /dev/null +++ b/docs/NOTE-REF2VA.md @@ -0,0 +1,130 @@ +# Ref2VA / DaSiWa port note — parity, and what this port does not reproduce + +DaSiWa is the reference ComfyUI workflow for MiniMax-H3 **Ref2VA**: generate a video *with* a +soundtrack conditioned on reference media — up to **nine images, three videos (each optionally with +its own soundtrack), and three standalone audio clips** — plus **continuity**: feeding a previous +clip's tail back in so a longer generation continues from where it left off. This note states where +the Radiance port (`/v1/videos`, `task=ref2va`, dual gfx1201 / TP2) matches that workflow and, more +importantly, **where it does not** — including the reference-count ceiling that once capped this +build at five images and how it now reaches nine. + +Everything below reflects the state on branch `ref2va-merge`. The design derivations live in the +sibling notes (`NOTE-P3-PACK.md`, `NOTE-P2-ENCODE.md`); this one is about capability boundaries. + +## What works today + +- **Image references — ≤9 photos, device-verified.** A request carrying `ref_image_1 … ref_image_9` + runs the full conditioned denoise on both cards and returns a video. Three fixed-seed runs of the + same prompt — no reference, one reference, nine references — produce three distinct outputs, so + the conditioning is demonstrably *live* (not inert) and reference-*aware*, and nine photos no + longer hit the earlier submit-time refusal. +- **Reference-media plumbing and caps.** The container declares 9/3/3 (images/videos/audios); the + VAE-encode passes, the reference table, and the widened step layout are all in place, and the + encode path is now unblocked by the host FFmpeg install. +- **The modulation-cell merge** that lifts the count ceiling (next section). + +## The reference-count ceiling: how it went from ≤5 to ≤9 + +The denoiser's **modulated normalization** reads a *modulation table*: one small vector pair per +"cell", indexed by which segment a row belongs to. The old build sized that table **per reference +segment**. On a dual-32 GB box the table is ≈219 MiB per cell against a 182 MiB KV allowance, so six +to nine photos simply had no headroom and were rejected at submit. + +The table does not actually need a cell per reference. **A cell is a pure function of a segment's +kind**: which modality's ada projection it uses (`video` / `text` / `audio`) and which timestep block +it rides (`video-schedule`, `audio-schedule`, `video-conditioned`, `audio-conditioned`). Every +reference photo is `(video-ada, video-conditioned)` — the *same* cell. So: + +- **Runs of consecutive same-cell segments collapse to one group.** Group boundaries are a strict + *subset* of the fine segment boundaries, and because the merge key is the kind alone, the merge is + **independent of sequence length**. +- The modulated-norm kernel takes its boundaries as an operand and only uses them to index the mod + row and gate — it has no size specialization. So it can be handed the **coarse group boundaries** + while attention keeps the **fine segment boundaries**, and the table is pitched by the **group + count**. Nine photos then occupy **four groups**: *prompt · all-photos · soundtrack · video* — a + twelve-segment fine layout riding a four-cell table. Buffer sizes (and the arena) are unchanged. + +**No regression for ≤5:** before the merge each photo filled its own table column from the *same* +input rows and *same* weights, so every photo cell was already bit-identical to every other; merging +issues that computation once instead of N times and yields the identical per-row value. A five-photo +request is byte-identical before and after the merge — only the previously-rejected sixth through +ninth photos change behavior, by being allowed. + +In short: **for photos the modulation table is no longer the limit.** Nine photos are four groups no +matter how many there are. + +## What this port still cannot reproduce (the honest list) + +1. **Many *interleaved* mixed-modality references would exceed the 8-group table** *(prospective — + only reachable once reference videos are wired, see point 4; today every accepted reference is a + photo, which is four groups and never binds).* Photos are free, but every reference *video* would + contribute two cells in order — *video-conditioned* then its *audio-conditioned* soundtrack — and + a photo placed after it **reopens** the video-conditioned cell, adding a group. Alternating photos + with video-plus-soundtrack refs could push the merged run past `kMaxSegs = 8` cells, which the + driver refuses at submit: *"these references change the conditioning's modulation cell N times, + but this deployment's modulation table holds 8 cells — ask for references that share their + modalities and target, or fewer of them."* **Workaround when videos arrive:** group references by + modality (all photos together, then the videos) so same-kind refs are contiguous and merge; the + ceiling only bites on heavy interleaving. + + *Why the ceiling stays at 8:* widening it means growing the shared `b_ada` / `b_nout` / `b_modg` + buffers on **both** cards — exactly the VRAM a dual-32 GB box does not have. Since the common case + (photos) already fits, this is a deliberate budget boundary, not an oversight. + +2. **The reference-token / row budget is the real binding limit at high resolution.** A conditioned + step lays out *text + all reference rows + target rows* as one fixed-length sequence, and that + must fit the server's `--max-model-len`. Nine large photos fit the four-group modulation table + yet can still exceed the row budget and are refused: *"a conditioned step is N rows and a pass + carries M; ask for a shorter or smaller video, or fewer references."* This is inherent to a + fixed-length DiT sequence — the reference ComfyUI workflow pays the same cost; the modulation + merge removes the *table-per-reference* growth, not the *per-reference token* cost. Raise + `--max-model-len`, or use smaller / fewer references. + +3. **Continuity (tail conditioning) is not yet implemented.** The pack places keyframe / tail + *conditioning rows*, but the driver path that conditions on them **outside the sampler** and trims + after sampling — what makes clip N+1 continue seamlessly from clip N — is still pending. So + multi-segment seamless continuation, as the DaSiWa workflow uses it, is not reproduced yet. Single + generation conditioned on reference *images* is (see point 4 for video / audio). + +4. **Reference videos and audios are refused at submit — not yet wired, even though the encoders + load.** `ref_video_N`, `ref_video_audio_N`, and `ref_audio_N` parts are accepted by the parser, + capped (3 / 3), and paired correctly, but the request is rejected with *"'ref_video_1' is not + consumed yet: reference videos and audios reach the model through the video and audio VAEs … + only ref_image_N parts condition a generation today."* The VAE encoders are declared and loaded, + and the `Vencode` pass runs for **image** references, but no path decodes a video's frames or an + audio's samples into the encoder. **Only reference images condition a generation today.** This is + the single largest remaining DaSiWa gap. The scaffolding is already designed for it — the + `VideoRefMedia` encoder view is documented as *"IMAGE/VIDEO fill the pixels, AUDIO/VIDEO_AUDIO the + samples,"* `decode_video` / `decode_audio` exist in the media layer, and the driver's encode + builder already branches on audio — so enabling them is bounded work, not a redesign: + (a) server-side, decode a video's frames / an audio's samples into `enc_pixels` / `enc_samples` on + the encoder grid (mirroring the image loop); (b) driver-side, drop the submit guard and enqueue + `RAD_ENC_VIDEO` / `RAD_ENC_VAUDIO` / `RAD_ENC_AUDIO` with the right latent grid and slot; (c) a + per-kind device differential (video, audio, video-with-soundtrack) proving each conditions the + output. Until then, treat the mixed-modality interleaving ceiling in point 1 as **prospective** — + today every accepted reference is a photo, which merges to four groups. + +5. **References and latent upscaling are mutually exclusive.** Combining the widened reference + layout with the small-size-then-upscale denoise is not unified; a request asking for both is + refused at submit (*"reference conditioning does not yet combine with latent upscale"*). Ask for + the target size directly. + +6. **Numeric parity with the reference denoiser for the *conditioned* step is not yet published.** + Conditioning is verified *active* and *reference-content-sensitive* on-device (see the controlled + check below), but a per-tensor / perceptual match to ComfyUI's outputs for the wide step is an open + parity task. Plain (unconditioned) generation retains its existing parity, and the merge is a no-op + there: with three fine segments the merged group table *is* the fine table. + +## Reproducing the checks + +- **Host:** `tests/ref2va_pack_test.cpp` — asserts the group invariants: photos collapse to the + prompt/photos/audio/video quartet; group boundaries are a subset of the fine boundaries; the merge + is sequence-length independent; a plain request merges to exactly its three fine segments. +- **Device (controlled — a *fixed seed on every job*, or a distinct output proves nothing):** run + `/v1/videos` with `task=ref2va` and one `seed` value held constant. Two jobs with the **same seed, + same prompt, same reference count, but different image content** must give **different** `sha256`s — + that content-control is what proves the reference is genuinely consumed (a with-ref vs no-ref pair + is confounded: an image also changes the prompt's token count). Add a `ref_image_1 … ref_image_9` + job: it must *complete* with a clean fault scan — that nine-photo completion is the ceiling lifted + (the pinned build refused it at submit). Sending `seed` and the reference parts requires `task= + ref2va`; the reference parts must be real file parts (e.g. `curl -F ref_image_1=@pic.png`). diff --git a/tests/ref2va_pack_test.cpp b/tests/ref2va_pack_test.cpp index 70f6137a..16d30599 100644 --- a/tests/ref2va_pack_test.cpp +++ b/tests/ref2va_pack_test.cpp @@ -262,4 +262,89 @@ TEST(pack_ref_kinds_predicates) { CHECK(!ref2va_is_audio(kR2VRefImg) && !ref2va_is_img(kR2VRefAudio)); } +TEST(pack_mod_groups_images_collapse_to_four) { + /* Nine reference photos -- the reference-to-video workflow's request. Every photo is a + * video-pinned reference block sharing ONE modulation cell, so all nine merge into a single + * group: the sequence collapses to FOUR groups (prompt, all-photos, soundtrack, video) whatever + * the photo count. This merge is what lets a nine-photo request ride the fixed kMaxSegs-wide + * modulation table that its twelve fine segments would otherwise overrun. */ + Ref2VAGeom g{ 2, 8, 8, 3 }; + std::vector refs(9, Ref2VARef{ kR2VRefImage, 6, 6, 1, 0 }); + Ref2VAPack p; + CHECK_EQ(ref2va_build(7, g, {}, refs, &p), 0); + CHECK_EQ(p.segs.size(), 12u); /* text + 9 photos + audio + video */ + + const int64_t S = 24; + Ref2VAModGroups grp; + ref2va_mod_groups(p, S, &grp); + CHECK_EQ(grp.md.size(), 4u); + CHECK(grp.md == std::vector({ 1, 0, 2, 0 })); /* text, photos, audio, video */ + /* Cells: text and the video target read the video schedule (r0 = 0); the photos read the + * video-PINNED block (2S); the soundtrack reads the audio schedule (S). */ + CHECK(grp.r0 == std::vector({ 0, 2 * S, S, 0 })); + CHECK_EQ(grp.bound.size(), 5u); + CHECK_EQ(grp.bound.front(), 0); + CHECK_EQ(grp.bound.back(), p.rows); + /* The photo group's span is the whole run of reference rows: it starts where the prompt ends and + * ends where the soundtrack starts -- the two fine boundaries that survive the merge. */ + const int64_t text_end = p.segs[0].end, audio_start = p.segs[p.segs.size() - 2].start; + CHECK_EQ(grp.bound[1], text_end); + CHECK_EQ(grp.bound[2], audio_start); +} + +TEST(pack_mod_groups_invariants_over_the_goldens) { + /* For every golden pack: the merged boundaries span the sequence and are a strictly-increasing + * SUBSET of the fine segment boundaries (so no fine segment is ever split); every fine segment + * lies wholly inside one group whose modality is the segment's own tag; no two adjacent groups + * share a cell (the merge is maximal -- had they, they would have collapsed); and the merge is + * independent of the step count S -- the driver derives it at S = 1, the denoiser at the real S, + * so the boundaries must be identical for the two tables to line up. */ + for (const char* name : { "t2va", "fl2va", "ref2va_all", "chain", "no_text" }) { + const Ref2VAPack p = build_case(golden()[name]); + Ref2VAModGroups a, b; + ref2va_mod_groups(p, 1, &a); + ref2va_mod_groups(p, 64, &b); + CHECK(a.bound == b.bound); + CHECK(!a.bound.empty()); + CHECK_EQ(a.bound.front(), 0); + CHECK_EQ(a.bound.back(), p.rows); + for (size_t i = 0; i + 1 < a.bound.size(); ++i) + CHECK(a.bound[i] < a.bound[i + 1]); + /* every boundary is a fine boundary (a segment start, or the closing rows count) */ + for (int64_t x : a.bound) { + bool found = (x == p.rows); + for (const Ref2VASeg& s : p.segs) if (s.start == x) found = true; + CHECK(found); + } + /* every fine segment sits whole in a group carrying its own modality */ + for (const Ref2VASeg& s : p.segs) { + if (s.end <= s.start) continue; + size_t g = 0; + while (g + 1 < a.bound.size() && a.bound[g + 1] <= s.start) ++g; + CHECK(a.bound[g] <= s.start && s.end <= a.bound[g + 1]); + CHECK_EQ(a.md[g], ref2va_seg_tag(s.kind)); + } + /* adjacent groups differ in (md, r0) -- merging left no mergeable neighbours */ + for (size_t i = 0; i + 1 < a.md.size(); ++i) + CHECK(a.md[i] != a.md[i + 1] || a.r0[i] != a.r0[i + 1]); + } +} + +TEST(pack_mod_groups_plain_equals_the_fine_table) { + /* A plain [text | audio | video] pack has three distinct cells -- no two share one -- so it + * merges to exactly the three fine groups and its boundaries equal the fine ones. That is why + * a driver with no mod-seg export can stage the fine table into the norm operand unchanged and + * reproduce the pre-merge output byte for byte. */ + Ref2VAPack p; + Ref2VAGeom g{ 3, 8, 10, 4 }; + CHECK_EQ(ref2va_build(5, g, {}, {}, &p), 0); + Ref2VAModGroups grp; + ref2va_mod_groups(p, 32, &grp); + CHECK_EQ(grp.md.size(), 3u); + CHECK(grp.md == std::vector({ 1, 2, 0 })); /* text, audio, video */ + CHECK(grp.r0 == std::vector({ 0, 32, 0 })); /* video sched, audio sched, video */ + CHECK_EQ(grp.bound.size(), 4u); + CHECK(grp.bound == std::vector({ 0, 5, 13, 5 + 8 + 60 })); +} + RAD_TEST_MAIN() diff --git a/tests/video_gen_test.cpp b/tests/video_gen_test.cpp index 6a41b999..5bbbf63f 100644 --- a/tests/video_gen_test.cpp +++ b/tests/video_gen_test.cpp @@ -214,10 +214,11 @@ struct VideoFixture { } int start_with_encode_gen(gen::VideoDriver::EncodeGeomFn enc) { return drv.init(prog, fake_positions, { gen::VideoDriver::RankIO{} }, nullptr, nullptr, - enc); + nullptr, enc); } int start_with_pack_encode(gen::VideoDriver::PackFn pack, gen::VideoDriver::EncodeGeomFn enc) { - return drv.init(prog, fake_positions, { gen::VideoDriver::RankIO{} }, nullptr, pack, enc); + return drv.init(prog, fake_positions, { gen::VideoDriver::RankIO{} }, nullptr, pack, + nullptr, enc); } std::unique_ptr req(int32_t chunks = 2, int32_t steps = 0) { auto r = std::make_unique();