Skip to content

Flatten propagation loop structure#1006

Merged
stephenswat merged 1 commit into
acts-project:mainfrom
stephenswat:refactor/flat_propagator
Jul 8, 2025
Merged

Flatten propagation loop structure#1006
stephenswat merged 1 commit into
acts-project:mainfrom
stephenswat:refactor/flat_propagator

Conversation

@stephenswat

Copy link
Copy Markdown
Member

This commit flattens the propagation loop structure with the primary goal of reducing the number of different call sites to the navigation update method. Currently. we update the navigator in three different places and this is expensive due to divergence. This commit puts all of those calls into one place in a loop, mirroring the same functional structure that was present before.

I measure a significant performance improvement due to this in traccc, and it also greatly reduces the size of the kernels.

@stephenswat
stephenswat requested a review from niermann999 June 20, 2025 12:49
@stephenswat stephenswat added refactor refactoring the current codes performance Improvements to compute performance labels Jun 20, 2025
stephenswat added a commit to stephenswat/detray that referenced this pull request Jun 20, 2025
This commit, which is very similar to acts-project#1006, flattens several different
calls to the navigator initialization into a single loop which reduces
the amount of code inlining, improves instruction cache performance and
also reducing divergence.
@stephenswat

Copy link
Copy Markdown
Member Author

Before

------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                    Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------------------------------------------------------
BM_PROPAGATION_TOY_DETECTOR_W_COV_TRANSPORT_262144_TRACKS/real_time   51675881 ns     51580750 ns           13 TracksPropagated=5.07285M/s
BM_PROPAGATION_TOY_DETECTOR_262144_TRACKS/real_time                   16518001 ns     16488511 ns           42 TracksPropagated=15.8702M/s

After

------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                    Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------------------------------------------------------
BM_PROPAGATION_TOY_DETECTOR_W_COV_TRANSPORT_262144_TRACKS/real_time   46664329 ns     46578745 ns           15 TracksPropagated=5.61765M/s
BM_PROPAGATION_TOY_DETECTOR_262144_TRACKS/real_time                   15715844 ns     15687933 ns           45 TracksPropagated=16.6802M/s

So seems to improve performance by about 5-10%.

@stephenswat
stephenswat force-pushed the refactor/flat_propagator branch 2 times, most recently from 83dcbef to edbed7f Compare June 24, 2025 11:08
@stephenswat

Copy link
Copy Markdown
Member Author

Okay, this passes the CI now!

@stephenswat

Copy link
Copy Markdown
Member Author

Updated performance results (with an added clause to force the navigator update to be inlined):

Before

------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                    Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------------------------------------------------------
BM_PROPAGATION_TOY_DETECTOR_W_COV_TRANSPORT_262144_TRACKS/real_time   48564724 ns     48479844 ns           14 TracksPropagated=5.39783M/s
BM_PROPAGATION_TOY_DETECTOR_262144_TRACKS/real_time                   15878392 ns     15849681 ns           44 TracksPropagated=16.5095M/s
BM_PROPAGATION_WIRE_CHAMBER_W_COV_TRANSPORT_262144_TRACKS/real_time   56845985 ns     56744657 ns           12 TracksPropagated=4.61148M/s
BM_PROPAGATION_WIRE_CHAMBER_262144_TRACKS/real_time                   17001492 ns     16970615 ns           41 TracksPropagated=15.4189M/s

After

------------------------------------------------------------------------------------------------------------------------------
Benchmark                                                                    Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------------------------------------------------------
BM_PROPAGATION_TOY_DETECTOR_W_COV_TRANSPORT_262144_TRACKS/real_time   37458648 ns     37390653 ns           19 TracksPropagated=6.99822M/s
BM_PROPAGATION_TOY_DETECTOR_262144_TRACKS/real_time                   15085580 ns     15058706 ns           46 TracksPropagated=17.3771M/s
BM_PROPAGATION_WIRE_CHAMBER_W_COV_TRANSPORT_262144_TRACKS/real_time   39743765 ns     39671997 ns           18 TracksPropagated=6.59585M/s
BM_PROPAGATION_WIRE_CHAMBER_262144_TRACKS/real_time                   13186369 ns     13162914 ns           53 TracksPropagated=19.8799M/s

Thus the performance gain has now gone up to at least 5% and at most 43% (!).

Comment thread core/include/detray/navigation/navigator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/navigation/navigator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
Comment thread core/include/detray/propagator/propagator.hpp
This commit flattens the propagation loop structure with the primary
goal of reducing the number of different call sites to the navigation
update method. Currently. we update the navigator in three different
places and this is expensive due to divergence. This commit puts all of
those calls into one place in a loop, mirroring the same functional
structure that was present before.

I measure a significant performance improvement due to this in traccc,
and it also greatly reduces the size of the kernels.
@stephenswat
stephenswat force-pushed the refactor/flat_propagator branch from bedceef to f7c16df Compare July 8, 2025 08:41
@stephenswat
stephenswat enabled auto-merge July 8, 2025 08:42
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2025

Copy link
Copy Markdown

@stephenswat
stephenswat merged commit fb035c0 into acts-project:main Jul 8, 2025
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Improvements to compute performance refactor refactoring the current codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants