Skip to content

Optional xsimd SIMD support (rebase of #113)#135

Draft
DiamonDinoia wants to merge 2 commits into
TRIQS:unstablefrom
DiamonDinoia:xsimd-review
Draft

Optional xsimd SIMD support (rebase of #113)#135
DiamonDinoia wants to merge 2 commits into
TRIQS:unstablefrom
DiamonDinoia:xsimd-review

Conversation

@DiamonDinoia

Copy link
Copy Markdown
Collaborator

Summary

Refreshes the xsimd SIMD support originally proposed in #113 (by @emrys53 / Fikret
Ardal), rebased onto current unstable and reworked so that xsimd is an optional
dependency, default OFF
. Supersedes #113.

All 37 SIMD commits are Fikret's, preserved with original authorship. Two commits on
top wire the optional dependency and guard the call sites.

What changed relative to #113

  • xsimd is now optional. New top-level SIMDSupport option (default OFF).
    When OFF, the build needs no xsimd and behaves exactly as unstable does today.
    When ON, xsimd is fetched via FetchContent pinned to master
    (0aa209057622721607f0ba8c76daeaee75fc9b00) and NDA_HAVE_XSIMD is defined.
  • Guards at every call site. The SIMD code is woven through ~580 lines across 11
    core files (math fns, reductions, arithmetic expr load, view load/store), not
    localized to simd/. Every xsimd:: / native_simd use is now guarded behind
    NDA_HAVE_XSIMD, with Vectorizable / LoadWithNativeSimd reducing to false
    stubs when OFF so downstream traits need no further guarding.
  • Bug fix: product() initialized its fold to value_t{} (== 0), so every product
    came out zero. Now initialized to the multiplicative identity {1} in both the
    scalar and SIMD-vector paths.

Review comments

Resolved:

  • FORCEINLINE switch (no raw [[gnu::always_inline]] in the SIMD code) — already
    done in Fikret's later commits.
  • asserts → throw for out-of-bounds SIMD access — already done.
  • simd_fwd.hpp added; SIMD traits use consteval — already done.
  • SIMD bounds check now uses NDA_RUNTIME_ERROR (file/line context) for consistency
    (hmenke).
  • simd_cost.hpp else-after-return / stray comment nits — no longer present after
    rebase.

Deferred to discussion (design-level, out of scope here):

  • cost-model direction, std::type_identity usage, "reuse apply_function".

Verification

  • SIMDSupport=OFF: full build clean, ctest 100% (37/37).
  • SIMDSupport=ON (clang, xsimd master / v14.2.0): full build clean, ctest 100%
    (39/39, including nda_simd).

🤖 Generated with Claude Code

Fikret Ardal and others added 2 commits June 8, 2026 15:15
Add SIMD vectorization for nda array operations, backed by xsimd:

  - vectorized element-wise maps and mapped math functions
  - vectorized reductions: sum, product, min/max, frobenius norm, hadamard
  - SIMD load on arithmetic expressions and load/store on arrays/views,
    including the matrix+scalar diagonal special case
  - a compile-time SIMD cost model (simd/simd_cost.hpp) that decides, per
    expression, whether to vectorize, emulate, or fall back to scalar
  - Vectorizable / LoadWithNativeSimd concepts and supporting traits

This squashes the original xsimd work (TRIQS#113).
Make the xsimd SIMD support optional and off by default, so the standard
build needs no xsimd and is unchanged:

  - new top-level SIMDSupport option (default OFF). When ON, deps fetches
    xsimd pinned to master (0aa209057622721607f0ba8c76daeaee75fc9b00),
    c++/nda links xsimd and defines NDA_HAVE_XSIMD.
  - guard every xsimd:: / native_simd call site behind NDA_HAVE_XSIMD
    (maps, reductions, arithmetic expr load, view load/store). Vectorizable
    and LoadWithNativeSimd reduce to false stubs when OFF, so downstream
    traits need no further guarding.
  - test suite filters the SIMD-only tests (nda_simd, nda_traits) when OFF;
    both still run in the ON build.

Fixes folded in (both inside guarded regions):
  - product() initialized its fold to value_t{} (== 0), making every product
    zero; now initialized to the multiplicative identity {1} in both the
    scalar and SIMD paths.
  - the SIMD bounds check uses NDA_RUNTIME_ERROR (file/line context) instead
    of a bare throw std::runtime_error, for consistency (review, hmenke).

Co-Authored-By: Fikret Ardal <fikret.ardal@tum.de>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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