SIMD: Add where and ternary operator#5095
Open
ax3l wants to merge 6 commits intoAMReX-Codes:developmentfrom
Open
SIMD: Add where and ternary operator#5095ax3l wants to merge 6 commits intoAMReX-Codes:developmentfrom
ax3l wants to merge 6 commits intoAMReX-Codes:developmentfrom
Conversation
To write more portable code, add a scalar fallback for `std::simd::where` for non-SIMD code. Expose both as `amrex::simd::stdx`. Add Doxygen string to existing scalar `amrex::simd::std::any_of` fallback. Add a new implementation for a portable tenary operator, inspired by Kokkos https://kokkos.org/kokkos-core-wiki/ProgrammingGuide/SIMD.html#ternary-operator as `amrex::simd::conditional`. Demonstrate usage in doc strings and new test cases.
This is the likely ISO C++26 name.
8dc1b72 to
bb4111a
Compare
bb4111a to
db1fbbb
Compare
Will be there eventually with C++26
db1fbbb to
888c531
Compare
Consistently: Real -> ParticleReal
Member
Author
|
@WeiqunZhang oh dang, I force pushed away your last commit. Sorry for this! If you still have it locally feel free to push. Just cleaning up santitizer warnings rn |
Member
|
No problems. Very simple change. |
Member
|
And your change was actually I wanted to do. But I was not 100 percent sure. So I did the nolint way. If your change works, it's better than nolint. |
WeiqunZhang
approved these changes
Mar 2, 2026
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
To write more portable code, add a scalar fallback for
std::simd::wherefor non-SIMD code. Expose both asamrex::simd::stdx.Add Doxygen string to existing scalar
amrex::simd::std::any_offallback.Add a new implementation for a portable ternary operator, inspired by Kokkos condition as
amrex::simd::stdx::select. (We call itselectbecause that is the likely ISO C++26 name: https://en.cppreference.com/w/cpp/numeric/simd.html )Demonstrate usage in doc strings and new test cases.
Additional background
These are patterns I commonly see needed in BLAST-ImpactX, e.g. here.
This will help to write more complex SIMD code like #4649 in a cleaner way, too.
Follow up to #4520 #4938 #4924
Checklist
The proposed changes: