Cycle 4 (LPF wd=8) closure: M1=100%, R=0.34, M4=+4.1%, PASS

Fourth daedalus-fourier kernel — VP9 8-tap inner loop filter wd=8
h_8_8 variant. Width extension of cycle 2's wd=4; completes VP9
inner-edge LPF coverage. Full cycle Phase 1-7 + M4'''' in one
combined go (cycle compressed since incremental from cycle 2).

Phase 5 review explicitly skipped (incremental ~30-line shader
delta from cycle 2 + same geometry + cycle-2 RED-pattern checks
still apply). Flagged in docs/k4_lpf8_phase4_7.md per dev_process.md
"Skipping phases is a deliberate choice that should be flagged."

Phase 6 v1 first-light: M1'''' 100.0000% bit-exact (65536/65536)
first try. Shaderdb shows 231 inst, 4 hardware threads, 0 spills,
27 max-temps, 48 uniforms — compiler at the latency-hiding ceiling.

Performance:

  M3'''' NEON (single-core)  52.382 Medge/s
  M2'''' QPU isolation       17.847 Medge/s
  R''''                      0.341  → ORANGE band
  30fps floor margin         9.2x (isolation), 20.3x (mixed)

M4'''' concurrent matrix:

  NEON 4-core                37.823 Medge/s  <- baseline
  QPU only                   14.867 Medge/s
  MIXED NEON-3 + QPU         39.389 Medge/s  <- +4.1% PASS

