Skip to content

AVX-512 register-permute gather in compute_ideal_weights_for_decimation - #683

Closed
karthick-mcw wants to merge 1 commit into
ARM-software:mainfrom
karthick-mcw:perf/avx512-permute-gather-main
Closed

karthick-mcw wants to merge 1 commit into
ARM-software:mainfrom
karthick-mcw:perf/avx512-permute-gather-main

Conversation

@karthick-mcw

Copy link
Copy Markdown

Summary

AVX-512 register-permute gather for compute_ideal_weights_for_decimation.

The initial-average and refine loops gather ei.weights / ei.weight_error_scale / infilled_weights per texel. The hardware vgatherdps used for this is microcoded and load-latency bound on Zen 5. For texel_count <= 48 (blocks up to 6x6, the size this workload uses) the whole lookup table fits in 3 zmm registers, so the gather is done as an in-register permute (vpermt2ps + vpermps) instead, with no memory access. Larger blocks (e.g. 8x8 = 64 texels) exceed register residency and fall back to the existing AVX2 gather path, unchanged.

The result is bit-identical: it's the same elements, fetched a different way. Adds a self-contained runtime AVX-512F check, since an AVX2 build of this library can still run on a host without AVX-512F — the new path is only taken when both the block is small enough and the host actually supports it.

Files: Source/astcenc_ideal_endpoints_and_weights.cpp

Measured

Asset compression workload, gain in % (positive means faster).

Vendor CPU OS Compiler Single thread All threads
AMD Granite 9600 Windows clang-cl 6.03 6.78
Intel Arrow Lake Windows clang-cl -0.14 0.21
Apple Mac Air macOS AppleClang 0 0.2

(Mac Air has no AVX-512, so this change is a no-op there, as expected — the 0%/0.2% is noise. Arrow Lake's AVX-512 was disabled by Intel on this generation, so it also falls back to the AVX2 path.)

Test plan

  • Bit-identical output: 6 representative LDR/HDR textures x 6 block sizes (4x4-12x12) x 4 quality presets (144 runs), byte-identical .astc output with and without the patch, on a host without AVX-512F (exercises the unchanged AVX2 fallback path).
  • Unit test: astcenc C++ unit test suite (ctest, -DASTCENC_UNITTEST=ON), 223/223 tests pass on the patched build.
  • Functional tests: Test/astc_test_functional.py --encoder avx2 gives the identical result with and without the patch (38/93 pass; the remaining 55 error only on a missing ImageMagick dependency in this test environment, not on the code — zero assertion failures either way).
  • Timing: single core and all cores on all three machines (table above) — carried over from the original measurement; not independently re-verified in this environment.
  • Execution check of the AVX-512 permute path itself on AVX-512F hardware — not available in this environment (dev machine has no AVX-512F); only compile-checked and verified to build cleanly. Worth re-running the bit-identical diff on a Zen 5/AVX-512-capable host before merge.

…r_decimation

For texel_count <= 48 (blocks up to 6x6), the ei.weights /
ei.weight_error_scale / infilled_weights lookup tables are register
resident in 3 zmm registers, so the per-texel gather in the initial
average and refine loops can be done as an in-register permute
(vpermt2ps + vpermps) instead of a hardware vgatherdps, which is
microcoded and load-latency bound on Zen 5. Larger blocks fall back
to the existing AVX2 gather path. Output is bit-identical.

Adds a self-contained runtime AVX-512F check, since an AVX2 build of
this library can still run on a host without AVX-512F.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant