Optional xsimd SIMD support (rebase of #113)#135
Draft
DiamonDinoia wants to merge 2 commits into
Draft
Conversation
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>
DiamonDinoia
force-pushed
the
xsimd-review
branch
from
June 8, 2026 19:15
b4c829f to
c42cf8a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refreshes the xsimd SIMD support originally proposed in #113 (by @emrys53 / Fikret
Ardal), rebased onto current
unstableand reworked so that xsimd is an optionaldependency, 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
SIMDSupportoption (default OFF).When OFF, the build needs no xsimd and behaves exactly as
unstabledoes today.When ON, xsimd is fetched via
FetchContentpinned to master(
0aa209057622721607f0ba8c76daeaee75fc9b00) andNDA_HAVE_XSIMDis defined.core files (math fns, reductions, arithmetic expr
load, viewload/store), notlocalized to
simd/. Everyxsimd::/native_simduse is now guarded behindNDA_HAVE_XSIMD, withVectorizable/LoadWithNativeSimdreducing tofalsestubs when OFF so downstream traits need no further guarding.
product()initialized its fold tovalue_t{}(== 0), so every productcame out zero. Now initialized to the multiplicative identity
{1}in both thescalar and SIMD-vector paths.
Review comments
Resolved:
FORCEINLINEswitch (no raw[[gnu::always_inline]]in the SIMD code) — alreadydone in Fikret's later commits.
throwfor out-of-bounds SIMD access — already done.simd_fwd.hppadded; SIMD traits useconsteval— already done.NDA_RUNTIME_ERROR(file/line context) for consistency(hmenke).
simd_cost.hppelse-after-return / stray comment nits — no longer present afterrebase.
Deferred to discussion (design-level, out of scope here):
std::type_identityusage, "reuseapply_function".Verification
SIMDSupport=OFF: full build clean,ctest100% (37/37).SIMDSupport=ON(clang, xsimd master / v14.2.0): full build clean,ctest100%(39/39, including
nda_simd).🤖 Generated with Claude Code