Repository navigation
Description
adm_csf_mode=1 on the fixed-point adm extractor gives meaningless scores: the Barten weights do not fit the integer types they are stored in. The default (adm_csf_mode=0, Watson97) is not affected, and adm_csf_mode=2 / 3 show no overflow (see the end).
Reproducer (master cea2b4d8, release build, -Denable_float=true; Netflix src01_hrc00_576x324 / src01_hrc01_576x324, 8 bit 4:2:0, adm_csf_mode overloads are suffixed _csf_1 in the output):
meson setup build libvmaf --buildtype release -Denable_float=true
ninja -C build
build/tools/vmaf -r src01_hrc00_576x324.yuv -d src01_hrc01_576x324.yuv -w 576 -h 324 -p 420 -b 8 \
--feature adm=adm_csf_mode=1 --feature float_adm=adm_csf_mode=1 --threads 1 --json -o out.jsonPer frame, integer_adm2_csf_1 against the float extractor's adm2_csf_1 (the value the existing python/test/vmafexec_feature_extractor_test.py Barten test asserts, 0.965404 for frame 0):
| pair | frame 0 | frame 1 | frame 2 |
|---|---|---|---|
| src01 (48 frames) | 0.002706 / 0.965404 | 0.002310 / 0.955263 | NaN / 0.952795 |
| checkerboard 1 px (3 frames) | NaN / 0.783557 | NaN / 0.834682 | NaN / 0.784923 |
On src01, 15 of 48 frames are NaN; the other 33 lie between 0.0019 and 0.0028 (mean 0.0023, float mean 0.9396). integer_adm3_csf_1 is 0.50 or 0.0 against 0.98. The numerators are wrong while the denominators are right (frame 0: integer_adm_num_csf_1 392 against adm_num_csf_1 140010; integer_adm_den_csf_1 145040 against 145028). With --cpumask -1 (scalar code) it is just as wrong but differently: frame 0 gives 0.02692, no NaN. So the SIMD and scalar paths disagree with each other, and both disagree with float; it is not specific to one kernel. With adm_csf_mode=0 all of these agree with float to about 1e-5.
Cause. Watson97 weights are about 0.01, and the fixed-point code is sized for that. Barten weights with the default adm_csf_scale / adm_csf_diag_scale are about 1.2 at scale 0 (2.5386e6 / 2^21) and about 5 at scale 1 (2.16562e10 / 2^32).
- Scale 0 stores
i_rfactoras Q21 / Q23 inuint16_t:libvmaf/src/feature/integer_adm.c:1129-1131(adm_csf) and:1551-1553(adm_cm). The Q21 value is 2.5e6, which does not fit in 16 bits. - Scales 1 to 3 store Q32 in
uint32_t::1233-1235(i4_adm_csf) and:1949-1951(i4_adm_cm). That format only holds weights below 1.0; the value computed for scale 1 is 2.17e10 (about 5.0). - The contrast-masking reduction then multiplies and cubes the weighted band:
ADM_CM_ACCUM_ROUND(:688) andI4_ADM_CM_ACCUM_ROUND(:698) narrow the squared term toint32_t, which a weight above about 1 overflows. x86/adm_avx2.candx86/adm_avx512.crepeat the same casts.
Building with -Db_sanitize=address,undefined reports nothing, because float-cast-overflow is not part of undefined. With -Dc_args=-fsanitize=float-cast-overflow (and the same in c_link_args) the run above reports every cast listed (e.g. integer_adm.c:1129:48: runtime error: 2.5386e+06 is outside the range of representable values of type 'short unsigned int'). Those casts are undefined behaviour in C as well as wrong in value.
What a fix has to bound. Every Barten weight must be representable in the type it is stored in, and the sum in the cube accumulator must keep its headroom, without changing the arithmetic for weights that already fit (Watson97 output must stay bit-identical, at both the default CPU dispatch and with SIMD masked off). One workable way: per scale, pick one shared power-of-two exponent k that makes the three band weights fit (a shared one, because separate exponents would change the H/V/D ratios), divide the weights by 2^k, and subtract 3k from the divisor exponent where the cube is converted back. The SIMD kernels need the same change, or a fall back to the scalar path when k > 0. That touches the four scalar functions and their AVX2 / AVX-512 twins, so I did not want to send it without asking how you would like it done. The alternative of rejecting out-of-range weights at init with -EINVAL is a few lines, but leaves the option unusable at its default scales.
Other observations, not verified further: nothing in python/test runs adm_csf_mode=1 against the integer extractor (the Barten tests use float_ADM), and libvmaf/test/test_barten_csf.c only covers the CSF formulas, not the fixed-point pipeline. The option was added to the integer extractor in 966be8d ("libvmaf/feature: port adm updates"); adm_csf_mode=2 is what the shipped vmaf_v1.0.16* models use.
Update (2026-10-09): this change is maintained in VMAFx/vmafx; no separate PR will follow here.
Activity
Shakhtar-Sankur commentedon Nov 21, 2026
Opened #1734 with the shared-exponent approach described above, with a C fallback when the weights need scaling, so the SIMD kernels are unchanged.