ops: the tiled encode ops take their row count from the operands, not from M

The engine never hands a kernel the issued value of a ranged parameter: the oracle
binds it to the matched band's bound, and ref_common.h's band_rows spells the rule
out -- the parameter stays a ceiling where one is stated -- which is why every
existing kernel derives its counts from its operands. vtile_plan/crop/join were the
first to read M as the row count of the call, so the first real tiled encode refused
on device: a 512 keyframe's 3 x 3 plan, issued under the band bound 33, tripped the
wrapper's rows-of-y < M clause, which answered RAD_E_STRIDE -- and the strerror
insisted, wrongly, that a non-contiguous operand was the problem. Crop and join
carried the same latent bug: crop would have launched 33 blocks over a ~590k-row
cut, and both would have refused every canvas under their bands' real bounds.

All three tiers now count from the operands and treat the passed M as the ceiling it
is -- y longer than the ceiling is refused, equality never demanded. The reference
and host tiers take the count from geom through band_rows; the device wrappers take
it from y's rows and pass that count in the kernel's M slot, which the kernels' own
operand-row guards make safe. OPS.md says the rule once at the head of the tiled
encoder section: an M written in a shape is an operand's row count, the ranged M
argument a ceiling only.

The host gates missed the bug precisely because they drove an exact M. ref_test's
three vtile cases now pass the band's bound -- 33, 33 * 256 * 256, 320 * 320 -- and
demand the same exact output, plus short-operand cases that must refuse E_SHAPE
under the over-declared ceiling; r4d_selftest drives the same bounds on device.
Verified: ref_test 264 cases, device vtile plan 4 / crop 8 / join 5 / gather 2 /
stitch 8 all exact, full ctest 123/123; and the FL2VA render that used to die in
tiled encode now runs its 25 steps with both keyframes visible in the decoded clip.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
gearwave00001andClaude committed 2026-10-25 11:23:15 -05:00
1 parent fe311c5c80
commit c463a0ab1b
6 files changed
+98 -40

No files matched your search

