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
@@ -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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user