Verdict: YELLOW-via-M4'''' PASS. Deploy wd=8 LPF on QPU alongside
cycle 2 wd=4. Combined VP9 inner-edge LPF coverage now complete.

Cross-cycle LPF comparison:

  | | wd=4 (k2) | wd=8 (k4) |
  | M3 NEON     | 48.3      | 52.4      |
  | M2 QPU iso  | 19.6      | 17.8      |
  | R iso       | 0.41      | 0.34      |
  | M4 delta    | +6.9%     | +4.1%     |
  | 30fps mixed | 7.2x      | 20.3x     |
  | Verdict     | GO QPU    | GO QPU    |

NEW finding (Phase 9 lesson): NEON gets faster per edge as filter
width grows (20.7 → 19.1 ns wd=4 → wd=8). The relative QPU loss
grows with width. wd=16 would probably flip negative based on the
trend line.

Deployment recipe with cycle 4:

  IDCT 8x8 (k1)     -> QPU   (R=0.92, +7% mixed)
  LPF wd=4 (k2)     -> QPU   (R=0.41, +7% mixed)
  LPF wd=8 (k4)     -> QPU   (R=0.34, +4% mixed)
  MC 8h (k3)        -> CPU   (R=0.067, -19% mixed)
  Entropy           -> CPU   (structural)

VP9 inner-edge LPF coverage complete. Project continues to higgs
deployment plumbing or further kernels per user direction.

New artifacts:
- src/v3d_lpf_h_8_8.comp                 — GLSL shader
- tests/vp9_lpf8_ref.c                   — standalone C ref
- tests/bench_neon_lpf8.c                — M1+M3 bench
- tests/bench_v3d_lpf8.c                 — M1+M2 bench
- tests/bench_concurrent_lpf8.c          — M4 pthread bench
- docs/k4_lpf8_phase1_3.md + phase4_7.md — combined cycle docs

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 12:56:25 +00:00
parent 356e446a49
commit 85feba4087
8 changed files with 1106 additions and 1 deletions
+150
View File
@@ -0,0 +1,150 @@
/*
* Cycle 4 Phase 3 — NEON M3'''' baseline for VP9 8-tap inner LPF wd=8
* (horizontal direction, 8-pixel edge).
*
* Same harness shape as bench_neon_lpf.c (cycle 2); the only changes
* are calling ff_vp9_loop_filter_h_8_8_neon + the wd=8 C reference.
*
* License: LGPL-2.1+ (links FFmpeg NEON snapshot).
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
extern void daedalus_vp9_loop_filter_h_8_8_ref(
uint8_t *dst, ptrdiff_t stride, int E, int I, int H);
extern void ff_vp9_loop_filter_h_8_8_neon(
uint8_t *dst, ptrdiff_t stride, int E, int I, int H);
static uint64_t xs_state;
static inline uint64_t xs(void) {
uint64_t x = xs_state;
x ^= x << 13; x ^= x >> 7; x ^= x << 17;
return xs_state = x;
}
#define EDGE_W 8
#define EDGE_H 8
#define EDGE_STRIDE 8
#define EDGE_BYTES (EDGE_H * EDGE_STRIDE)
static void gen_edge_pixels(uint8_t *buf)
{
int side_a = (int)(xs() % 200) + 20;
int side_b = (int)(xs() % 200) + 20;
int noise = (int)(xs() % 30);
for (int r = 0; r < EDGE_H; r++)
for (int c = 0; c < EDGE_W; c++) {
int base = (c < 4) ? side_a : side_b;
int n = ((int)(xs() % (2 * noise + 1))) - noise;
int v = base + n;
buf[r * EDGE_STRIDE + c] = (uint8_t)(v < 0 ? 0 : v > 255 ? 255 : v);
}
}
static void gen_thresholds(int *E, int *I, int *H) {
*E = (int)(xs() % 81);
*I = (int)(xs() % 41);
*H = (int)(xs() % 11);
}
static double now_seconds(void) {
struct timespec ts; clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
return ts.tv_sec + ts.tv_nsec * 1e-9;
}
static int correctness_check(uint64_t seed, int n)
{
xs_state = seed ? seed : 0xa57edbeef5717ULL;
int mis = 0;
uint8_t a[EDGE_BYTES], b[EDGE_BYTES];
for (int i = 0; i < n; i++) {
gen_edge_pixels(a);
memcpy(b, a, EDGE_BYTES);
int E, I, H; gen_thresholds(&E, &I, &H);
daedalus_vp9_loop_filter_h_8_8_ref(a + 4, EDGE_STRIDE, E, I, H);
ff_vp9_loop_filter_h_8_8_neon (b + 4, EDGE_STRIDE, E, I, H);
if (memcmp(a, b, EDGE_BYTES) != 0) {
if (mis < 3) fprintf(stderr, "MISMATCH edge %d E=%d I=%d H=%d\n", i, E, I, H);
mis++;
}
}
printf("M1''''_c correctness: %d / %d edges bit-exact (%.4f%%)\n",
n - mis, n, 100.0 * (n - mis) / n);
return mis;
}
static void throughput(uint64_t seed, int n_edges, double duration)
{
xs_state = seed ? seed : 0xa57edfeed5170ULL;
uint8_t *master = malloc((size_t) n_edges * EDGE_BYTES);
uint8_t *work = malloc((size_t) n_edges * EDGE_BYTES);
int *Es = malloc(n_edges*sizeof(int)), *Is = malloc(n_edges*sizeof(int)), *Hs = malloc(n_edges*sizeof(int));
for (int i = 0; i < n_edges; i++) {
gen_edge_pixels(master + (size_t)i * EDGE_BYTES);
gen_thresholds(&Es[i], &Is[i], &Hs[i]);
}
memcpy(work, master, (size_t) n_edges * EDGE_BYTES);
for (int i = 0; i < n_edges; i++)
ff_vp9_loop_filter_h_8_8_neon(work + (size_t)i * EDGE_BYTES + 4, EDGE_STRIDE, Es[i], Is[i], Hs[i]);
double t0 = now_seconds(), tend = t0 + duration;
uint64_t done = 0;
while (now_seconds() < tend) {
memcpy(work, master, (size_t) n_edges * EDGE_BYTES);
for (int i = 0; i < n_edges; i++)
ff_vp9_loop_filter_h_8_8_neon(work + (size_t)i * EDGE_BYTES + 4, EDGE_STRIDE, Es[i], Is[i], Hs[i]);
done += n_edges;
}
double el = now_seconds() - t0;
int it = (int)(done / n_edges);
double s0 = now_seconds();
for (int i = 0; i < it; i++) memcpy(work, master, (size_t) n_edges * EDGE_BYTES);
double s1 = now_seconds();
double ks = el - (s1 - s0);
double mes = done / ks / 1e6;
printf("M3'''' NEON throughput:\n");
printf(" edges/batch: %d\n", n_edges);
printf(" total edges: %llu\n", (unsigned long long) done);
printf(" elapsed (kernel)=%.6f s\n", ks);
printf(" throughput = %.3f Medge/s\n", mes);
printf(" per-edge = %.1f ns\n", ks / done * 1e9);
printf(" equiv 1080p = %.1f FPS (~64530 edges/frame, worst case)\n",
mes * 1e6 / 64530.0);
free(master); free(work); free(Es); free(Is); free(Hs);
}
int main(int argc, char **argv)
{
int n_edges = 65536;
double duration = 5.0;
uint64_t seed = 0;
int do_corr = 1;
static struct option opts[] = {
{"edges", required_argument, 0, 'e'},
{"duration", required_argument, 0, 'd'},
{"seed", required_argument, 0, 's'},
{"no-correctness", no_argument, 0, 'C'},
{0,0,0,0}
};
for (int c; (c = getopt_long(argc, argv, "e:d:s:C", opts, 0)) != -1;) {
switch (c) {
case 'e': n_edges = atoi(optarg); break;
case 'd': duration = atof(optarg); break;
case 's': seed = strtoull(optarg, 0, 0); break;
case 'C': do_corr = 0; break;
default: return 2;
}
}
if (do_corr) {
printf("=== M1''''_c bit-exact (10000 random edges) ===\n");
if (correctness_check(seed, 10000) != 0) return 1;
printf("\n");
}
printf("=== M3'''' NEON throughput ===\n");
throughput(seed, n_edges, duration);
return 0;
}