Skip to content

CI: Enable IPO for all Package builds - #2772

Closed
blowekamp wants to merge 8 commits into
SimpleITK:mainfrom
blowekamp:ci/package-python-ipo
Closed

blowekamp wants to merge 8 commits into
SimpleITK:mainfrom
blowekamp:ci/package-python-ipo

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Adds the SimpleITK_INTERPROCEDURAL_OPTIMIZATION option from #2766 (first commit) and enables it for all Package workflow builds (core, Python, Java, C#, manylinux and macOS/Windows scripts). Standalone language wrapper projects now include the IPO module so they link consistently with IPO-built libraries.

In Build.yml only mac-arm64-elastix-python uses IPO (links serialized via a Ninja job pool); the previous all-entries WIP is dropped. Note mac-arm64-superbuild uses build type RelMinSize, which is not a CMake config, so IPO would not apply there.

Supersedes the WIP CI commit of #2766. CI results pending.

blowekamp and others added 6 commits October 26, 2026 19:52
Add an option, default OFF, to enable interprocedural optimization (LTO)
for Release, RelWithDebInfo and MinSizeRel builds. Support is verified
with check_ipo_supported. The CMAKE_INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
variables are set before ITK is added so FetchContent builds of ITK use
them, and they are forwarded to the ITK, Elastix and SimpleITK projects
in the SuperBuild.
Enable SimpleITK_INTERPROCEDURAL_OPTIMIZATION for the core and the
Python, Java and C# wrapper builds in the Package workflow, including
the manylinux scripts. Standalone language projects include the IPO
module so wrappers link against IPO-built libraries consistently.

In Build.yml only mac-arm64-elastix-python enables IPO, with links
serialized by a Ninja job pool, to limit CI time.

Co-authored-by: Copilot <[email protected]>
Use Ninja with a serialized link pool for the manylinux SuperBuild, as
parallel IPO links got the runner killed. Leave IPO off for the Windows
core build, where MSVC hits an internal compiler error linking ITK's
itkTestDriver with link-time code generation.

Co-authored-by: Copilot <[email protected]>
Ninja defaults to more jobs than cores, which exhausted the memory of
the runner while compiling Elastix.

Co-authored-by: Copilot <[email protected]>
A single full IPO link of the Java wrapper had lto1 killed by the OOM
killer on the runner. Limit the parallelism of each link to two jobs
and use Ninja with a link job pool for the SuperBuild and all wrapper
builds.

Co-authored-by: Copilot <[email protected]>
The macOS core builds with IPO exceed the time limit of the hosted
runners, so only the Python wrappers use IPO there, as on Windows. The
GCC IPO link of the manylinux wrappers needs about 20GB of memory, which
exceeds the memory of the runners, so add swap space.

Co-authored-by: Copilot <[email protected]>
blowekamp and others added 2 commits October 27, 2026 12:14
Each IPO link of an example or unit test executable took minutes, and
the Python wrapper builds linked about 40 examples per wheel, which
exceeded the job time limit. The wheel only needs the module, so do not
build the SuperBuild unit tests or the examples of the wrapper builds.

Co-authored-by: Copilot <[email protected]>
The Java wrapper tests need sitkCompareDriver from the SuperBuild.

Co-authored-by: Copilot <[email protected]>
@blowekamp

Copy link
Copy Markdown
Member Author

The CMAKE_INTERPROCEDURAL_OPTIMIZATION_${_config} can be set with out having to add the custom SimpleITK CMake option. This feature decreases run time and can not be linked with the GH provided agents and will not be used.

