-
Notifications
You must be signed in to change notification settings - Fork 45
Offload optical photons from Geant4 to optical track #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Rashika-Gupta
wants to merge
29
commits into
celeritas-project:develop
Choose a base branch
from
Rashika-Gupta:optical-steps
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
735cbc6
Optical track offloadin inherited from LocalOffloadInterface
Rashika-Gupta 2eb5c36
Add track-offload option and replace LocalOffloadinterface with Track…
Rashika-Gupta 29c8c14
Add optical track-offload option and integrate with constructor
Rashika-Gupta a96adc1
Modify the track info in push
Rashika-Gupta 7603078
Fix vecgeom 2.x with CUDA (#2136)
sethrj 1544ae7
WIP
Rashika-Gupta 89c4601
Add OpticalTrackOffload option in problem
Rashika-Gupta db5ea62
change push parameter
Rashika-Gupta 3054a37
Flush and Push logs
Rashika-Gupta 0b44367
Optical track offload test
Rashika-Gupta 4d6d600
log number of optical tracks
Rashika-Gupta d8f1b58
remove debug statements
Rashika-Gupta e1d4ab5
Move tracking action to test case
Rashika-Gupta e6272d0
fixes for floating precision
Rashika-Gupta d62f9df
Change name to LocalOpticalGenOffload from LocalOpticalOffload
Rashika-Gupta 91c9469
cleanup
Rashika-Gupta e353eb5
Merge upstream/develop
sethrj 036d4ea
Added EndOfRunAction
Rashika-Gupta 369bc1e
Integrate optical problem input changes
Rashika-Gupta e03b0ba
Address comments
Rashika-Gupta d9c004b
Merge remote-tracking branch 'upstream/develop' into optical-steps
sethrj ece5cf6
Push to generic interface, delete debug code
sethrj 5566457
Fix merge errors
sethrj 197574b
REVERTME: delete LocalOpticalTrackOffload
sethrj 4c6fbd7
More removal
sethrj 2a40d8d
No special case for offload
sethrj a513957
tweaks
sethrj b210b26
This reverts commit 197574b72fc4e7bf051ffefb30222a5bb79cbf6e.
Rashika-Gupta 7498929
Merge upstream/develop
sethrj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| //------------------------------- -*- C++ -*- -------------------------------// | ||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| //---------------------------------------------------------------------------// | ||
| //! \file accel/LocalOpticalTrackOffload.cc | ||
| //---------------------------------------------------------------------------// | ||
| #include "LocalOpticalTrackOffload.hh" | ||
|
|
||
| #include <G4EventManager.hh> | ||
| #include <G4MTRunManager.hh> | ||
|
|
||
| #include "corecel/Assert.hh" | ||
| #include "corecel/sys/ScopedProfiling.hh" | ||
| #include "geocel/GeantUtils.hh" | ||
| #include "celeritas/global/CoreParams.hh" | ||
| #include "celeritas/optical/CoreParams.hh" | ||
| #include "celeritas/optical/Transporter.hh" | ||
|
|
||
| #include "SetupOptions.hh" | ||
| #include "SharedParams.hh" | ||
|
|
||
| namespace celeritas | ||
| { | ||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Offload Geant4 optical photon tracks to Celeritas | ||
| */ | ||
| LocalOpticalTrackOffload::LocalOpticalTrackOffload(SetupOptions const& options, | ||
| SharedParams& params) | ||
| { | ||
| CELER_VALIDATE(params.mode() == SharedParams::Mode::enabled, | ||
| << "cannot create local optical track offload when " | ||
| "Celeritas " | ||
| "offloading is disabled"); | ||
|
|
||
| // Save a pointer to the optical transporter | ||
| transport_ = params.optical_problem_loaded().transporter; | ||
|
|
||
| CELER_ASSERT(transport_); | ||
| CELER_ASSERT(transport_->params()); | ||
|
|
||
| auto const& optical_params = *transport_->params(); | ||
|
|
||
| // Check the thread ID and MT model | ||
| validate_geant_threading(optical_params.max_streams()); | ||
|
|
||
| CELER_EXPECT(options.optical); | ||
| auto const& capacity = options.optical->capacity; | ||
| auto_flush_ = capacity.tracks; | ||
|
|
||
| auto stream_id = id_cast<StreamId>(get_geant_thread_id()); | ||
|
|
||
| // Allocate thread-local state data | ||
| auto memspace = celeritas::device() ? MemSpace::device : MemSpace::host; | ||
| if (memspace == MemSpace::device) | ||
| { | ||
| state_ = std::make_shared<optical::CoreState<MemSpace::device>>( | ||
| optical_params, stream_id, capacity.tracks); | ||
| } | ||
| else | ||
| { | ||
| state_ = std::make_shared<optical::CoreState<MemSpace::host>>( | ||
| optical_params, stream_id, capacity.tracks); | ||
| } | ||
|
|
||
| // Allocate auxiliary data | ||
| if (optical_params.aux_reg()) | ||
| { | ||
| state_->aux() = std::make_shared<AuxStateVec>( | ||
| *optical_params.aux_reg(), memspace, stream_id, capacity.tracks); | ||
| } | ||
|
|
||
| CELER_ENSURE(*this); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Initialize with options and shared data. | ||
| */ | ||
| void LocalOpticalTrackOffload::Initialize(SetupOptions const& options, | ||
| SharedParams& params) | ||
| { | ||
| *this = LocalOpticalTrackOffload(options, params); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Set the event ID and reseed the Celeritas RNG at the start of an event. | ||
| */ | ||
| void LocalOpticalTrackOffload::InitializeEvent(int id) | ||
| { | ||
| CELER_EXPECT(*this); | ||
| CELER_EXPECT(id >= 0); | ||
|
|
||
| event_id_ = id_cast<UniqueEventId>(id); | ||
| if (!(G4Threading::IsMultithreadedApplication() | ||
| && G4MTRunManager::SeedOncePerCommunication())) | ||
| { | ||
| // Since Geant4 schedules events dynamically, reseed the Celeritas | ||
| // RNGs | ||
| // using the Geant4 event ID for reproducibility. This guarantees | ||
| // that | ||
| // an event can be reproduced given the event ID. | ||
| state_->reseed(transport_->params()->rng(), id_cast<UniqueEventId>(id)); | ||
| } | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Buffer optical tracks. | ||
| */ | ||
| void LocalOpticalTrackOffload::Push(G4Track& g4track) | ||
| { | ||
| CELER_EXPECT(*this); | ||
|
|
||
| ++num_pushed_; | ||
|
|
||
| CELER_EXPECT(g4track.GetDefinition()); | ||
| CELER_EXPECT(g4track.GetDefinition()->GetParticleName() == "opticalphoton"); | ||
|
|
||
| // TODO : Populate optical::TrackInitializer from Geant4 Track | ||
| TrackData init; | ||
|
|
||
| ScopedProfiling profile_this{"push"}; | ||
|
|
||
| buffer_.push_back(init); | ||
|
|
||
| if (buffer_.size() >= auto_flush_) | ||
| { | ||
| this->Flush(); | ||
| } | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Flush buffered optical photon tracks. | ||
| */ | ||
| void LocalOpticalTrackOffload::Flush() | ||
| { | ||
| CELER_EXPECT(*this); | ||
|
|
||
| if (buffer_.empty()) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Number of flushed optical tracks | ||
| ++num_flushed_; | ||
|
|
||
| // TODO insert buffered track into | ||
| // optical CoreState and execute optical transport. | ||
| // state_->insert_primaries(make_span(buffer_)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And still need to offload the buffered tracks here. |
||
|
|
||
| buffer_.clear(); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| auto LocalOpticalTrackOffload::GetActionTime() const -> MapStrDbl | ||
| { | ||
| CELER_EXPECT(*this); | ||
| // TODO Add Per-track optical transport action timing once | ||
| // optical track insertion and transport are implemented. | ||
| return transport_->get_action_times(*state_->aux()); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Finalize the local optical track offload state | ||
| */ | ||
| void LocalOpticalTrackOffload::Finalize() | ||
| { | ||
| CELER_EXPECT(*this); | ||
|
|
||
| CELER_VALIDATE(buffer_.empty(), | ||
| << buffer_.size() << " optical tracks were not flushed"); | ||
|
|
||
| CELER_LOG(info) << "Finalizing Celeritas after " << num_pushed_ | ||
| << " optical tracks pushed (over " << num_flushed_ | ||
| << " ) flushes"; | ||
|
|
||
| *this = {}; | ||
|
|
||
| CELER_ENSURE(!*this); | ||
| } | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| } // namespace celeritas | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| //------------------------------- -*- C++ -*- -------------------------------// | ||
| // Copyright Celeritas contributors: see top-level COPYRIGHT file for details | ||
| // SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| //---------------------------------------------------------------------------// | ||
| //! \file accel/LocalOpticalTrackOffload.hh | ||
| //---------------------------------------------------------------------------// | ||
| #pragma once | ||
|
|
||
| #include "corecel/Types.hh" | ||
| #include "celeritas/Types.hh" | ||
| #include "celeritas/optical/TrackInitializer.hh" | ||
|
|
||
| #include "TrackOffloadInterface.hh" | ||
|
|
||
| namespace celeritas | ||
| { | ||
| namespace optical | ||
| { | ||
| class CoreStateBase; | ||
| class Transporter; | ||
| } // namespace optical | ||
|
|
||
| struct SetupOptions; | ||
| class SharedParams; | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| /*! | ||
| * Offload Geant4 optical photon tracks to Celeritas. | ||
| */ | ||
| class LocalOpticalTrackOffload final : public TrackOffloadInterface | ||
| { | ||
| public: | ||
| //!@{ | ||
| //! \name Type aliases | ||
| using TrackData = optical::TrackInitializer; | ||
| //!@} | ||
|
|
||
| public: | ||
| // Construct in an invalid state | ||
| LocalOpticalTrackOffload() = default; | ||
|
|
||
| // Construct with shared (across threads) params | ||
| LocalOpticalTrackOffload(SetupOptions const& options, SharedParams& params); | ||
|
|
||
| //!@{ | ||
| //! \name TrackOffloadInterface | ||
|
|
||
| // Initialize with options and shared data | ||
| void Initialize(SetupOptions const&, SharedParams&) final; | ||
|
|
||
| // Set the event ID and reseed the Celeritas RNG at the start of an event | ||
| void InitializeEvent(int) final; | ||
|
|
||
| // Transport all buffered tracks to completion | ||
| void Flush() final; | ||
|
|
||
| // Clear local data and return to an invalid state | ||
| void Finalize() final; | ||
|
|
||
| // Whether the class instance is initialized | ||
| bool Initialized() const final { return static_cast<bool>(transport_); } | ||
|
|
||
| // Number of buffered tracks | ||
| size_type GetBufferSize() const final { return buffer_.size(); } | ||
|
|
||
| // Get accumulated action times | ||
| MapStrDbl GetActionTime() const final; | ||
| //!@} | ||
|
|
||
| // Offload optical distribution track to Celeritas | ||
| void Push(G4Track&) final; | ||
|
|
||
| private: | ||
| // Transport pending optical tracks | ||
| std::shared_ptr<optical::Transporter> transport_; | ||
|
|
||
| // Thread-local state data | ||
| std::shared_ptr<optical::CoreStateBase> state_; | ||
|
|
||
| // Buffered tracks for offloading | ||
| std::vector<TrackData> buffer_; | ||
|
|
||
| // Number of photons tracks to buffer before offloading | ||
| size_type auto_flush_{}; | ||
|
|
||
| // Accumulated number of optical photon tracks | ||
| size_type num_pushed_{}; | ||
|
|
||
| // Accumulated number of tracks pushed over flushes | ||
| size_type num_flushed_{}; | ||
|
|
||
| // Current event ID for obtaining it | ||
| UniqueEventId event_id_; | ||
| }; | ||
|
|
||
| //---------------------------------------------------------------------------// | ||
| } // namespace celeritas |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to populate the track initializer here.