Skip to content
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

Define a "unique event ID" different from event counter #1447

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions src/accel/LocalTransporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void LocalTransporter::InitializeEvent(int id)
CELER_EXPECT(*this);
CELER_EXPECT(id >= 0);

event_id_ = EventId(id);
event_id_ = UniqueEventId(id);
track_counter_ = 0;

if (!(G4Threading::IsMultithreadedApplication()
Expand All @@ -166,7 +166,6 @@ void LocalTransporter::InitializeEvent(int id)
void LocalTransporter::Push(G4Track const& g4track)
{
CELER_EXPECT(*this);
CELER_EXPECT(event_id_);

Primary track;

Expand Down Expand Up @@ -199,7 +198,7 @@ void LocalTransporter::Push(G4Track const& g4track)
* back to Geant4.
*/
track.track_id = TrackId{track_counter_++};
track.event_id = event_id_;
track.event_id = EventId{0};
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is just temporary, and the plan is to set the Celeritas event ID from a global counter and to reset the (single, local) sim data track counter at the start of a new event? And I guess until we do that our track IDs won't be meaningful...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, the next PR will include a function to reset these at every event. Track IDs aren't currently very meaningful anyway since they're nondeterministic.


buffer_.push_back(track);
if (buffer_.size() >= auto_flush_)
Expand Down
2 changes: 1 addition & 1 deletion src/accel/LocalTransporter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LocalTransporter
std::vector<Primary> buffer_;
std::shared_ptr<detail::HitProcessor> hit_processor_;

EventId event_id_;
UniqueEventId event_id_;
TrackId::size_type track_counter_{};

size_type auto_flush_{};
Expand Down
5 changes: 4 additions & 1 deletion src/celeritas/Types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ namespace celeritas
//! Opaque index to ElementRecord in the global vector of elements
using ElementId = OpaqueId<struct ElementRecord>;

//! Counter for the initiating event for a track
//! Zero-indexed counter for the initiating event for a track
using EventId = OpaqueId<struct Event_>;

//! Unique identifier for an event used by external applications
using UniqueEventId = OpaqueId<struct Event_, std::uint64_t>;

//! Opaque index to IsotopeRecord in a vector
using IsotopeId = OpaqueId<struct IsotopeRecord>;

Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/global/Stepper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ auto Stepper<M>::operator()(SpanConstPrimary primaries) -> result_type
* reproduced.
*/
template<MemSpace M>
void Stepper<M>::reseed(EventId event_id)
void Stepper<M>::reseed(UniqueEventId event_id)
{
reseed_rng(get_ref<M>(*params_->rng()), state_->ref().rng, event_id.get());
reseed_rng(get_ref<M>(*params_->rng()), state_->ref().rng, event_id);
}

//---------------------------------------------------------------------------//
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/global/Stepper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class StepperInterface
virtual StepperResult operator()(SpanConstPrimary primaries) = 0;

// Reseed the RNGs at the start of an event for reproducibility
virtual void reseed(EventId event_id) = 0;
virtual void reseed(UniqueEventId event_id) = 0;

//! Get action sequence for timing diagnostics
virtual ActionSequenceT const& actions() const = 0;
Expand Down Expand Up @@ -166,7 +166,7 @@ class Stepper final : public StepperInterface
StepperResult operator()(SpanConstPrimary primaries) final;

// Reseed the RNGs at the start of an event for reproducibility
void reseed(EventId event_id) final;
void reseed(UniqueEventId event_id) final;

//! Get action sequence for timing diagnostics
ActionSequenceT const& actions() const final { return *actions_; }
Expand Down
9 changes: 6 additions & 3 deletions src/celeritas/random/RngReseed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ namespace celeritas
*/
void reseed_rng(HostCRef<RngParamsData> const& params,
HostRef<RngStateData> const& state,
size_type event_id)
UniqueEventId event_id)
{
auto size = state.size();
CELER_EXPECT(event_id);
static_assert(sizeof(ull_int) == sizeof(UniqueEventId::size_type));

ull_int size = state.size();
#if CELERITAS_OPENMP == CELERITAS_OPENMP_TRACK
# pragma omp parallel for
#endif
for (TrackSlotId::size_type i = 0; i < size; ++i)
{
RngEngine::Initializer_t init;
init.seed = params.seed;
init.subsequence = event_id * size + i;
init.subsequence = event_id.unchecked_get() * size + i;
RngEngine engine(params, state, TrackSlotId{i});
engine = init;
}
Expand Down
7 changes: 4 additions & 3 deletions src/celeritas/random/RngReseed.cu
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace
*/
__global__ void reseed_rng_kernel(DeviceCRef<RngParamsData> const params,
DeviceRef<RngStateData> const state,
size_type event_id)
UniqueEventId::size_type event_id)
{
auto tid = TrackSlotId{
celeritas::KernelParamCalculator::thread_id().unchecked_get()};
Expand Down Expand Up @@ -57,11 +57,12 @@ __global__ void reseed_rng_kernel(DeviceCRef<RngParamsData> const params,
*/
void reseed_rng(DeviceCRef<RngParamsData> const& params,
DeviceRef<RngStateData> const& state,
size_type event_id)
UniqueEventId event_id)
{
CELER_EXPECT(state);
CELER_EXPECT(params);
CELER_LAUNCH_KERNEL(reseed_rng, state.size(), 0, params, state, event_id);
CELER_LAUNCH_KERNEL(
reseed_rng, state.size(), 0, params, state, event_id.get());
}

//---------------------------------------------------------------------------//
Expand Down
7 changes: 4 additions & 3 deletions src/celeritas/random/RngReseed.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "corecel/Macros.hh"
#include "corecel/Types.hh"
#include "corecel/data/Collection.hh"
#include "celeritas/Types.hh"

#include "RngData.hh"

Expand All @@ -20,11 +21,11 @@ namespace celeritas
// Reinitialize the RNG states on host/device at the start of an event
void reseed_rng(DeviceCRef<RngParamsData> const&,
DeviceRef<RngStateData> const&,
size_type);
UniqueEventId);

void reseed_rng(HostCRef<RngParamsData> const&,
HostRef<RngStateData> const&,
size_type);
UniqueEventId);

#if !CELER_USE_DEVICE
//---------------------------------------------------------------------------//
Expand All @@ -33,7 +34,7 @@ void reseed_rng(HostCRef<RngParamsData> const&,
*/
inline void reseed_rng(DeviceCRef<RngParamsData> const&,
DeviceRef<RngStateData> const&,
size_type)
UniqueEventId)
{
CELER_ASSERT_UNREACHABLE();
}
Expand Down
4 changes: 2 additions & 2 deletions test/celeritas/random/RngReseed.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST_F(RngReseedTest, reseed)
RngHostStore states(params->host_ref(), StreamId{0}, size);

size_type id = 8;
reseed_rng(params->host_ref(), states.ref(), id);
reseed_rng(params->host_ref(), states.ref(), UniqueEventId{id});

RngEngine::Initializer_t init;
init.seed = params->host_ref().seed;
Expand All @@ -55,7 +55,7 @@ TEST_F(RngReseedTest, reseed)
ASSERT_EQ(skip_rng(), rng());
}

reseed_rng(params->host_ref(), states.ref(), id);
reseed_rng(params->host_ref(), states.ref(), UniqueEventId{id});
std::vector<unsigned int> values;
for (auto i : range(states.size()).step(128u))
{
Expand Down
Loading