Skip to content
Draft
Show file tree
Hide file tree
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 Dec 1, 2025
2eb5c36
Add track-offload option and replace LocalOffloadinterface with Track…
Rashika-Gupta Dec 3, 2025
29c8c14
Add optical track-offload option and integrate with constructor
Rashika-Gupta Dec 3, 2025
a96adc1
Modify the track info in push
Rashika-Gupta Dec 3, 2025
7603078
Fix vecgeom 2.x with CUDA (#2136)
sethrj Dec 2, 2025
1544ae7
WIP
Rashika-Gupta Dec 8, 2025
89c4601
Add OpticalTrackOffload option in problem
Rashika-Gupta Dec 16, 2025
db5ea62
change push parameter
Rashika-Gupta Dec 16, 2025
3054a37
Flush and Push logs
Rashika-Gupta Dec 17, 2025
0b44367
Optical track offload test
Rashika-Gupta Dec 17, 2025
4d6d600
log number of optical tracks
Rashika-Gupta Dec 18, 2025
d8f1b58
remove debug statements
Rashika-Gupta Dec 18, 2025
e1d4ab5
Move tracking action to test case
Rashika-Gupta Dec 18, 2025
e6272d0
fixes for floating precision
Rashika-Gupta Dec 18, 2025
d62f9df
Change name to LocalOpticalGenOffload from LocalOpticalOffload
Rashika-Gupta Dec 18, 2025
91c9469
cleanup
Rashika-Gupta Dec 19, 2025
e353eb5
Merge upstream/develop
sethrj Jan 25, 2026
036d4ea
Added EndOfRunAction
Rashika-Gupta Jan 25, 2026
369bc1e
Integrate optical problem input changes
Rashika-Gupta Jan 25, 2026
e03b0ba
Address comments
Rashika-Gupta Jan 25, 2026
d9c004b
Merge remote-tracking branch 'upstream/develop' into optical-steps
sethrj Jan 25, 2026
ece5cf6
Push to generic interface, delete debug code
sethrj Jan 26, 2026
5566457
Fix merge errors
sethrj Jan 26, 2026
197574b
REVERTME: delete LocalOpticalTrackOffload
sethrj Jan 26, 2026
4c6fbd7
More removal
sethrj Jan 26, 2026
2a40d8d
No special case for offload
sethrj Jan 26, 2026
a513957
tweaks
sethrj Jan 26, 2026
b210b26
This reverts commit 197574b72fc4e7bf051ffefb30222a5bb79cbf6e.
Rashika-Gupta Jan 26, 2026
7498929
Merge upstream/develop
sethrj Jan 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions src/accel/LocalOpticalTrackOffload.cc
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;
Copy link
Contributor

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.


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_));
Copy link
Contributor

Choose a reason for hiding this comment

The 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
97 changes: 97 additions & 0 deletions src/accel/LocalOpticalTrackOffload.hh
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
6 changes: 4 additions & 2 deletions src/accel/TrackingManagerConstructor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class TrackingManagerIntegration;
shared_params, [](int){ return &local_transporter; });
\endcode
*
* \note If Celeritas is globally disabled, it will not add the track manager.
* \note If Celeritas is globally disabled, it will not add the track
manager.
* If Celeritas is configured to "kill offload" mode (for testing maximum
* theoretical performance) then the tracking manager will be added but will
* theoretical performance) then the tracking manager will be added but
will
* not send the tracks to Celeritas: it will simply kill them.
*/
class TrackingManagerConstructor final : public G4VPhysicsConstructor
Expand Down
1 change: 1 addition & 0 deletions src/accel/detail/IntegrationSingleton.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>

#include "corecel/sys/Stopwatch.hh"
#include "accel/LocalOpticalTrackOffload.hh"

#include "../LocalOpticalGenOffload.hh"
#include "../LocalTransporter.hh"
Expand Down
7 changes: 7 additions & 0 deletions test/accel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ celeritas_add_integration_tests(
RMTYPE ${_optical_rm_type}
)

# Test with optical track offloading
celeritas_add_integration_tests(
UserActionIntegration LarSphereOpticalTrackOffload run
OFFLOAD cpu gpu g4
RMTYPE ${_optical_rm_type}
)

# Test optical surface physics
celeritas_add_integration_tests(
TrackingManagerIntegration OpticalSurfaces run
Expand Down
Loading
Loading