Repository navigation
Time device actions asynchronously with CUDA/HIP events - #2709
Merged
Merged
Conversation
Test summary 8 214 files 13 532 suites 14m 45s ⏱️ Results for commit ebb6f73. ♻️ This comment has been updated with latest results. |
sethrj
marked this pull request as ready for review
November 29, 2026 03:43
sethrj
marked this pull request as draft
November 29, 2026 11:39
sethrj
reviewed
Nov 29, 2026
sethrj
requested changes
Nov 30, 2026
sethrj
reviewed
Nov 30, 2026
elliottbiondo
pushed a commit
to osanstrong/celeritas
that referenced
this pull request
Dec 1, 2026
…ect#2711) * Add device event timing and asynchronous stream timer Add DeviceEvent::query_elapsed_time and a StreamTimer that records a chain of timing events on a stream without synchronizing, and later flushes the elapsed intervals into per-ID accumulators. This is split out of celeritas-project#2709 so it can be reviewed separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Move stream timer layout notes to flush docs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Disable stream timer test when GPU is disabled * Apply device requirement to stream timer test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Bind stream timer to a single stream at construction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Seth R Johnson <johnsonsr@ornl.gov>
Add a timing option and elapsed_since to DeviceEvent, and a StreamTimer that records a chain of timed events on a stream and reads them lazily. ActionTimesState holds a StreamTimer for device states; ActionTimer wraps the host stopwatch and the device timer, flushing the previous step's intervals at the start of the next step (after the host has already waited on the step counters). Factor the step-action loop shared by ActionSequence and optical::Transporter into detail::execute_step_actions and execute_end_transport_actions. Since action timers no longer synchronize, keep the documented DeviceDebug::sync_stream behavior with an explicit ActionSequence option, and stop the apps from enabling sync_stream just to get action times. Device code is built but untested (no GPU available in this session). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Replace DeviceEvent::Timing and elapsed_since with a private bool constructor, DeviceEvent::with_timing, use_timing(), and a free non-synchronizing elapsed_time(start, stop) - Move ActionLoop out of global/detail to celeritas/action so optical code doesn't use another package's detail; note the rule in AGENTS.md - Stop enabling action timers from DeviceDebug::sync_stream - Apply sync_stream to in-core optical offload actions as well Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Replace the StreamTimer integer index and start-marker sentinel with a TimerId; a StreamTimer now requires an active device (no null mode) - Move ActionTimer and the timer state to celeritas/action/ActionTimer.hh so that action code does not depend on celeritas/user - Specialize ActionTimesState and ActionTimer on the memory space, with a common ActionTimesStateBase for reading times - Replace ActionTimes::clear_action_times with exchange_action_times, which includes pending device times instead of discarding them - Document the remaining ActionLoop parameters, the final flush, and the StreamTimer event lifetime Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Store the stream ID rather than a stream reference in the device action times state, since device streams may be recreated during the state's lifetime. Document the step-timer and time-type follow-ups as todos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the action times state into celeritas/action/ActionTimesState.hh and make the accumulated times private - Replace the specialized ActionTimer classes with a single non-owning template that forwards to private state functions - Remove StreamTimer::add_elapsed: flush is the only read and checks that the accumulator covers every pending ID - Make get_action_times take mutable aux data so it can flush - Rename elapsed_time to query_elapsed_time Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sethrj-bot
force-pushed
the
async-action-timers
branch
from
December 1, 2026 16:51
1370f5b to
33fe6a6
Compare
sethrj
previously requested changes
Dec 1, 2026
Make the recording functions of ActionTimesStateBase public virtual (final in the memory-space specializations) and pass an ObserverPtr to the state to the action loop in place of ActionTimer, which is removed. Replace StepperInterface::sp_state with a mutable state() overload. Add todos for casting between opaque ID types and for moving the action timing files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sethrj
marked this pull request as ready for review
December 2, 2026 01:31
Member
|
@esseivaju This one's ready 😄 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2709 +/- ##
===========================================
- Coverage 86.04% 85.96% -0.08%
===========================================
Files 1417 1423 +6
Lines 45512 45543 +31
Branches 11660 11637 -23
===========================================
- Hits 39159 39152 -7
+ Misses 4641 4609 -32
- Partials 1712 1782 +70
🚀 New features to boost your workflow:
|
esseivaju
approved these changes
Dec 3, 2026
esseivaju
left a comment
Member
There was a problem hiding this comment.
Looks good! Two minor comments
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merged
via the queue into
celeritas-project:develop
with commit Dec 3, 2026
8dfc575
49 checks passed
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.
Action timers on device no longer synchronize the stream after every action. Core (
ActionSequence) and optical (optical::Transporter) action times are now measured with CUDA/HIP events recorded asynchronously on the state's stream. Host timing still uses the CPUStopwatchand behaves as before.Built and tested on CPU and on an NVIDIA V100 (CUDA). The new device tests pass, and the full GPU ctest has no regressions compared with upstream/develop. See "GPU test results" below. After the rebase the tree is byte-identical to the previously tested 1370f5b (develop ac9e26d plus #2711), so those results still apply. The review changes in 8f9f368 were tested on a P100 (
release-orange-celer-cuda, sm_60): 194/197 related GPU and CPU tests pass. The 3 failures (StepperGeant:TestEm3Msc,StepperGeant:TestEm15FieldMsc,OpticalCollector, all device step/photon counts) also fail on the same node with develop db9a1d4, so they come from the P100 and not from this PR.Design
The
DeviceEventtiming API andStreamTimerare described in #2711. The action timer constructs oneStreamTimer(device, sid)per state and callsstart()/stop(TimerId)around each action.ActionTimesState<M>(new,celeritas/action/ActionTimesState.{hh,cc})These live in
celeritas/actionso that the action loop doesn't depend onceleritas/user.ActionTimesStateBaseholds the private accumulated times. Its memory-space-independent reads areget_times()(flush pending, return the totals without resetting) andexchange_times()(flush, return, reset), built on a private virtualflush_pending. This is the same pattern asGeneratorStateBase. The class docs list the callers of each read and why both exist.begin_step/start/stopare public pure virtuals on the base.ActionTimesState<M>is specialized on the memory space and implements them asfinal(both specializations arefinal), so callers holding the derived type don't need virtual dispatch.Stopwatchwhose time is added immediately, as before.StreamTimerand theStreamId, and looks up the stream on each call.begin_stepflushes the previous step's intervals and records a start marker. The flush syncs only the last event of the previous step. Both drivers wait on the step counters before starting the next step, and that counter copy is enqueued after the actions, so in practice the flush never blocks.ActionTimesStatePtr<M>(ObserverPtr<ActionTimesState<M>, MemSpace::host>, inActionLoop.hh); null means timing is disabled. The driver gets the typed state withActionTimes::state<M>(aux)and callsbegin_step()once per step. (An earlierActionTimer<M>handle was removed in review.)get_action_timesnow takesAuxStateVec&(inActionTimes,ActionSequence,optical::TransporterandOpticalCollector) so that it can flush. This is where the final step's intervals get read, and it blocks only for the last recorded event. Callers passstate().aux(), using a new mutableStepperInterface::state()overload that replacessp_state(), so the accelGetActionTime() constsignatures are unchanged.LocalTransporter::GetState()no longer needs itsconst_cast.ActionTimes::clear_action_timesis replaced byexchange_action_times, which flushes, returns, and resets the times.optical::Transporter::exchange_action_timesforwards to it.Shared step loop (
celeritas/action/ActionLoop.hh)execute_step_actions(groups, params, state, ActionTimesStatePtr<M>, skip, post)holds the common body thatActionSequence::stepandoptical::Transporter::transport_implused to duplicate: loop over step actions, profiling range,action.step, timer stop, post hook.execute_end_transport_actionsdoes the same for end-of-transport actions.skip_post_actionpredicate and a post hook that runs theStatusChecker(when enabled) and the optionalsync_streamsync.timer.start()so checker work is not counted against the next action. Previously the timed and untimed paths were two copies of the loop; now there is one.sync_streamsemanticsinp::DeviceDebug::sync_streamwas documented as "synchronize after every kernel launch". In practice it only turned on action timers, and those were what synchronized. Now action timers and stream sync are independent:ActionSequence::Options::sync_streamandoptical::Transporter::Input::sync_stream. They are set frominp::DeviceDebuginsetup::problem, the latter throughOpticalCollector::InputandOpticalLaunchAction, and they sync the stream after each core or optical step action. The standaloneinp::OpticalProblemhas noDeviceDebugyet.sync_streamno longer enables action timers. Onlydiagnostics.timers.action(or running on host) does, for both the core sequence and the in-core optical offload.RunnerInput.cc) and accel (SetupOptions.cc) no longer setsync_stream = action_times, so asking for action times no longer brings back the per-action sync.Timing semantics (documented in
inp::Timers,StreamTimer,Stepper::async)On device, an action's time is the elapsed device time from the previous marker to the marker after that action's launches. It includes kernel execution and any device idle time while waiting for the host to launch the next action. Host-side time that overlaps earlier device work is hidden, and it no longer includes forced synchronization overhead. Step times (
inp::Timers::step) are unchanged: host wall clock, synchronized at the end of each device step. Converting them is a follow-up, recorded as a\todoonActionSequence::step; so is a dedicated time type forquery_elapsed_timeandStreamTimer.Tests
corecel/sys/DeviceEvent.test.cc, newtimingtest (device only): a 50 ms host function between timed events gives an elapsed time of at least 45 ms; back-to-back events give a small non-negative time;query_elapsed_timeon a pending event throws (DebugErrorwith debug assertions, elseRuntimeError), anduse_timing()is checked on timed, untimed, and null events.corecel/sys/StreamTimer.test.cc(new):devicecovers interleaved timer IDs, chained stops, an untimed 100 ms gap that must be excluded, that recording doesn't block, flush/clear, event reuse, and flushing a shorter sequence after a longer one (it must wait on the latest marker, notevents_.back()). With debug assertions it also checks that an undersized accumulator throws (not run yet: the GPU build isCELERITAS_DEBUG=OFF).celeritas/global/Stepper.test.cc, newActionTimesTest.{host,device}: warmup isn't timed;get_action_timesworks right afterasync()while a step is still running; times stay the same across repeated (flushing) reads and only increase across steps;exchange_action_timesreturns the same times and then empties them; expected actions have times > 0.hostpasses on CPU.devicepasses on the V100.optical/Generatorhost tests check that the optical action times are > 0, and they still pass. Their:gpuvariants exercise the async optical path, and they pass on the V100.Build/test status (CPU host)
release-orange-cuda(CUDA 70;80;90;120, OpenMP,-Werror): full build OK. CPU ctest withCELER_DISABLE_DEVICE=1: 458/459 pass. The one failure,celeritas/Json, is unrelated and also fails on upstream/develop: it expects_version"0.7.0" but the tree is 0.7.1-rc.ActionTimesTest.hostpasses; the device tests are skipped. (CPU numbers predate the review changes; the review commits were tested on the GPU build below, including its host tests.).ccfiles were compiled individually with that build'scompile_commands.jsonflags (-Werror), and they pass.DeviceEvent.ccandStreamTimer.cccompile with therelease-orange-hipflags.GPU test results (V100,
release-orange-cuda)DeviceEvent|StreamTimer|Stepper|optical/(Generator|Detector)|accel, 147 tests) passes 147/147, includingDeviceEventTest.timing,StreamTimerTest.device, andActionTimesTest.{host,device}.app/celer-sim|optical/Runner|optical/OpticalCollectorfail only onoptical/OpticalCollectorandapp/celer-sim:lar:gpu, the two known upstream failures listed below, with the same messages.DeviceEvent|StreamTimer|Stepper|optical|accel, 181 tests) passes exceptoptical/OpticalCollectorandapp/celer-sim:lar:gpu, the two known upstream failures listed below.StreamTimerTest.deviceandActionTimesTest.{host,device}pass. 87498d7 (stream ID lookup,\todonotes) builds cleanly; its targeted test run was stopped early on request, so it was not re-run.Results from 9579d4b (first review round):
DeviceEventTest.timingStreamTimerTest.deviceActionTimesTest.devicecorecel/sys/{DeviceEvent,StreamTimer}andceleritas/global/Stepperoptical/Generator*:gpu,optical/Detector:gpu, and accel*:gpu:{serial,mt,task}integration tests pass.lar-sphere-gpuwith action times on reports 36 actions, all with time > 0, including the optical actions (optical::generate,optical::along-step, ...).-j32gives 507/511 passing. I rebuilt the merge base (upstream/develop 27b38d2) and confirmed all 4 failures there, so none are caused by this PR:celeritas/Json: version string, as on CPU.optical/OpticalCollectordevice_{distributions,generate}: reference counts differ on this GPU (403128 vs 416523 photons). The values are identical on upstream and are deterministic from run to run.app/celer-sim:lar:gpu: thesimple-driver.py:219assertionlen(steps[0]) == num_step_iterations[0]fails on upstream too. Step times accumulate over the 4 events on one stream (16 entries), but the check compares against a single event (4 iterations).celeritas/global/StepperSimpleComptonTest.fail_initialize(host): fails only when the machine is oversubscribed. It fails 20/20 withOMP_NUM_THREADS=4 taskset -c <one cpu>and passes 40/40 otherwise. The baseline shows the same behavior. The cause is the order ofatomic_addinmake_track_id, which changes the expectedtrack_id.CELERITAS_DISABLE_DEVICEis cached when CMake configures. If you configure withCELER_DISABLE_DEVICE=1set, every:gpug4 test stays disabled even after you unset it. Reconfigure withcmake -U CELERITAS_DISABLE_DEVICE.Remaining GPU checks
To reproduce:
Then run celer-sim with
"action_times": true(and optionally withsync_stream) and compare the action times against the previous synchronous numbers. Expect similar kernel-dominated times and a lower total wall time.Things to watch:
Items 1–3 were verified on CUDA (V100). They are still unchecked on HIP. Items 4–5 have shown no failures, but they have not been profiled.
DeviceEventTest.timing✅ CUDA: theEXPECT_THROWon a pending event assumescudaEventElapsedTimereturnscudaErrorNotReady, whichCELER_DEVICE_API_CALLthrows and clears. If HIP reports this differently, drop that check.StreamTimerTest.device✅ CUDA: timing comes from host functions (launch_host_func) that sleep. Tolerances are 25% relative, and the record loop must take under 100 ms. IfcudaLaunchHostFuncturns out to serialize the host in a way that breaks the "doesn't block" check, loosen or remove it.ActionTimesTest.device✅ CUDA (all labels > 0): if any listed label has zero time on device, the action was probably skipped or launched nothing. Adjust the list instead of the implementation.ActionTimesState<device>looks updevice().stream(stream_id)on each call, and keeps only theStreamId, because tests callcreate_streamsagain. Events recorded on an old stream are still valid forcudaEventElapsedTime.transport_implcallsbegin_step()on the action times every optical step, so each step flushes the previous step's events. That should be free, since the counters were already waited on. Check with nsys that no extracudaEventSynchronizestalls show up between optical steps.🤖 (Claude Code, Opus 5.5)
🤖 Generated with Claude Code