@blowekamp blowekamp closed this Oct 30, 2026
hjmjohnson added a commit to BRAINSia/ITKPythonPackage that referenced this pull request Nov 19, 2026
Port of the SimpleITK_DEAD_STRIP option from SimpleITK
(SimpleITK/SimpleITK#2784, which followed the
link-time optimization study in
SimpleITK/SimpleITK#2772). On Linux it compiles
with -ffunction-sections -fdata-sections and links with gold
--gc-sections --icf=safe. Off by default; other platforms are unchanged.

A/B on ITK 957816d, manylinux_2_28 (GCC 14.2, gold 1.15), cp311 abi3:

  wheel                 off      on
  itk_core            89.5 MB  87.0 MB
  itk_filtering       89.3 MB  86.4 MB
  itk_filtering_extra 60.3 MB  57.8 MB
  itk_numerics        64.7 MB  62.9 MB

.text across the 96 wrapper modules fell 4.4%, against 15% in
SimpleITK: _ITKCommonPython exports 33,625 symbols from its statically
linked ITK libraries, and the linker must keep them all.
ITK already links its wrapper modules with -flto, so link cost barely
moved: the three largest modules, linked alone, took 1-4% longer and
used the same peak memory (9.05 GB for _ITKImageIntensityPython).

Seventeen Python cases gave bit-identical output in both arms;
BSpline/LBFGSB registration ran 5-7% slower, as it did in SimpleITK,
and the rest stayed within run-to-run noise.

ld64 -dead_strip changed the macOS arm64 wheels by under 0.1% and is
not applied there.
hjmjohnson added a commit to BRAINSia/ITKPythonPackage that referenced this pull request Nov 20, 2026
Port of the SimpleITK_DEAD_STRIP option from SimpleITK
(SimpleITK/SimpleITK#2784, which followed the
link-time optimization study in
SimpleITK/SimpleITK#2772). On Linux it compiles
with -ffunction-sections -fdata-sections and links with gold
--gc-sections --icf=safe. Off by default; other platforms are unchanged.

A/B on ITK 957816d, manylinux_2_28 (GCC 14.2, gold 1.15), cp311 abi3:

  wheel                 off      on
  itk_core            89.5 MB  87.0 MB
  itk_filtering       89.3 MB  86.4 MB
  itk_filtering_extra 60.3 MB  57.8 MB
  itk_numerics        64.7 MB  62.9 MB

.text across the 96 wrapper modules fell 4.4%, against 15% in
SimpleITK: _ITKCommonPython exports 33,625 symbols from its statically
linked ITK libraries, and the linker must keep them all.
ITK already links its wrapper modules with -flto, so link cost barely
moved: the three largest modules, linked alone, took 1-4% longer and
used the same peak memory (9.05 GB for _ITKImageIntensityPython).

Seventeen Python cases gave bit-identical output in both arms;
BSpline/LBFGSB registration ran 5-7% slower, as it did in SimpleITK,
and the rest stayed within run-to-run noise.

ld64 -dead_strip changed the macOS arm64 wheels by under 0.1% and is
not applied there.
hjmjohnson added a commit to BRAINSia/ITKPythonPackage that referenced this pull request Nov 20, 2026
Port of the SimpleITK_DEAD_STRIP option from SimpleITK
(SimpleITK/SimpleITK#2784, which followed the
link-time optimization study in
SimpleITK/SimpleITK#2772). On Linux it compiles
with -ffunction-sections -fdata-sections and links with gold
--gc-sections --icf=safe. Off by default; other platforms are unchanged.

A/B on ITK 957816d, manylinux_2_28 (GCC 14.2, gold 1.15), cp311 abi3:

  wheel                 off      on
  itk_core            89.5 MB  87.0 MB
  itk_filtering       89.3 MB  86.4 MB
  itk_filtering_extra 60.3 MB  57.8 MB
  itk_numerics        64.7 MB  62.9 MB

.text across the 96 wrapper modules fell 4.4%, against 15% in
SimpleITK: _ITKCommonPython exports 33,625 symbols from its statically
linked ITK libraries, and the linker must keep them all.
ITK already links its wrapper modules with -flto, so link cost barely
moved: the three largest modules, linked alone, took 1-4% longer and
used the same peak memory (9.05 GB for _ITKImageIntensityPython).

Seventeen Python cases gave bit-identical output in both arms;
BSpline/LBFGSB registration ran 5-7% slower, as it did in SimpleITK,
and the rest stayed within run-to-run noise.

ld64 -dead_strip changed the macOS arm64 wheels by under 0.1% and is
not applied there.
hjmjohnson added a commit to BRAINSia/ITKPythonPackage that referenced this pull request Nov 20, 2026
Port of the SimpleITK_DEAD_STRIP option from SimpleITK
(SimpleITK/SimpleITK#2784, which followed the
link-time optimization study in
SimpleITK/SimpleITK#2772). On Linux it compiles
with -ffunction-sections -fdata-sections and links with gold
--gc-sections --icf=safe. Off by default; other platforms are unchanged.

A/B on ITK 957816d, manylinux_2_28 (GCC 14.2, gold 1.15), cp311 abi3:

  wheel                 off      on
  itk_core            89.5 MB  87.0 MB
  itk_filtering       89.3 MB  86.4 MB
  itk_filtering_extra 60.3 MB  57.8 MB
  itk_numerics        64.7 MB  62.9 MB

.text across the 96 wrapper modules fell 4.4%, against 15% in
SimpleITK: _ITKCommonPython exports 33,625 symbols from its statically
linked ITK libraries, and the linker must keep them all.
ITK already links its wrapper modules with -flto, so link cost barely
moved: the three largest modules, linked alone, took 1-4% longer and
used the same peak memory (9.05 GB for _ITKImageIntensityPython).

Seventeen Python cases gave bit-identical output in both arms;
BSpline/LBFGSB registration ran 5-7% slower, as it did in SimpleITK,
and the rest stayed within run-to-run noise.

ld64 -dead_strip changed the macOS arm64 wheels by under 0.1% and is
not applied there.
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