+6 -2
View File
@@ -1564,14 +1564,18 @@ one latent plane. The encoder itself is the existing per-level ops, issued per t
geometries; these three ops are the plan, the cut and the blend. Their axis split is vae.py's
`split_tiles`, whose multi-tile branch is the decoder's rule above exactly but whose single-tile
branch answers one tile `[0, L)` even when `tile > L` -- a lone short tile, which the decoder's
exact-fit split refuses. MiniMax-H3: `tile` 16 latents, `overlap` 4, `ratio` 16.
exact-fit split refuses. MiniMax-H3: `tile` 16 latents, `overlap` 4, `ratio` 16. An `M` written
in a shape below is that operand's row count, which the kernels read from the operand; the ranged
`M` argument is a ceiling only, as everywhere else -- the engine binds a ranged parameter to the
band's bound, never to this call's rows.
- `vtile_plan`: the plan for one frame of `geom` = `(clip, H, W)` pixels, split in latent units
over the spatial axes and numbered row-major over (row band, column band). Row `t` of the i32
`y [M, 22]`: the tile's first pixel `(y0, x0)` at [0] [1], its pixel extent `(th, tw)` at
[2] [3] (`tile ratio`, save the lone short tile), and level `L`'s volume
`(1, th / 2^min(L, 4), tw / 2^min(L, 4))` at `3 L + 4` for `L = 0..5` -- the encoder's five
levels and the deepest one's repeat, which shares it. `M` is the tile count.
levels and the deepest one's repeat, which shares it. The tile count is `y`'s row count, the
`M` argument a ceiling only.
- `vtile_crop`: the frame's pixel plane `x [>= H W, 3]` (pixel `(Y, X)` at row `Y W + X`) cut into
the plan's tiles: `y [M, 3]` holds the tiles' pixels tile-major, tile `t`'s `(th, tw)` rows in
plane order at their offset in the sum; `M` is the tiles' pixel count. The tiles' union covers
+14 -10
View File
@@ -464,12 +464,14 @@ AVX_KERNEL(vtile_stitch) {
/* The plan one frame's encode runs over (libref): geom = (clip, H, W) the frame's extent in
* pixels, split by split_tiles_axis over the spatial axes in latent units; row t of y (i32
* [M, 22]) the tile's first pixel, its pixel extent, and the six level volumes. */
/* The tile count comes from G; the ranged `M` is a ceiling only (libref's band_rows rule -- the
* engine binds a ranged parameter to its band's bound, not to this call). */
AVX_KERNEL(vtile_plan) {
if (!rad_args_have(a, 2)) return RAD_E_INVAL;
const RadTensor *G = &a->t[0], *Y = &a->t[1];
const int64_t M = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t band = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t overlap = p_int(a, "overlap", 0), ratio = p_int(a, "ratio", 0);
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(G) < 3)
if (tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(G) < 3)
return RAD_E_SHAPE;
const int64_t H = at(G, 1), W = at(G, 2);
std::vector<int64_t> sy, sx, oy, ox;
@@ -478,7 +480,8 @@ AVX_KERNEL(vtile_plan) {
!split_tiles_axis(W / ratio, tile, overlap, &sx, &ox))
return RAD_E_SHAPE;
const int64_t nh = (int64_t)sy.size(), nw = (int64_t)sx.size();
if (M != nh * nw || rows_of(Y, 22) < M) return RAD_E_SHAPE;
const int64_t M = band_rows(nh * nw, band);
if (M <= 0 || rows_of(Y, 22) < M) return RAD_E_SHAPE;
const int64_t* psy = sy.data(), *psx = sx.data();
AVX_PARALLEL_FOR_IF(M >= AVX_PAR_MIN)
for (int64_t t = 0; t < M; ++t) {
@@ -500,9 +503,9 @@ AVX_KERNEL(vtile_plan) {
AVX_KERNEL(vtile_crop) {
if (!rad_args_have(a, 3)) return RAD_E_INVAL;
const RadTensor *X = &a->t[0], *G = &a->t[1], *Y = &a->t[2];
const int64_t M = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t band = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t overlap = p_int(a, "overlap", 0), ratio = p_int(a, "ratio", 0);
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(G) < 3)
if (tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(G) < 3)
return RAD_E_SHAPE;
const int64_t H = at(G, 1), W = at(G, 2);
std::vector<int64_t> sy, sx, oy, ox;
@@ -519,7 +522,8 @@ AVX_KERNEL(vtile_crop) {
off[(size_t)(i * nw + j)] +
th * std::min(tile, W / ratio - sx[(size_t)j]) * ratio;
}
if (M != off.back() || rows_of(X, 3) < H * W || rows_of(Y, 3) < M) return RAD_E_SHAPE;
const int64_t M = band_rows(off.back(), band);
if (M <= 0 || rows_of(X, 3) < H * W || rows_of(Y, 3) < M) return RAD_E_SHAPE;
const int64_t* psy = sy.data(), *psx = sx.data(), *poff = off.data();
AVX_PARALLEL_FOR_IF(M * 3 >= AVX_PAR_MIN)
for (int64_t r = 0; r < M; ++r) {
@@ -543,9 +547,9 @@ AVX_KERNEL(vtile_crop) {
AVX_KERNEL(vtile_join) {
if (!rad_args_have(a, 3)) return RAD_E_INVAL;
const RadTensor *X = &a->t[0], *G = &a->t[1], *Y = &a->t[2];
const int64_t M = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t band = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t overlap = p_int(a, "overlap", 0), n = p_int(a, "n", 0);
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || n <= 0 || numel(G) < 3)
if (tile <= 0 || overlap < 0 || overlap >= tile || n <= 0 || numel(G) < 3)
return RAD_E_SHAPE;
const int64_t H = at(G, 1), W = at(G, 2);
std::vector<int64_t> sy, sx, oy, ox;
@@ -553,7 +557,7 @@ AVX_KERNEL(vtile_join) {
!split_tiles_axis(W, tile, overlap, &sx, &ox))
return RAD_E_SHAPE;
const int64_t nh = (int64_t)sy.size(), nw = (int64_t)sx.size();
if (M != H * W) return RAD_E_SHAPE;
const int64_t M = band_rows(H * W, band);
std::vector<int64_t> off((size_t)(nh * nw + 1), 0);
for (int64_t i = 0; i < nh; ++i) {
const int64_t th = std::min(tile, H - sy[(size_t)i]);
@@ -561,7 +565,7 @@ AVX_KERNEL(vtile_join) {
off[(size_t)(i * nw + j + 1)] =
off[(size_t)(i * nw + j)] + th * std::min(tile, W - sx[(size_t)j]);
}
if (rows_of(X, n) < off.back() || rows_of(Y, n) < M) return RAD_E_SHAPE;
if (M <= 0 || rows_of(X, n) < off.back() || rows_of(Y, n) < M) return RAD_E_SHAPE;
/* The owner tile of every canvas row and column. */
std::vector<int64_t> own_y((size_t)H), own_x((size_t)W);
for (int64_t Yp = 0, i = 0; Yp < H; ++Yp) {
+8 -4
View File
@@ -7537,9 +7537,11 @@ void vtile_plan_cases(const Plugin& pl) {
void* dy = dalloc((size_t)(M * 22) * 4);
const std::string nm = fmt("vtile_plan %lld x %lld in %lld x %lld tiles", (long long)H,
(long long)W, (long long)nh, (long long)nw);
/* M rides the band's bound (m.tiles), as the engine binds it -- never this call's tile
* count; the tile count comes from geom and y's rows. */
const int rc = launch(r, { TI32({ 3 }, { 1, (int32_t)H, (int32_t)W }),
T(dy, RAD_I32, { M, 22 }) },
{ PI("M", M), PI("tile", 16), PI("overlap", 4), PI("ratio", 16) });
{ PI("M", 33), PI("tile", 16), PI("overlap", 4), PI("ratio", 16) });
if (rc != RAD_OK) { ok(nm.c_str(), false, "rc " + std::to_string(rc)); continue; }
std::vector<int32_t> want((size_t)(M * 22));
for (int64_t i = 0; i < nh; ++i)
@@ -7594,9 +7596,10 @@ void vtile_crop_cases(const Plugin& pl) {
void* dy = dalloc((size_t)(M * 3) * (bf ? 2 : 4));
const std::string nm = fmt("vtile_crop %lld x %lld %s tile %lld", (long long)H,
(long long)W, bf ? "bf16" : "f32", (long long)tile);
/* M rides the band's bound, as the engine binds it; the cut's rows come from y. */
const int rc = launch(r, { T(dx, dt, { H * W, 3 }), TI32({ 3 }, { 1, (int32_t)H, (int32_t)W }),
T(dy, dt, { M, 3 }) },
{ PI("M", M), PI("tile", tile), PI("overlap", ov),
{ PI("M", 33 * 256 * 256), PI("tile", tile), PI("overlap", ov),
PI("ratio", ratio), PS("dtype", bf ? "bf16" : "f32") });
if (rc != RAD_OK) { ok(nm.c_str(), false, "rc " + std::to_string(rc)); continue; }
std::vector<float> want((size_t)(M * 3));
@@ -7638,9 +7641,10 @@ void vtile_join_cases(const Plugin& pl) {
void* dy = dalloc((size_t)(M * n) * 2);
const std::string nm = fmt("vtile_join %lld x %lld bf16 tile %lld", (long long)H,
(long long)W, (long long)tile);
/* M rides the band's bound, as the engine binds it; the canvas rows come from y. */
const int rc = launch(r, { T(dx, RAD_BF16, { Sm, n }), TI32({ 3 }, { 1, (int32_t)H, (int32_t)W }),
T(dy, RAD_BF16, { M, n }) },
{ PI("M", M), PI("tile", tile), PI("overlap", ov), PI("n", n),
{ PI("M", 320 * 320), PI("tile", tile), PI("overlap", ov), PI("n", n),
PS("dtype", "bf16") });
if (rc != RAD_OK) { ok(nm.c_str(), false, "rc " + std::to_string(rc)); continue; }
/* The blends round to bf16 at every step, as the kernel's rdv does. */
@@ -7686,7 +7690,7 @@ void vtile_join_cases(const Plugin& pl) {
const int rc = launch(r, { T(dx, RAD_F32, { 9 * tile * tile, n }),
TI32({ 3 }, { 1, (int32_t)H, (int32_t)W }),
T(dy, RAD_F32, { H * W, n }) },
{ PI("M", H * W), PI("tile", tile), PI("overlap", ov), PI("n", n),
{ PI("M", 320 * 320), PI("tile", tile), PI("overlap", ov), PI("n", n),
PS("dtype", "f32") });
if (rc != RAD_OK) { ok("vtile_join 32 x 32 exact f32", false, "rc " + std::to_string(rc)); }
else {
+18 -9
View File
@@ -860,13 +860,17 @@ extern "C" int r4d_rad_vtile_plan(const RadArgs* a, RadStream s) {
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 ||
r4d_numel(geom) < 3)
return R4D_NO(RAD_E_SHAPE);
/* The tile count comes from y: the engine binds the ranged parameter to the band's bound,
* not to this call's rows (ref_common.h's `band_rows` rule), and r4d_rows_pitch already
* read y narrowed to them. The parameter is a ceiling only. */
long long ry = 0;
const long long yl = r4d_rows_pitch(y, 22, &ry);
if (yl < 0 || !r4d_contig(geom) || ry < M) return R4D_NO(RAD_E_STRIDE);
const int64_t total = (int64_t)M * 22;
if (yl < 0 || !r4d_contig(geom)) return R4D_NO(RAD_E_STRIDE);
if (ry <= 0 || (M > 0 && ry > M)) return R4D_NO(RAD_E_SHAPE);
const int64_t total = ry * 22;
hipLaunchKernelGGL(vtile_plan_kernel, dim3(blocks_for(total)), dim3(kT), 0, (hipStream_t)s,
(const int*)geom->data, (int*)y->data, (int)tile, (int)overlap, (int)ratio,
(int)yl, M, ry);
(int)yl, ry, ry);
return st_of(hipGetLastError());
}
@@ -881,13 +885,16 @@ extern "C" int r4d_rad_vtile_crop(const RadArgs* a, RadStream s) {
r4d_numel(geom) < 3)
return R4D_NO(RAD_E_SHAPE);
long long rx = 0, ry = 0;
/* y's rows are the tiles' pixel rows this call cuts; the ranged `M` is the band's bound, a
* ceiling only (ref_common.h's `band_rows` rule). The kernel re-walks the tiles and stops at
* their sum, so rows past it -- when the band overshoots the cut -- write nothing. */
const long long xl = r4d_rows_pitch(x, 3, &rx), yl = r4d_rows_pitch(y, 3, &ry);
if (xl < 0 || yl < 0 || !r4d_contig(geom)) return R4D_NO(RAD_E_STRIDE);
if (ry < M) return R4D_NO(RAD_E_SHAPE);
if (ry <= 0 || (M > 0 && ry > M)) return R4D_NO(RAD_E_SHAPE);
#define R4D_VTC(T) \
hipLaunchKernelGGL((vtile_crop_kernel<T>), dim3(blocks_for(M)), dim3(kT), 0, (hipStream_t)s, \
hipLaunchKernelGGL((vtile_crop_kernel<T>), dim3(blocks_for(ry)), dim3(kT), 0, (hipStream_t)s, \
(const T*)x->data, (const int*)geom->data, (T*)y->data, (int)tile, \
(int)overlap, (int)ratio, (int)xl, (int)yl, M, rx, ry)
(int)overlap, (int)ratio, (int)xl, (int)yl, ry, rx, ry)
if (is_f32(x)) R4D_VTC(float);
else R4D_VTC(uint16_t);
#undef R4D_VTC
@@ -904,13 +911,15 @@ extern "C" int r4d_rad_vtile_join(const RadArgs* a, RadStream s) {
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || n <= 0 || r4d_numel(geom) < 3)
return R4D_NO(RAD_E_SHAPE);
long long rx = 0, ry = 0;
/* The canvas is y: its rows are the join's threads. The ranged `M` is the band's bound, a
* ceiling only (ref_common.h's `band_rows` rule). */
const long long xl = r4d_rows_pitch(x, n, &rx), yl = r4d_rows_pitch(y, n, &ry);
if (xl < 0 || yl < 0 || !r4d_contig(geom)) return R4D_NO(RAD_E_STRIDE);
if (ry < M) return R4D_NO(RAD_E_SHAPE);
if (ry <= 0 || (M > 0 && ry > M)) return R4D_NO(RAD_E_SHAPE);
#define R4D_VTJ(T) \
hipLaunchKernelGGL((vtile_join_kernel<T>), dim3(blocks_for(M)), dim3(kT), 0, (hipStream_t)s, \
hipLaunchKernelGGL((vtile_join_kernel<T>), dim3(blocks_for(ry)), dim3(kT), 0, (hipStream_t)s, \
(const T*)x->data, (const int*)geom->data, (T*)y->data, (int)tile, \
(int)overlap, (int)n, (int)xl, (int)yl, M, rx, ry)
(int)overlap, (int)n, (int)xl, (int)yl, ry, rx, ry)
if (is_f32(x)) R4D_VTJ(float);
else R4D_VTJ(uint16_t);
#undef R4D_VTJ
+20 -15
View File
@@ -733,13 +733,14 @@ int ref_cond_aug(const RadArgs* a, RadStream) {
* encoder's five levels and the deepest one's repeat, which shares it (no
* downsampler between them), exactly venc_geom's level layout for one frame.
*
* M is the tile count; any other count is refused. */
* The tile count comes from `geom`: the engine binds a ranged parameter to its band's bound,
* not to this call, so `M` is a ceiling only (band_rows) and y must hold the tiles. */
int ref_vtile_plan(const RadArgs* a, RadStream) {
if (!have(a, 2)) return RAD_E_INVAL;
const RadTensor *geom = &a->t[0], *y = &a->t[1];
const int64_t M = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t band = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t overlap = p_int(a, "overlap", 0), ratio = p_int(a, "ratio", 0);
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(geom) < 3)
if (tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(geom) < 3)
return RAD_E_SHAPE;
const int64_t H = ldi(geom, 1), W = ldi(geom, 2);
std::vector<int64_t> sy, sx, oy, ox;
@@ -748,7 +749,8 @@ int ref_vtile_plan(const RadArgs* a, RadStream) {
!split_tiles_axis(W / ratio, tile, overlap, &sx, &ox))
return RAD_E_SHAPE;
const int64_t nh = (int64_t)sy.size(), nw = (int64_t)sx.size();
if (M != nh * nw || rows_of(y, 22) < M) return RAD_E_SHAPE;
const int64_t M = band_rows(nh * nw, band);
if (M <= 0 || rows_of(y, 22) < M) return RAD_E_SHAPE;
REF_PAR_FOR(M)
for (int64_t t = 0; t < M; ++t) {
const int64_t i = t / nw, j = t % nw;
@@ -766,15 +768,16 @@ int ref_vtile_plan(const RadArgs* a, RadStream) {
/* ------------------------------------------------------------------ vtile_crop */
/* One frame's pixel plane cut into vtile_plan's tiles: x f32 [>= H W, 3] is the plane (pixel
* (Y, X) at row Y W + X) of geom = (clip, H, W) in pixels; y f32 [M, 3] holds the tiles' pixels
* tile-major, tile t's (th, tw) rows in plane order at their offset in the sum. M is the tiles'
* pixel count, sum of th tw over the plan. Only the row the tile stands on is read; the tiles'
* union covers the plane, but their sum may exceed it -- that is why y is its own buffer. */
* tile-major, tile t's (th, tw) rows in plane order at their offset in the sum. The cut's row
* count -- the sum of th tw over the plan -- comes from `geom`; `M` is a ceiling only
* (band_rows). Only the row the tile stands on is read; the tiles' union covers the plane, but
* their sum may exceed it -- that is why y is its own buffer. */
int ref_vtile_crop(const RadArgs* a, RadStream) {
if (!have(a, 3)) return RAD_E_INVAL;
const RadTensor *x = &a->t[0], *geom = &a->t[1], *y = &a->t[2];
const int64_t M = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t band = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t overlap = p_int(a, "overlap", 0), ratio = p_int(a, "ratio", 0);
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(geom) < 3)
if (tile <= 0 || overlap < 0 || overlap >= tile || ratio <= 0 || numel(geom) < 3)
return RAD_E_SHAPE;
const int64_t H = ldi(geom, 1), W = ldi(geom, 2);
std::vector<int64_t> sy, sx, oy, ox;
@@ -791,7 +794,8 @@ int ref_vtile_crop(const RadArgs* a, RadStream) {
off[(size_t)(i * nw + j)] +
th * std::min(tile, W / ratio - sx[(size_t)j]) * ratio;
}
if (M != off.back() || rows_of(x, 3) < H * W || rows_of(y, 3) < M) return RAD_E_SHAPE;
const int64_t M = band_rows(off.back(), band);
if (M <= 0 || rows_of(x, 3) < H * W || rows_of(y, 3) < M) return RAD_E_SHAPE;
REF_PAR_FOR(M * 3)
for (int64_t r = 0; r < M; ++r) {
const int64_t t = (int64_t)(std::upper_bound(off.begin(), off.end(), r) - off.begin()) - 1;
@@ -823,13 +827,14 @@ int ref_vtile_crop(const RadArgs* a, RadStream) {
*
* the first when i > 0 and ly < ev, the second when j > 0 and lx < eh. Only a lone tile is
* short, and it has no neighbour, so a neighbour's extent along the blended axis is always
* `tile`. */
* `tile`. The canvas' row count -- lat_h lat_w -- comes from `geom`; `M` is a ceiling only
* (band_rows). */
int ref_vtile_join(const RadArgs* a, RadStream) {
if (!have(a, 3)) return RAD_E_INVAL;
const RadTensor *x = &a->t[0], *geom = &a->t[1], *y = &a->t[2];
const int64_t M = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t band = p_int(a, "M", 0), tile = p_int(a, "tile", 0);
const int64_t overlap = p_int(a, "overlap", 0), n = p_int(a, "n", 0);
if (M <= 0 || tile <= 0 || overlap < 0 || overlap >= tile || n <= 0 || numel(geom) < 3)
if (tile <= 0 || overlap < 0 || overlap >= tile || n <= 0 || numel(geom) < 3)
return RAD_E_SHAPE;
const int64_t H = ldi(geom, 1), W = ldi(geom, 2);
std::vector<int64_t> sy, sx, oy, ox;
@@ -837,7 +842,7 @@ int ref_vtile_join(const RadArgs* a, RadStream) {
!split_tiles_axis(W, tile, overlap, &sx, &ox))
return RAD_E_SHAPE;
const int64_t nh = (int64_t)sy.size(), nw = (int64_t)sx.size();
if (M != H * W) return RAD_E_SHAPE;
const int64_t M = band_rows(H * W, band);
std::vector<int64_t> off((size_t)(nh * nw + 1), 0);
for (int64_t i = 0; i < nh; ++i) {
const int64_t th = std::min(tile, H - sy[(size_t)i]);
@@ -845,7 +850,7 @@ int ref_vtile_join(const RadArgs* a, RadStream) {
off[(size_t)(i * nw + j + 1)] =
off[(size_t)(i * nw + j)] + th * std::min(tile, W - sx[(size_t)j]);
}
if (rows_of(x, n) < off.back() || rows_of(y, n) < M) return RAD_E_SHAPE;
if (M <= 0 || rows_of(x, n) < off.back() || rows_of(y, n) < M) return RAD_E_SHAPE;
/* The owner tile of every canvas row and column. */
std::vector<int64_t> own_y((size_t)H), own_x((size_t)W);
for (int64_t Y = 0, i = 0; Y < H; ++Y) {
+32
View File
@@ -6949,6 +6949,16 @@ TEST(vtile_plan_plans_one_frame_the_way_vae_py_splits_it) {
T g2(RAD_I32, {3}); g2.n({1, 100, 96});
A d; d.t(g2).t(y1).i("M", 1).i("tile", 16).i("overlap", 4).i("ratio", 16);
CHECK_EQ(run("vtile_plan", d), RAD_E_SHAPE);
/* The engine binds M to the band's bound (m.tiles), never to this call: a ceiling above the
* tiles plans the same rows, and a y that cannot hold them is still refused. */
T yb(RAD_I32, {6, 22});
A f; f.t(geom).t(yb).i("M", 33).i("tile", 16).i("overlap", 4).i("ratio", 16);
CHECK_OK(run("vtile_plan", f));
for (int64_t t = 0; t < 6; ++t) CHECK_EQ(yb.iat(t * 22 + 0), y0[t]);
T ys(RAD_I32, {5, 22});
A g; g.t(geom).t(ys).i("M", 33).i("tile", 16).i("overlap", 4).i("ratio", 16);
CHECK_EQ(run("vtile_plan", g), RAD_E_SHAPE);
}
/* A 20 x 20 px plane in ratio 4, tiles of 3 latents (12 px) with overlap 1: each axis splits at
@@ -7016,6 +7026,16 @@ TEST(vtile_crop_cuts_the_plane_tile_major) {
T x2(RAD_F32, {399, 3});
A d; d.t(x2).t(geom).t(y).i("M", 576).i("tile", 3).i("overlap", 1).i("ratio", 4);
CHECK_EQ(run("vtile_crop", d), RAD_E_SHAPE);
/* The engine binds M to the band's bound, never to this call: a ceiling above the cut copies
* the same rows, and a y that cannot hold the tiles is still refused. */
T yb(RAD_F32, {576, 3});
A f; f.t(x).t(geom).t(yb).i("M", 33 * 256 * 256).i("tile", 3).i("overlap", 1).i("ratio", 4);
CHECK_OK(run("vtile_crop", f));
CHECK_EQ(yb.at(575 * 3 + 2), (float)399);
T ys(RAD_F32, {575, 3});
A g; g.t(x).t(geom).t(ys).i("M", 33 * 256 * 256).i("tile", 3).i("overlap", 1).i("ratio", 4);
CHECK_EQ(run("vtile_crop", g), RAD_E_SHAPE);
}
/* A 6 x 6 latent canvas, tiles of 4 with overlap 2: each axis splits at 0 and 2, the kept ranges
@@ -7089,6 +7109,18 @@ TEST(vtile_join_blends_raw_neighbours_down_then_across) {
T x2(RAD_BF16, {63, 1});
A d; d.t(x2).t(geom).t(y).i("M", 36).i("tile", 4).i("overlap", 2).i("n", 1).s("dtype", "bf16");
CHECK_EQ(run("vtile_join", d), RAD_E_SHAPE);
/* The engine binds M to the band's bound, never to this call: a ceiling above the canvas
* blends the same rows, and a y short of the canvas is still refused. */
T yb(RAD_BF16, {36, 1});
A f; f.t(x).t(geom).t(yb).i("M", 320 * 320).i("tile", 4).i("overlap", 2).i("n", 1)
.s("dtype", "bf16");
CHECK_OK(run("vtile_join", f));
CHECK_EQ(yb.at(5 * 6 + 5), 32.0f);
T ys(RAD_BF16, {35, 1});
A g; g.t(x).t(geom).t(ys).i("M", 320 * 320).i("tile", 4).i("overlap", 2).i("n", 1)
.s("dtype", "bf16");
CHECK_EQ(run("vtile_join", g), RAD_E_SHAPE);
}
/* ================================================================== the latent upscaler