Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion optimized_inference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ foreach(pair IN ITEMS "dpdfnet_train;tools/train.c" "dpdfnet_benchmark;benchmark
endforeach()
include(CTest)
if(BUILD_TESTING)
# Compare batched quantization directly with the ordered per-row algorithm.
# Private implementation is included only in this standalone oracle target.
add_executable(quantize4_contract tests/quantize4_contract.c)
target_include_directories(quantize4_contract PRIVATE include src/private)
target_compile_definitions(quantize4_contract PRIVATE DPDF_MODEL_SIZE=2 DPDF_X86_DISPATCH)
target_compile_options(quantize4_contract PRIVATE -mavx2 -mfma -frounding-math)
target_link_libraries(quantize4_contract PRIVATE m)
dpdf_compile(quantize4_contract)
add_test(NAME quantize4_contract COMMAND quantize4_contract)
add_executable(public_contract tests/public_contract.c)
target_link_libraries(public_contract PRIVATE dpdfnet m)
dpdf_compile(public_contract)
Expand All @@ -158,7 +167,7 @@ if(BUILD_TESTING)
"${CMAKE_CURRENT_SOURCE_DIR}/models/dpdfnet8_48khz_hr/weights.f32")
foreach(size IN ITEMS 2 8)
foreach(test IN ITEMS full_contract extended_contract layout_contract generated_gru_contract
conv_helpers_contract depthwise_contract int8_contract int8_dispatch_contract fused_contract pair_contract)
conv_helpers_contract depthwise_contract int8_contract int8_dispatch_contract fused_contract pair_contract cm_contract)
set(target "model${size}_${test}")
add_executable(${target} tests/${test}.c $<TARGET_OBJECTS:backend${size}>)
target_include_directories(${target} PRIVATE include src src/private)
Expand All @@ -174,6 +183,9 @@ if(BUILD_TESTING)
endif()
dpdf_compile(${target})
add_test(NAME ${target} COMMAND ${target} "${CMAKE_CURRENT_SOURCE_DIR}/models/dpdfnet${size}_48khz_hr/weights.f32")
if(test STREQUAL "int8_contract" OR test STREQUAL "cm_contract")
set_tests_properties(${target} PROPERTIES SKIP_RETURN_CODE 77)
endif()
endforeach()
endforeach()
# Scalar reference must retain its ordered multiply/add operations.
Expand Down
10 changes: 6 additions & 4 deletions optimized_inference/benchmarks/kernels.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ int main(int argc,char **argv) {
if(iterations<100 || iterations>10000000) return 2;
int kind=-1;
const char *names[]={"depthwise2","depthwise3","pair40","pair48","batch40","row64",
"gates1","gates40","gates48","norm40","transpose"};
for(int i=0;i<11;++i) if(!strcmp(argv[1],names[i])) kind=i;
"gates1","gates40","gates48","norm40","transpose","matrix128"};
for(int i=0;i<12;++i) if(!strcmp(argv[1],names[i])) kind=i;
if(kind<0) return 2;
const size_t count=64*480;
float *x=malloc(count*sizeof(float)),*b=malloc(count*sizeof(float));
float *w=malloc(count*sizeof(float)),*y=malloc(count*sizeof(float)),*z=malloc(count*sizeof(float));
if(!x||!b||!w||!y||!z) return 2;
for(size_t i=0;i<count;++i){x[i]=sample();b[i]=sample();w[i]=sample();y[i]=0;z[i]=0;}
dpdf_qmatrix *q0=dpdf_qcreate(w,64,192),*q1=dpdf_qcreate(w+64*192,64,192);
if(!q0||!q1) return 2;
dpdf_qmatrix *q128=dpdf_qcreate(w,128,64);
if(!q0||!q1||!q128) return 2;
int64_t start=0,cpu_start=0,warm_deadline=ns(CLOCK_MONOTONIC)+INT64_C(100000000);
for(int i=-1000;i<iterations;++i) {
if(i==0 && ns(CLOCK_MONOTONIC)<warm_deadline) i=-1000;
Expand All @@ -53,13 +54,14 @@ int main(int argc,char **argv) {
case 6: case 7: case 8: dpdf_gates_avx2(x,b,w,y,kind==6?1:kind==7?40:48); break;
case 9: dpdf_norm_residual_avx2(y,x,b,w,w+64,1e-5f,40); break;
case 10: dpdf_transpose_avx2(x,y,64,48); break;
case 11: dpdf_qaffine(q128,x,b,y,40); break;
}
}
int64_t elapsed=ns(CLOCK_MONOTONIC)-start,cpu=ns(CLOCK_THREAD_CPUTIME_ID)-cpu_start;
uint32_t checksum=0;
for(size_t i=0;i<count;++i){uint32_t value;memcpy(&value,y+i,4);checksum=checksum*33+value;}
printf("{\"kernel\":\"%s\",\"iterations\":%d,\"mean_ms\":%.12f,\"cpu_ms\":%.12f,\"checksum\":%u,\"measurement\":\"hot-cache amortized call time, not per-call latency\"}\n",
names[kind],iterations,(double)elapsed/iterations/1e6,(double)cpu/iterations/1e6,checksum);
dpdf_qdestroy(q0);dpdf_qdestroy(q1);free(x);free(b);free(w);free(y);free(z);
dpdf_qdestroy(q0);dpdf_qdestroy(q1);dpdf_qdestroy(q128);free(x);free(b);free(w);free(y);free(z);
return 0;
}
109 changes: 109 additions & 0 deletions optimized_inference/docs/PERFORMANCE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Performance, memory and output quality

