Skip to content

BeamOptics: Generalize SIMD Logic in AMReX#1289

Open
ax3l wants to merge 2 commits into
BLAST-ImpactX:developmentfrom
ax3l:topic-generalize-simd-amrex
Open

BeamOptics: Generalize SIMD Logic in AMReX#1289
ax3l wants to merge 2 commits into
BLAST-ImpactX:developmentfrom
ax3l:topic-generalize-simd-amrex

Conversation

@ax3l
Copy link
Copy Markdown
Member

@ax3l ax3l commented Feb 3, 2026

Follow-up to #1279 , but now relying on AMReX constructs of 26.02+ in AMReX-Codes/amrex#4924

@ax3l ax3l added the backend: SIMD CPU with SIMD acceleration label Feb 3, 2026
@ax3l ax3l changed the title BeamOptics: Generalize SIMD Logic BeamOptics: Generalize SIMD Logic in AMReX Feb 3, 2026
@ax3l ax3l changed the title BeamOptics: Generalize SIMD Logic in AMReX BeamOptics: Generalize SIMD Logic in AMReX Feb 3, 2026
@ax3l ax3l force-pushed the topic-generalize-simd-amrex branch from 23082d8 to cbfb21b Compare February 10, 2026 06:39
Comment thread src/elements/mixin/beamoptic.H Fixed
Comment thread src/elements/mixin/beamoptic.H Fixed
@ax3l ax3l force-pushed the topic-generalize-simd-amrex branch from cbfb21b to 0956fc6 Compare February 23, 2026 21:29
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 23, 2026

Merging this PR will not alter performance

✅ 37 untouched benchmarks


Comparing ax3l:topic-generalize-simd-amrex (477d648) with development (ba130b6)

Open in CodSpeed

@ax3l ax3l force-pushed the development branch 2 times, most recently from 9a1e4af to fa61eba Compare April 20, 2026 04:08
@ax3l ax3l force-pushed the topic-generalize-simd-amrex branch from 0956fc6 to d577c40 Compare April 22, 2026 22:08
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented Apr 22, 2026

Oops, #1430 #1441

@ax3l ax3l force-pushed the topic-generalize-simd-amrex branch 3 times, most recently from a1ade1e to 43311b1 Compare April 28, 2026 05:15
@ax3l ax3l force-pushed the topic-generalize-simd-amrex branch from 43311b1 to 86ae08a Compare April 30, 2026 21:36
@ax3l ax3l requested review from EZoni and WeiqunZhang May 1, 2026 00:03
@ax3l
Copy link
Copy Markdown
Member Author

ax3l commented May 1, 2026

@WeiqunZhang @EZoni this is ready now :)

Comment on lines +125 to +134
store_1d<P_Method, 0>(x, m_part_x, i);
store_1d<P_Method, 1>(y, m_part_y, i);
store_1d<P_Method, 2>(t, m_part_t, i);
store_1d<P_Method, 3>(px, m_part_px, i);
store_1d<P_Method, 4>(py, m_part_py, i);
store_1d<P_Method, 5>(pt, m_part_pt, i);
store_1d<P_Method, 6>(sx, m_part_sx, i);
store_1d<P_Method, 7>(sy, m_part_sy, i);
store_1d<P_Method, 8>(sz, m_part_sz, i);
store_1d<P_Method, 9>(idcpu, m_part_idcpu, i);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These store_1d calls are not guarded anymore by

if constexpr (amrex::simd::is_vectorized<T_Element>)

while the store_1d calls below (lines 241-247) kept that guard (line 233).

Is this intentional and, if so, what's the reason for the asymmetry?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a special constexpr check in store_1d in AMReX

        // SIMD uses special vector register types in ValType that need to be copied back to RAM array type T
        if constexpr (!std::is_same_v<ValType, T>) {

that serves the same purpose as the "is this a vectorized type" check we had before.
https://github.com/AMReX-Codes/amrex/pull/4924/changes

I should remove the guard below as well and just forgot (it does not hurt, but it is verbose).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah but here is the catch:
Scalar-only elements like ExactCFbend have a concrete non-template particle operator() that we need to guard the constexpr decltype(auto) P_Method = ... from.

The spin path does not hit that issue because it uses spin_and_phasespace_push, and currently all the spin-capable elements implement that as a templated method.

Comment thread src/elements/mixin/beamoptic.H Fixed
Comment thread src/elements/mixin/beamoptic.H Fixed
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend: SIMD CPU with SIMD acceleration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants