Skip to content

perf(build): compile the release for x86-64-v3 (AVX2) - #43

Merged
SMI-Lab-Inha merged 1 commit into
devfrom
perf/avx2-target
Oct 22, 2026
Merged

SMI-Lab-Inha merged 1 commit into
devfrom
perf/avx2-target

Conversation

@SMI-Lab-Inha

Copy link
Copy Markdown
Owner

Summary

First item of the speed programme before 0.3.0.

The problem. Profiling the release driver (IFX, static) on the benchmark decks put the largest share in the vectorised cos/sin/exp of the wave kinematics: 24 % of lazy_wave_vessel_rao and 37 % of als_volturnus_line_break_time. The element kernels came next. The release build targets baseline x86-64, so this vector maths ran only two doubles wide (SSE2).

What changes:

  • CABLEDYN_TARGET_AVX2 (CMake option, default OFF) compiles the Fortran core for x86-64-v3 (Intel Haswell and AMD Excavator or newer):
    • IFX: /arch:CORE-AVX2 /Qfma-. The /arch form is the vendor-neutral one; /Qx gave the same code and speed here.
    • gfortran 11+: -march=x86-64-v3 -ffp-contract=off.
    • The static Windows release turns it on.
  • FMA contraction stays off. With it, the compiler fuses the same expression differently where it is inlined. A restored instance then no longer continued the run bit for bit (test_line_attachments failed with gfortran x86-64-v3). Contraction was worth only 2–5 % more speed.
  • Start-up processor check (src/cabledyn_cpu_guard.c):
    • It is compiled for baseline x86-64 and runs as a CRT initializer (MSVC) or constructor (GNU), before any Fortran code.
    • On a processor or OS without x86-64-v3 it writes the missing instructions to stderr and exits with status 3. Without it, the program would crash at the first AVX2 instruction with no explanation.
    • It uses only operating-system calls. In the Windows GNU build, C library names such as fprintf resolved to openblas.dll's exports and imported it at load time, which defeated the run-time BLAS loading.
    • Setting CABLEDYN_CPU_GUARD_SIMULATE exercises the stop on any processor.
  • Identification: CableDyn_driver --version prints the build line (x86-64-v3 (AVX2) or baseline). The OpenFAST module prints CableDyn build: x86-64-v3 (AVX2). at initialisation. These references also keep the check in the static links.
  • Release script: builds the reference LAPACK with /arch:CORE-AVX2. It requires both executables to report the x86-64-v3 build, and to stop with exit 3 and the message under the simulated missing feature.
  • Docs: processor requirement in doc/installation.rst and the README asset table; the option in DEVELOPMENT.md; CHANGELOG entry.

Speed (IFX static release configuration, this workstation, mean of two runs)

Deck dev this PR change
lazy_wave_vessel_rao 11.9 s 8.8 s −26 %
buoy_clamped_cable 2.11 s 1.83 s −13 %
als_volturnus_line_break_time 35.5 s 23.9 s −33 %

Result changes (round-off)

Deck Largest change, relative to the channel's range
lazy_wave_vessel_rao 3.0e-7 (last printed digit)
buoy_clamped_cable 7.4e-7 (last printed digit)
als_volturnus_line_break_time identical traces until about 900 s; after that, the platform's slow drift following the line break at 300 s amplifies the round-off

On the line-break deck, statistics over the whole run match dev:

Channel Max, dev Max, this PR Std, dev Std, this PR
AnchTen2 1.9177e6 1.9177e6 2.9901e5 2.9902e5
FairTen3 1.2722e7 1.2723e7 1.1631e6 1.1631e6
Body1Rz 4.5699 4.5699 1.4069 1.4068

Verification

  • Default build (Windows, gfortran, Release, slow tier included):
    • ctest 297/297;
    • pytest 2051 passed;
    • pre-commit run --all-files and the Sphinx -W build pass.
  • -DCABLEDYN_TARGET_AVX2=ON build (gfortran, x86-64-v3): ctest 298/298, including cpu_guard and the end-to-end cpu_guard_stop. libcabledyn.dll imports no openblas.dll.
  • IFX static release configuration:
    • --version reports x86-64-v3 (AVX2);
    • with CABLEDYN_CPU_GUARD_SIMULATE the driver prints the message and exits 3 before the banner.
  • OpenFAST (gfortran, CMake integration): builds with the module change, and a 2 s coupled IEA-15 MW CompMooring = 5 run terminates normally.

Checklist

  • pre-commit run --all-files passes
  • ctest --test-dir build --output-on-failure passes
  • python -m pytest tests python/tests passes (if Python or validation records changed)
  • VALIDATION.md updated if a validation result changed (round-off only; recorded above)
  • CHANGELOG.md updated under [Unreleased] (heading added if missing) for user-visible changes
  • Documentation in doc/ updated for changed inputs, options, or outputs
  • Conventional Commit title (feat:, fix:, docs:, ...)
  • Commits are signed off (git commit -s) under the
    Developer Certificate of Origin

The wave kinematics and the element kernels spend most of their time in
vectorised cos/sin/exp, which the release build ran two doubles wide
(SSE2). CABLEDYN_TARGET_AVX2 compiles the Fortran core for x86-64-v3
(/arch:CORE-AVX2 with IFX, -march=x86-64-v3 with gfortran 11+), and the
static Windows release sets it: the IFX driver runs the benchmark decks
13-33% faster (lazy_wave_vessel_rao 11.9 s to 8.8 s,
als_volturnus_line_break_time 35.5 s to 23.9 s).

Contraction into fused multiply-adds stays off (/Qfma-,
-ffp-contract=off): with it the compiler fuses the same expression
differently where it is inlined, and a restored instance no longer
continued a run bit for bit (test_line_attachments).

src/cabledyn_cpu_guard.c, compiled for baseline x86-64, checks the
processor before any Fortran code runs and stops a program on an older
one with a message naming the missing instructions (exit 3). It writes
with the operating system's calls only: in the Windows GNU build the C
library names can resolve to openblas.dll's exports and import it at
load time. CABLEDYN_CPU_GUARD_SIMULATE exercises the stop on any
processor; the release script checks it for both executables, and the
driver's --version and the OpenFAST module's start-up lines report the
x86-64-v3 build.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T06:41:14.364386Z 7b6c2cf Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 7b6c2cf390

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 CableDyn | 🛠️ Build #35317412 | 📁 Comparing 7b6c2cf against latest (d3ddfeb)

  🔍 Preview build  

10 files changed · ± 10 modified

± Modified

@SMI-Lab-Inha
SMI-Lab-Inha merged commit 825d016 into dev Oct 22, 2026
18 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the perf/avx2-target branch October 22, 2026 08:03
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