Skip to content

SIMD: Add where and ternary operator#5095

Open
ax3l wants to merge 6 commits intoAMReX-Codes:developmentfrom
ax3l:simd-where-tenary
Open

SIMD: Add where and ternary operator#5095
ax3l wants to merge 6 commits intoAMReX-Codes:developmentfrom
ax3l:simd-where-tenary

Conversation

@ax3l
Copy link
Member

@ax3l ax3l commented Feb 26, 2026

Summary

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 ternary operator, inspired by Kokkos condition as amrex::simd::stdx::select. (We call it select because 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:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

ax3l added 2 commits February 26, 2026 11:18
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.
@ax3l ax3l force-pushed the simd-where-tenary branch from 8dc1b72 to bb4111a Compare February 26, 2026 19:38
@ax3l ax3l changed the title SIMD: Add where and tenary operator SIMD: Add where and ternary operator Feb 26, 2026
@ax3l ax3l force-pushed the simd-where-tenary branch from bb4111a to db1fbbb Compare February 26, 2026 19:41
Will be there eventually with C++26
@ax3l ax3l force-pushed the simd-where-tenary branch from db1fbbb to 888c531 Compare February 26, 2026 19:46
@ax3l ax3l force-pushed the simd-where-tenary branch from 2ea37df to 98e25d7 Compare March 2, 2026 17:38
Consistently: Real -> ParticleReal
@ax3l ax3l force-pushed the simd-where-tenary branch from cf14f73 to f26ead9 Compare March 2, 2026 22:05
@ax3l
Copy link
Member Author

ax3l commented Mar 2, 2026

@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

@WeiqunZhang
Copy link
Member

No problems. Very simple change.

@WeiqunZhang
Copy link
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.

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.

2 participants