Skip to content

Fix EVE/simd unaligned load and store broadcast - #7435

Merged
hkaiser merged 1 commit into
TheHPXProject:masterfrom
adhithyaragavan:fix-unaligned-vector-pack-load-store
Aug 9, 2026
Merged

hkaiser merged 1 commit into
TheHPXProject:masterfrom
adhithyaragavan:fix-unaligned-vector-pack-load-store

Conversation

@adhithyaragavan

Copy link
Copy Markdown
Contributor

Summary

Fixes #7287.

vector_pack_load<V, T>::unaligned returned a broadcast of a single scalar (*iter) across every lane of the pack instead of loading the N consecutive elements starting at that address, for both the EVE and std-experimental-simd backends. The symmetric bug existed in vector_pack_store<V, T>::unaligned, writing the same broadcast value everywhere instead of storing each lane back to its own position.

  • EVE backend: unaligned() now constructs directly from the pointer (V(std::addressof(*iter))), which resolves to eve::wide's genuine unaligned-load constructor rather than the scalar-broadcast constructor; store uses eve::store(value, ptr) with a plain (non-as_aligned) pointer.
  • std-experimental-simd backend: exposed std::experimental::element_aligned (previously only vector_aligned was re-exported) and used it for both load and store.

V can also be instantiated as a scalar value_type — the width-1 "pack" used by the remainder/tail-element path (see vector_pack_type<T, 1, Abi>) — for which neither eve::wide's pointer constructor / eve::store, nor std::experimental::simd's pointer constructor / copy_to, are valid. Both fixes are gated on eve::is_simd_value<V>{} / datapar::experimental::is_simd_v<V> respectively, falling back to the original plain-assignment behavior for the scalar case.

Scope: this only touches the unaligned load/store fix itself, split out from the larger change in #7288 (which also rewrites search/search_n) per discussion there.

Tests

Added libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp (gated on HPX_WITH_DATAPAR), following the naming/registration pattern of the other numbered regression tests in that directory (annotated_minmax_2593, chunk_size_4118, etc.). It:

  1. Loads a non-uniform, strictly-increasing full-width pack via unaligned() and checks every lane against the source data (a broadcast bug collapses every lane to the first element).
  2. Negates each lane and stores the pack back via unaligned(), then checks every destination element was updated independently (a broadcast bug overwrites the whole range with one repeated value).

Test plan

  • Built and ran locally with HPX_WITH_DATAPAR_BACKEND=EVE: new regression test passes.
  • Confirmed the test is meaningful — reverting just the EVE load fix reproduces a compile error against the pre-fix code (not merely a wrong-value bug): eve::wide's scalar-broadcast constructor is explicit, so return *iter; fails to convert to a full-width V when the function is actually instantiated with a genuine pack (as happens via invoke_vectorized_in2/invoke_vectorized_in2_ind in iterator_helpers.hpp, used by two-iterator algorithms like mismatch/equal_binary/transform_binary). None of the current datapar test suite happens to instantiate unaligned() with a full pack today, so this was previously silent; the new regression test is (as far as I can tell) the first thing in-tree to exercise that path directly.
  • Re-ran the full existing datapar test set potentially affected (foreach_datapar_test, transform_datapar_test, find_datapar_test, datapar_zip_iterator_guard_test, mismatch_datapar_test, equal_binary_datapar_test, transform_binary_datapar_test, search_datapar_test, search_n_datapar_test, foreach_datapar_zipiter_test) — all still pass with the fix applied.
  • Not tested against the SVE or Vc backends (no access to that hardware/library locally); the std::experimental::simd fix was verified by inspection/compile reasoning only (this machine's compilers don't expose the same EVE test harness for that backend) — would appreciate a check on CI.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a05cf9cc-995d-487a-bc48-5146ee45eb68

📥 Commits

Reviewing files that changed from the base of the PR and between fe2a761 and 246fb37.

📒 Files selected for processing (5)
  • libs/core/execution/include/hpx/execution/traits/detail/eve/vector_pack_load_store.hpp
  • libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_load_store.hpp
  • libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_simd.hpp
  • libs/core/execution/tests/regressions/CMakeLists.txt
  • libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp
🚧 Files skipped from review as they are similar to previous changes (5)
  • libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_simd.hpp
  • libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_load_store.hpp
  • libs/core/execution/include/hpx/execution/traits/detail/eve/vector_pack_load_store.hpp
  • libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp
  • libs/core/execution/tests/regressions/CMakeLists.txt

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved unaligned loading and storing for SIMD values.
    • Added correct scalar handling for unaligned operations.
  • New Features

    • Exposed an SIMD element-alignment option for supported operations.
  • Tests

    • Added regression coverage verifying unaligned vector-pack loads and stores across all lanes.

Walkthrough

This PR separates SIMD and scalar handling in unaligned vector-pack load/store operations for the SIMD and EVE backends. It exports element_aligned and adds regression coverage for per-lane load and store behavior.

Changes

Unaligned vector pack load/store regression fix

Layer / File(s) Summary
SIMD and scalar unaligned load/store split
libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_simd.hpp, libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_load_store.hpp, libs/core/execution/include/hpx/execution/traits/detail/eve/vector_pack_load_store.hpp
The SIMD wrapper exports hpx::datapar::experimental::element_aligned. The unaligned helpers use SIMD operations for SIMD packs and direct dereference or assignment for scalar values.
Regression coverage and test registration
libs/core/execution/tests/regressions/CMakeLists.txt, libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp
The regression test list registers vector_pack_unaligned_load_store_7287. The test checks per-lane unaligned load and store values when dataparsupport is enabled and provides a successful fallback otherwise.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • TheHPXProject/hpx#7287 — The PR changes the unaligned vector_pack_load and vector_pack_store paths and adds regression coverage for this issue.

Suggested reviewers: hkaiser

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the fix for unaligned EVE and SIMD load and store broadcasting.
Description check ✅ Passed The description directly explains the bug, implementation changes, scalar handling, and regression test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@StellarBot

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp (1)

36-39: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add deterministic coverage for the scalar width-one path.

vector_pack_type_t<value_type> selects the default width and skips the width-one scalar fallback in this test. Use an explicit vector_pack_type_t<value_type, 1> case to cover scalar unaligned load/store independently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp`
around lines 36 - 39, Update the test’s vector type declaration near value_type
and V to explicitly instantiate vector_pack_type_t with width 1, ensuring the
unaligned load/store regression exercises the scalar fallback path
deterministically while preserving the existing width-based test setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@libs/core/execution/include/hpx/execution/traits/detail/eve/vector_pack_load_store.hpp`:
- Around line 43-45: Replace the undocumented eve::is_simd_value predicate in
the affected vector-pack load/store branches with the supported eve::simd_value
trait, matching the neighboring vector_pack_type specialization; apply this
consistently at both referenced locations.

In `@libs/core/execution/tests/regressions/CMakeLists.txt`:
- Around line 11-14: Add regression coverage for both datapar backend paths by
adding or selecting CI configurations that set HPX_WITH_DATAPAR_BACKEND to EVE
and STD_EXPERIMENTAL_SIMD, rather than relying only on HPX_WITH_DATAPAR or
EMULATE. Ensure the existing datapar regression tests, including
lambda_arguments_2403, lambda_return_type_2402, rebind_par_simd, and
vector_pack_unaligned_load_store_7287, execute under each backend.

---

Nitpick comments:
In
`@libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp`:
- Around line 36-39: Update the test’s vector type declaration near value_type
and V to explicitly instantiate vector_pack_type_t with width 1, ensuring the
unaligned load/store regression exercises the scalar fallback path
deterministically while preserving the existing width-based test setup.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 897cdad7-3603-4e92-be9d-f6e879b47b86

📥 Commits

Reviewing files that changed from the base of the PR and between d4a43d7 and 3bc918a.

📒 Files selected for processing (5)
  • libs/core/execution/include/hpx/execution/traits/detail/eve/vector_pack_load_store.hpp
  • libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_load_store.hpp
  • libs/core/execution/include/hpx/execution/traits/detail/simd/vector_pack_simd.hpp
  • libs/core/execution/tests/regressions/CMakeLists.txt
  • libs/core/execution/tests/regressions/vector_pack_unaligned_load_store_7287.cpp

Comment thread libs/core/execution/tests/regressions/CMakeLists.txt
@hkaiser

hkaiser commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Please have a look at the clang-format complaints and address the comments (or mark them as resolved with an explanation).

vector_pack_load<V, T>::unaligned returned a broadcast of a single
scalar across every lane instead of loading the N consecutive
elements starting at that address, for both the EVE and
std-experimental-simd backends; the symmetric bug existed in
vector_pack_store<V, T>::unaligned. Fix both to perform genuine
unaligned loads/stores (EVE via the pointer constructor and
eve::store, simd via the newly exposed element_aligned tag).

V can also be instantiated as a scalar value_type (the width-1 pack
used for remainder/tail elements), which neither eve::wide's pointer
constructor, eve::store, nor std::experimental::simd's copy_to accept,
so both fixes are gated on an is_simd_value/is_simd_v check with the
original scalar behavior preserved in the else branch.

Add a regression test that loads a non-uniform full-width pack via
unaligned(), verifies every lane against the source (a broadcast bug
collapses every lane to the first element), negates each lane, stores
it back via unaligned(), and verifies each destination element was
updated independently rather than overwritten with one repeated value.
Confirmed this test fails to compile against the pre-fix code (EVE
backend) and passes with the fix.

Fixes TheHPXProject#7287

Signed-off-by: adhithyaragavan <[email protected]>
@adhithyaragavan
adhithyaragavan force-pushed the fix-unaligned-vector-pack-load-store branch from 3bc918a to 246fb37 Compare August 6, 2026 21:49
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@adhithyaragavan

adhithyaragavan commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed the clang-format issue (and the DCO sign-off / C++20 modules build failure that were also flagged), pushed. Replied inline to the two CodeRabbit comments below with my reasoning on why I left those as is, let me know if you'd like it done differently.

@hkaiser hkaiser mentioned this pull request Aug 7, 2026
3 tasks done

@hkaiser hkaiser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@hkaiser hkaiser added this to the 2.0.0 milestone Aug 9, 2026
@hkaiser
hkaiser merged commit 8caada2 into TheHPXProject:master Aug 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector_pack_load::unaligned broadcasts scalar instead of loading pack

3 participants