-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly clear state counters and data for reuse (#1367)
* Add a helper method to reset state data * Add a generic function to fill a collection with a sequence * Move track shuffle util to global/detail
- Loading branch information
1 parent
ac99201
commit 1e4aa73
Showing
18 changed files
with
208 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 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/global/detail/TrackSlotUtils.cc | ||
//---------------------------------------------------------------------------// | ||
#include "TrackSlotUtils.hh" | ||
|
||
#include <algorithm> | ||
#include <random> | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Shuffle track slot indices. | ||
*/ | ||
void shuffle_track_slots( | ||
Collection<TrackSlotId::size_type, Ownership::value, MemSpace::host, ThreadId>* | ||
track_slots, | ||
StreamId) | ||
{ | ||
CELER_EXPECT(track_slots); | ||
auto* start | ||
= static_cast<TrackSlotId::size_type*>(track_slots->data().get()); | ||
auto seed = static_cast<unsigned int>(track_slots->size()); | ||
std::mt19937 g{seed}; | ||
std::shuffle(start, start + track_slots->size(), g); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // 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,42 @@ | ||
//---------------------------------*-CUDA-*----------------------------------// | ||
// Copyright 2024 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/global/detail/TrackSlotUtils.cu | ||
//---------------------------------------------------------------------------// | ||
#include "TrackSlotUtils.hh" | ||
|
||
#include <thrust/device_ptr.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/random.h> | ||
#include <thrust/shuffle.h> | ||
|
||
#include "corecel/sys/Thrust.device.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Shuffle track slot indices. | ||
*/ | ||
void shuffle_track_slots( | ||
Collection<TrackSlotId::size_type, Ownership::value, MemSpace::device, ThreadId>* | ||
track_slots, | ||
StreamId stream) | ||
{ | ||
CELER_EXPECT(track_slots); | ||
using result_type = thrust::default_random_engine::result_type; | ||
thrust::default_random_engine g{ | ||
static_cast<result_type>(track_slots->size())}; | ||
auto start = thrust::device_pointer_cast(track_slots->data().get()); | ||
thrust::shuffle( | ||
thrust_execute_on(stream), start, start + track_slots->size(), g); | ||
CELER_DEVICE_CHECK_ERROR(); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // 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,42 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 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/global/detail/TrackSlotUtils.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include "corecel/Assert.hh" | ||
#include "corecel/Macros.hh" | ||
#include "corecel/Types.hh" | ||
#include "corecel/data/Collection.hh" | ||
#include "corecel/sys/ThreadId.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace detail | ||
{ | ||
//---------------------------------------------------------------------------// | ||
// Shuffle track slot indices | ||
void shuffle_track_slots( | ||
Collection<TrackSlotId::size_type, Ownership::value, MemSpace::host, ThreadId>*, | ||
StreamId); | ||
void shuffle_track_slots( | ||
Collection<TrackSlotId::size_type, Ownership::value, MemSpace::device, ThreadId>*, | ||
StreamId); | ||
|
||
//---------------------------------------------------------------------------// | ||
// INLINE DEFINITIONS | ||
//---------------------------------------------------------------------------// | ||
#if !CELER_USE_DEVICE | ||
inline void shuffle_track_slots( | ||
Collection<TrackSlotId::size_type, Ownership::value, MemSpace::device, ThreadId>*, | ||
StreamId) | ||
{ | ||
CELER_NOT_CONFIGURED("CUDA or HIP"); | ||
} | ||
#endif | ||
//---------------------------------------------------------------------------// | ||
} // namespace detail | ||
} // 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
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.