InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

PERF: Quantify `-mprefer-vector-width=256` as a required companion to `-march=x86-64-v4`

Open
#6,745 1 comment 0 reactions 0 assignees View on GitHub
type:Infrastructure type:Performance
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

`CMake/ITKSetStandardCompilerFlags.cmake:163-172` advises users on AVX-512
hardware to add `-mprefer-vector-width=256`, but that advice is unquantified and
the two issues it cites (#2634, #1939) are both closed. Local benchmarks suggest
the advice is correct and should be promoted to documented, measured guidance.

Measured evidence — Sapphire Rapids Resample sweep

Host: Intel Xeon w7-3545 (Sapphire Rapids), GCC 13.3. Four-config Resample
benchmark sweep:

| Variant | `-march=x86-64-v4` vs baseline |
|---|---|
| Affine-only | **+17% to +20%** |
| BSpline-dominated | **−12% to −17%** |

The regression is not localized to one hot function. The v4 build emits
**53,063 zmm instructions across 4,977 functions**, versus 162 zmm instructions
at baseline. That breadth keeps the CPU in the AVX-512 license-throttled P-state
essentially all the time (throttle persistence measured at ~670 µs after the
last wide instruction). BSpline `TransformPoint` is memory-latency-bound, so
wider vectors buy it nothing while the lower clock costs it directly.

Proposed work

1. Re-run the sweep with `-march=x86-64-v4 -mprefer-vector-width=256`.
Hypothesis: recovers the Affine speedup without the BSpline regression.
2. Repeat on at least one non-Intel AVX-512 part (Zen 4/5, which has no
license-based frequency throttle) to determine whether the guidance is
Intel-specific or universal.
3. Survey whether **any** ITK kernel family measurably benefits from 512-bit
width. If none does, promote the CMake comment to explicit documentation
that `-mprefer-vector-width=256` should always accompany `-march=x86-64-v4`,
and update `CMake/ITKSetStandardCompilerFlags.cmake` to say so with the
measurement attached.

Note that ITK sets no architecture flags by default; this is guidance for
downstream builders and packagers, not a default-behavior change.

Why the referenced issues are dead

- #2634 — CLOSED 2026-04-13.
- #1939 — CLOSED 2020-10-20.
- #6039 (PR) — closed, superseded by merged #6049 ("COMP: Remove hardcoded
`-march=corei7`, `-mtune=generic`, and dead code"). The `ITK_X86_64_ISA_LEVEL`
option that PR proposed does not exist on `main`.

So the CMake comment currently points readers at three dead references.

Contributor guide

Open the contributing guide

Research direction

Start with CMake/ITKSetStandardCompilerFlags.cmake:163-172 and the cited closed issues, then reproduce the four-configuration Resample sweep with -march=x86-64-v4 -mprefer-vector-width=256. Repeat on a non-Intel AVX-512 system and survey ITK kernel families for width benefits; done means measured guidance is established and the CMake comment is updated with evidence and current references.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, documentation, performance
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.