-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure reproducibility when using MT Geant4 with Celeritas offloading (…
…#1061) * Add kernel to reseed RNG states based on Geant4 event ID * Reseed Celeritas RNG at the start of an event in LocalTransporter * Add Celeritas step diagnostic to celer-g4 when offloading is enabled * Move RngReseed to celeritas/random * Use same type for RNG engine initializer seed and RNG params seed * Add a reseed method to stepper * Deprecate SetEventId and always reseed RNG * Always reseed RNGs in serial mode
- Loading branch information
1 parent
94fb9e4
commit bc3ccd5
Showing
16 changed files
with
307 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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,40 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2023 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file celeritas/random/RngReseed.cc | ||
//---------------------------------------------------------------------------// | ||
#include "RngReseed.hh" | ||
|
||
#include "corecel/cont/Range.hh" | ||
#include "corecel/sys/ThreadId.hh" | ||
|
||
#include "RngEngine.hh" | ||
|
||
namespace celeritas | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Reinitialize the RNG states on host at the start of an event. | ||
* | ||
* Each thread's state is initialized using same seed and skipped ahead a | ||
* different number of subsequences so the sequences on different threads will | ||
* not have statistically correlated values. | ||
*/ | ||
void reseed_rng(HostCRef<RngParamsData> const& params, | ||
HostRef<RngStateData> const& state, | ||
size_type event_id) | ||
{ | ||
for (auto tid : range(TrackSlotId{state.size()})) | ||
{ | ||
RngEngine::Initializer_t init; | ||
init.seed = params.seed; | ||
init.subsequence = event_id * state.size() + tid.get(); | ||
RngEngine engine(params, state, tid); | ||
engine = init; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
This file contains 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,67 @@ | ||
//---------------------------------*-CUDA-*----------------------------------// | ||
// Copyright 2023 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file celeritas/random/RngReseed.cu | ||
//---------------------------------------------------------------------------// | ||
#include "RngReseed.hh" | ||
|
||
#include "corecel/device_runtime_api.h" | ||
#include "corecel/Assert.hh" | ||
#include "corecel/sys/Device.hh" | ||
#include "corecel/sys/KernelParamCalculator.device.hh" | ||
|
||
#include "RngEngine.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace | ||
{ | ||
//---------------------------------------------------------------------------// | ||
// KERNELS | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Reinitialize the RNG states on device at the start of an event. | ||
*/ | ||
__global__ void reseed_rng_kernel(DeviceCRef<RngParamsData> const params, | ||
DeviceRef<RngStateData> const state, | ||
size_type event_id) | ||
{ | ||
auto tid = TrackSlotId{ | ||
celeritas::KernelParamCalculator::thread_id().unchecked_get()}; | ||
if (tid.get() < state.size()) | ||
{ | ||
TrackSlotId tsid{tid.unchecked_get()}; | ||
RngEngine::Initializer_t init; | ||
init.seed = params.seed; | ||
init.subsequence = event_id * state.size() + tsid.get(); | ||
RngEngine rng(params, state, tsid); | ||
rng = init; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace | ||
|
||
//---------------------------------------------------------------------------// | ||
// KERNEL INTERFACE | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Reinitialize the RNG states on device at the start of an event. | ||
* | ||
* Each thread's state is initialized using same seed and skipped ahead a | ||
* different number of subsequences so the sequences on different threads will | ||
* not have statistically correlated values. | ||
*/ | ||
void reseed_rng(DeviceCRef<RngParamsData> const& params, | ||
DeviceRef<RngStateData> const& state, | ||
size_type event_id) | ||
{ | ||
CELER_EXPECT(state); | ||
CELER_EXPECT(params); | ||
CELER_LAUNCH_KERNEL(reseed_rng, state.size(), 0, params, state, event_id); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
This file contains 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,43 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2023 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file celeritas/random/RngReseed.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "corecel/Assert.hh" | ||
#include "corecel/Macros.hh" | ||
#include "corecel/Types.hh" | ||
#include "corecel/data/Collection.hh" | ||
|
||
#include "RngData.hh" | ||
|
||
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); | ||
|
||
void reseed_rng(HostCRef<RngParamsData> const&, | ||
HostRef<RngStateData> const&, | ||
size_type); | ||
|
||
#if !CELER_USE_DEVICE | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Reinitialize the RNG states on device at the start of an event. | ||
*/ | ||
inline void reseed_rng(DeviceCRef<RngParamsData> const&, | ||
DeviceRef<RngStateData> const&, | ||
size_type) | ||
{ | ||
CELER_ASSERT_UNREACHABLE(); | ||
} | ||
#endif | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
This file contains 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 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 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.