Latest verification (2026-11-08): a direct cumulative comparison from `afa8292` (before the three i7 optimization stages) to `cf16ba6` measures the combined result without adding historical component percentages. Continuous/performance time reductions are 11.948% / 9.019% for models 2 / 8; throughput increases are 13.569% / 9.913%. See [the direct cumulative study](#direct-cumulative-comparison-2026-11-08) for original-power results, SD/SE and adjusted intervals, and [portable evidence](https://github.com/varyagnord/DPDFNet/blob/41d0aa8f94fbd725f11b24a9b7482c17979d50e6/optimized_inference/validation/i7_7700t_total.json). Earlier incremental component measurements remain below.

The current defaults were selected separately for models 2 and 8 on an
Intel Core i7-7700T. The older i7-8700 latency/quality records below describe
the historical package baseline; they were not remeasured for these defaults.
Expand Down Expand Up @@ -351,3 +353,110 @@ the historic 65-file release corpus described above and does not add perceptual
quality scores. `tools/compare_streams.py` compares multiple library builds on
every spectrum and complete recurrent state at every hop, including in-place
buffers and reset replay. Keep these correctness jobs separate from timing.

## Four-row exact quantization follow-up (2026-11-07)

The AVX2 K64 batch and paired paths compute quantization parameters for four independent rows using packed exact division. Zero-range groups retain the previous per-row algorithm. The minimum remains AVX2/FMA; optional VNNI objects are byte-identical to baseline. Weights and ABI are unchanged.

| Model | Baseline ms | Candidate ms | Time reduction | Adjusted interval |
| --- | ---: | ---: | ---: | ---: |
| 2 | 0.747387 | 0.737902 | 1.274% | [0.132, 2.403]% |
| 8 | 1.827997 | 1.807429 | 1.128% | [0.480, 1.772]% |

Independent post-plan confirmation used 36 mirrored randomized blocks, two fresh processes per variant/block, 120 warmup and 500 timed hops, continuous neural calls, GCC14.2 PGO, performance governor/EPP, and an isolated physical i7-7700T core (CPU2 with sibling CPU6 reserved). The original screens did not pass their selection thresholds; the separately fixed follow-up and every screen are retained in the local evidence archive. The intervals use a family-four correction across two confirmations and two original-power guards.

At the original powersave/balance_performance policy with 10ms cadence, model2 improved by 4.338% (adjusted interval [0.464, 8.062]%), while model8 remained inconclusive at 1.081% ([-2.307, 4.357]%). These are scoped local results, not end-to-end audio or cross-CPU speedup claims.

Every spectrum and complete state matched baseline over 65 local EARS/stress streams (147,711 hops/model), including aliases/reset. The new direct quantization oracle covers 16,384 rounding/FTZ/DAZ cases and guard pages. PGO release, ASan/UBSan, AVX2-only, static and CPU-mask checks pass; six native VNNI contracts skip where that ISA is unavailable. No new perceptual quality scores are claimed. See [the portable result record](https://github.com/varyagnord/DPDFNet/blob/41d0aa8f94fbd725f11b24a9b7482c17979d50e6/optimized_inference/validation/i7_7700t_quantize4.json). Complete protocols, raw runs and logs are retained locally under `/home/varyagnord/reports/dpdfnet-opt-2026-11-07`.


## Model-8 original-power precision repeat (2026-11-08)

The exact `98df765`/`26c7a9c` binaries were compared again at the original
powersave/balance_performance policy and 10 ms cadence. The fixed design uses
288 balanced randomized ABBA/BAAB blocks, 1,152 fresh processes, 120 warmup and
250 timed hops per process: 288,000 timed hops, twelve times the earlier guard.
Frame indices and recurrent history match that guard. The stopped 96×750
workload-design pilot is archived separately and excluded; neither historical
data nor the pilot is pooled into the new estimate. No observations are removed.

| Model | Time reduction | Primary 95% interval | Paired log-ratio SD | SE of mean log ratio |
| --- | ---: | ---: | ---: | ---: |
| 8 | +0.4627% | [-0.3447, +1.2636]% | 0.06965684 | 0.00410457 |

The gain remains inconclusive in this power/cadence regime. Run means are
4.411520 ms (SD 0.387506) before and 4.393384 ms (SD 0.415042) after the change.
The paired arithmetic difference is 0.018136 ms, with SD 0.300840 ms, SE
0.017727 ms and 95% interval [-0.016756, +0.053027] ms. Pooled individual-hop SD
is 1.602747/1.604627 ms; this describes latency variation and is not the SE of
the mean effect. Complete blocks, rather than hops, are the statistical units.
Whole-block bootstrap, HAC lag 3 and moving-block bootstrap lengths 4/8 all retain
zero in their 95% intervals; balanced randomization p=0.26094. The old guard's
interval recomputed at the same 95% level is [-1.4950,+3.5917]%; the new interval
is 3.163 times narrower. Its historical family-four interval used 98.75%, so
comparing those different confidence levels directly would overstate precision.

All slow runs remain. Calls above 10 ms were 0/1 and late completions 0/3, before/
after; these few events do not establish a change in deadline-miss probability.
CPU 2 and sibling CPU 6 were reserved together as before. Ordinary work was
excluded from both; residual kernel/interrupt/package effects remain. Sampled
policy settings never changed, and CPU 6 user/nice counters did not advance.
Diagnostic monitoring began after the initial blocks. All isolation and power
settings were restored. See the [portable precision record](https://github.com/varyagnord/DPDFNet/blob/41d0aa8f94fbd725f11b24a9b7482c17979d50e6/optimized_inference/validation/i7_7700t_precision.json)
and local raw evidence under `/home/varyagnord/reports/dpdfnet-deep-2026-11-08`.

## Channel-major pointwise follow-up (2026-11-08)

The exact AVX2 K64×N64 pointwise path quantizes eight frequency positions directly from channel-major input and writes channel-major output with a register 4×8 transpose. It bypasses sixteen full float transposes per graph. Original min/max reduction, exact divisions, integer dot, correction/scaling/FMA and weights are retained. Other precision/shape/overlap/VNNI cases use the original chain. No new mandatory ISA is introduced.

| Model | Baseline mean ± run SD, ms | Final mean ± run SD, ms | Time reduction | Adjusted interval |
| --- | ---: | ---: | ---: | ---: |
| 2 | 0.724998 ± 0.009977 | 0.682770 ± 0.007971 | 5.823% | [5.222, 6.421]% |
| 8 | 1.716139 ± 0.015128 | 1.661071 ± 0.014034 | 3.209% | [2.709, 3.707]% |

Independent confirmation: 36 mirrored randomized blocks, 120 warmup and 750 timed hops per fresh process, continuous calls, performance governor/EPP, unchanged 800–3800 MHz bounds, GCC 14.2 PGO, physical CPU 2+6 reserved and workers only CPU 2. Family-eight intervals include confirmation/guards and reserved final-integration checks; discovery uses family twenty. All runs and negative outcomes remain. These percentages compare with `26c7a9c`; do not add historical gains.

| Model | Original-power paced time reduction | Adjusted interval | Confirmed |
| --- | ---: | ---: | --- |
| 2 | 5.482% | [1.077, 9.690]% | yes |
| 8 | 0.793% | [-0.453, 2.023]% | no |

The initial power guards use 24 blocks, 250 timed hops and 10 ms cadence. A separately fixed independent 288-block original-power model-8 repeat uses the final library; it is not pooled with its initial guard and replaces one reserved final guard within the unchanged family-eight budget. The larger model-8 quantize4 precision repeat above concerns a different code contrast. Neither power regime establishes cross-CPU or whole-audio-chain speedups.

Other screened layout/K128/depth-specialization candidates did not establish a gain; two profile-motivated entry-prefetch variants regressed both models. The first layout-in prototype failed the decoder-skip regression before timing. The initial CM intrinsics prototype had two accumulator spills per K step; a fixed AVX2 register schedule removes those hot-loop accesses, with all correctness checks repeated before screening. None of these untimed refinements is presented as an independently timed component gain.

Every spectrum and complete state matched on 65 local streams / 147,711 hops per model. Final contracts include 2,688 direct CM cases per model, scalar INT8 oracle with read-only guarded packing over 16 rounding/FTZ/DAZ modes, and byte-for-byte full graph parity across FP32/FP16/INT8 × all 16 masks × eight frames. Release/ASan-UBSan/AVX2-only/static and CPU-mask checks pass. Ten VNNI objects match baseline byte-for-byte; native VNNI execution/speed remains unavailable here. Seven public exports, libc/libm-only release dependencies, state ABI and owned heap are preserved. Measured/final identity or separate final confirmation is recorded. All isolation settings are restored. See the [portable deep result](https://github.com/varyagnord/DPDFNet/blob/41d0aa8f94fbd725f11b24a9b7482c17979d50e6/optimized_inference/validation/i7_7700t_deep.json).

## Direct cumulative comparison (2026-11-08)

This new fixed-count study directly compares `afa8292f3b8083c3daadd06dbcfe4ff877dd3172` with `cf16ba6f0e0332f65b689c6732ece60066dbefe6`. It covers GV/GVBSJ, four-row quantization and channel-major pointwise together. The baseline already includes the earlier W7A8/AVX2 runtime and optional VNNI; it is not the original PyTorch FP32 model. No component percentages or historical measurements are pooled.

| Policy / cadence | Model | Baseline mean ± run SD, ms | Final mean ± run SD, ms | Time reduction (98.75% CI) | Throughput increase (98.75% CI) |
| --- | --- | ---: | ---: | ---: | ---: |
| performance / continuous | 2 | 0.775668 ± 0.010495 | 0.682981 ± 0.008152 | +11.948% [+11.784, +12.112]% | +13.569% [+13.358, +13.781]% |
| performance / continuous | 8 | 1.823240 ± 0.020046 | 1.658830 ± 0.022045 | +9.019% [+8.830, +9.207]% | +9.913% [+9.685, +10.141]% |
| original / 10 ms | 2 | 3.310288 ± 0.195274 | 2.884951 ± 0.188570 | +12.881% [+12.052, +13.702]% | +14.786% [+13.704, +15.878]% |
| original / 10 ms | 8 | 4.667054 ± 0.288936 | 4.668449 ± 0.333109 | +0.009% [-0.947, +0.955]% | +0.009% [-0.938, +0.965]% |

Each model/policy cell uses 288 randomized ABBA/BAAB blocks, four fresh processes per block, 576 runs per version. Six fixed recorded inputs `original-00..05` have equal weight, 48 blocks/input and 24 orders of each type. Models are interleaved in randomized balanced round order. Every process has 120 warmup hops, followed by 600 continuous timed hops under performance governor/EPP or 250 paced timed hops at the saved powersave/balance_performance policy, with unchanged 800–3800 MHz bounds. The timed frame history matches between versions and never wraps. There are 4,608 main processes / 1,958,400 timed calls. Separate 24-block A/A controls in all four cells run before any main outcomes; all pass the fixed conditional-randomization gate. Including controls: 4,992 processes / 2,121,600 timed calls, excluding warmup, tests, training and trace probes.

The statistical unit is the complete four-process block. The primary estimator averages block log ratios with equal input weights; SE uses within-input variances and a Welch–Satterthwaite t interval. The four aggregate model/policy contrasts use individual 98.75% intervals and Bonferroni-adjusted randomization p-values, giving at least 95% family coverage under the stated assumptions. Time reduction `100*(1-r)` and throughput increase `100*(1/r-1)` transform the same ratio and interval; they are different quantities. The arithmetic mean ± sample run SD above describes the run distribution and can differ slightly from the paired geometric effect.

| Policy | Model | Paired difference mean, ms | Paired difference SD, ms | Stratified SE, ms | Log-ratio SD | Log-ratio SE |
| --- | --- | ---: | ---: | ---: | ---: | ---: |
| performance | 2 | 0.092687034 | 0.009311757 | 0.000550102 | 0.012546789 | 0.000741050 |
| performance | 8 | 0.164409731 | 0.024457542 | 0.001443593 | 0.013932929 | 0.000822406 |
| original | 2 | 0.425336912 | 0.184138090 | 0.010777615 | 0.064322660 | 0.003764199 |
| original | 8 | -0.001394759 | 0.298459584 | 0.017594557 | 0.064176725 | 0.003783676 |

The original-power model-8 A/A control has a +2.996% point estimate and a t interval [0.115, 5.794]% excluding zero. Its conditional randomization raw p=0.02723 (adjusted p=0.10892) does not reach the prespecified halt threshold 0.0125; the gate passes according to that fixed rule. This discrepancy is retained explicitly. A/A is not subtracted as a fixed bias correction, and the main sample size is unchanged. Controls have only four blocks/input, versus 48 in each main cell.

All slow runs remain, with no effect-based stopping or historical pooling. Secondary checks include 20,000 stratified whole-block bootstrap resamples, HAC lag 3, and 20,000 circular chronological residual-block resamples at lengths 4 and 8 after removing input effects; per-input and chronological-quarter effects are descriptive. Conditional randomization uses 100,000 balanced within-input assignments and the +1 correction. Individual-hop samples and pooled SD/p99/max/deadline statistics are preserved separately; individual hops are not counted as independent replications. Full numeric intervals, heterogeneity and sensitivity results are in the portable record.

Both pinned revisions were rebuilt with GCC 14.2 and independently trained identical model-8 PGO streams (4,000 hops). Both resulting shared libraries match their corresponding archived binaries byte-for-byte; the final SO SHA256 is `d52b21267579dc3a75c22c35dc13a3d55bb3e68ddc1300ec568110c45f26c80a`. One byte-identical measurement executable resolves its own library through `$ORIGIN` in both directories. All input/weight and raw-sample hashes are checked. Baseline Release tests pass 21 / skip 6 VNNI; final tests pass 31 / skip 6. Fresh direct comparisons match every spectrum and complete state bitwise on 65 streams / 147,711 hops per model, including aliases, reset and canaries. No inference code changed for this study.

CPU 2 and its HT sibling CPU 6 were reserved together as a cgroup v2 isolated partition; workers ran only on CPU 2 with UID 1000 and zero capabilities. Ordinary work was excluded from both logical CPUs, with movable IRQ/workqueues/watchdog steered away. All sampled policies and cpuset settings match the fixed condition; CPU 6 user/nice counters do not advance over the monitored intervals. Independent scheduler traces show only idle/bound kernel work on CPU 6. Residual bound kernel, interrupt, firmware and package effects remain. Every phase restored all saved settings, removed its cgroup and stopped the independent recovery timer. Telemetry did not select or exclude observations.

These intervals concern repeated measurements on this CPU and six fixed inputs. The conditions differ in cadence, power policy and timed length, so their difference is not solely a governor effect. They do not establish cross-CPU performance or whole audio-pipeline acceleration. FFT, synthesis, I/O and model creation are excluded. AVX2+FMA remains the minimum; optional VNNI execution/speed is unavailable on this host.

See [portable results and integrity](https://github.com/varyagnord/DPDFNet/blob/41d0aa8f94fbd725f11b24a9b7482c17979d50e6/optimized_inference/validation/i7_7700t_total.json), [all paired block observations](https://github.com/varyagnord/DPDFNet/blob/41d0aa8f94fbd725f11b24a9b7482c17979d50e6/optimized_inference/validation/i7_7700t_total_blocks.json).
Loading
Loading