Generalize SIMD Single Source Design#4924
Merged
ax3l merged 2 commits intoAMReX-Codes:developmentfrom Feb 5, 2026
Merged
Conversation
5c3adb1 to
6cf39cb
Compare
4 tasks
This adds another template overload to `ParalleForSIMD`.
A typical user pattern for maximum controls so far is:
```
if constexpr (amrex::simd::is_vectorized<T>) {
amrex::ParallelForSIMD<T::simd_width>(np, pushSingleParticle); // TODO: test 2,4,8, ... and handle remainder
} else
{
amrex::ParallelFor(np, pushSingleParticle);
}
```
This simplifies it to:
```
amrex::ParallelForSIMD<T>(np, pushSingleParticle);
```
indicating there might be a templated path.
877dde1 to
40f36a6
Compare
Member
|
I don't think |
ax3l
commented
Feb 3, 2026
3 tasks
40f36a6 to
8da037c
Compare
A typical SIMD user pattern for particle SoA kernels was:
```C++
SIMDParticleReal<SIMD_WIDTH> part_x;
part_x.copy_from(&m_part_x[i], stdx::element_aligned);
el.compute(part_x);
if constexpr (is_nth_arg_non_const<&el::compute, n>)
part_x.copy_to(&m_part_x[i], stdx::element_aligned);
```
This simplifies it to:
```C++
decltype(auto) x = load_1d(m_part_x, i);
el.compute(x);
store_1d<&el::compute, 0>(x, m_part_x, i);
```
8da037c to
963e095
Compare
ax3l
commented
Feb 3, 2026
| AMREX_ATTRIBUTE_FLATTEN_FOR | ||
| void ParallelForSIMD (N n, L && f) noexcept | ||
| { | ||
| #ifdef AMREX_USE_SIMD |
Member
Author
There was a problem hiding this comment.
One could maybe add another "and not GPU" here, just to be super sure if someone turns on SIMD and GPU at the same time to stay with the GPU path... Not sure if relevant.
WeiqunZhang
approved these changes
Feb 4, 2026
Member
Author
|
Tests in #4938 |
ax3l
added a commit
that referenced
this pull request
Feb 7, 2026
## Summary Needed to cover SIMD features and generic SIMD/non-SIMD patterns. Bravely vibe coded, but now reviewed and improved for sensibility. ## Additional background #4924 #4607 #4600 #4520 ## 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 --------- Co-authored-by: Weiqun Zhang <[email protected]>
5 tasks
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.
Add
ParallelForSIMD<T>This adds another template overload to
ParallelForSIMD.A typical user pattern for maximum controls so far is:
This simplifies it to:
indicating there might be a SIMD path if
T(e.g., a functor) implements it.One can still call
ParallelForSIMDwith an explicit SIMD width (int), as before.Generalized Particle Load/Store
A typical SIMD user pattern for particle SoA kernels was:
This simplifies it to:
and can now also be used for the GPU path, where for now the load is a transparent pointer forward/deref and the store is a no-OP.
Combined
Using these patterns together, one can now write single-source SIMD-CPU/non-SIMD-CPU/GPU kernels, e.g., BLAST-ImpactX/impactx#1279
Follow-up to #4520
Checklist
The proposed changes: