Archived
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:
1 parent
fe311c5c80
commit
c463a0ab1b
6 files changed
+98
-40
No files matched your search
+14
-10
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user