-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor track initialization code (#240)
* Use collections for track initializer interface * Separate track initialization data storage from functionality * Template TrackInterface on Ownership and MemSpace and remove State/ParamStore * Address reviewer feedback
- Loading branch information
1 parent
2e9ec21
commit 4d58a41
Showing
24 changed files
with
909 additions
and
768 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2021 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file TrackInitInterface.cc | ||
//---------------------------------------------------------------------------// | ||
#include "TrackInitInterface.hh" | ||
|
||
#include "base/Assert.hh" | ||
#include "base/CollectionBuilder.hh" | ||
#include "comm/Device.hh" | ||
|
||
namespace celeritas | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Resize and initialize track initializer data on device. | ||
*/ | ||
void resize( | ||
TrackInitStateData<Ownership::value, MemSpace::device>* data, | ||
const TrackInitParamsData<Ownership::const_reference, MemSpace::host>& params, | ||
size_type size) | ||
{ | ||
CELER_EXPECT(params); | ||
CELER_EXPECT(size > 0); | ||
CELER_EXPECT(celeritas::device()); | ||
|
||
// Allocate device data | ||
auto capacity = params.storage_factor * size; | ||
make_builder(&data->initializers.storage).resize(capacity); | ||
make_builder(&data->parents.storage).resize(capacity); | ||
make_builder(&data->secondary_counts).resize(size); | ||
|
||
// Start with an empty vector of track initializers and parent thread IDs | ||
data->initializers.resize(0); | ||
data->parents.resize(0); | ||
|
||
// Initialize vacancies to mark all track slots as empty | ||
StateCollection<size_type, Ownership::value, MemSpace::host> vacancies; | ||
make_builder(&vacancies).resize(size); | ||
for (auto i : range(ThreadId{size})) | ||
vacancies[i] = i.get(); | ||
data->vacancies.storage = vacancies; | ||
data->vacancies.resize(size); | ||
|
||
// Initialize the track counter for each event as the number of primary | ||
// particles in that event | ||
Collection<TrackId::size_type, Ownership::value, MemSpace::host, EventId> | ||
track_counters; | ||
for (const auto& p : params.primaries[AllItems<Primary, MemSpace::host>{}]) | ||
{ | ||
const auto event_id = p.event_id; | ||
if (!(event_id < track_counters.size())) | ||
{ | ||
make_builder(&track_counters).resize(event_id.get() + 1); | ||
} | ||
++track_counters[event_id]; | ||
} | ||
data->track_counters = track_counters; | ||
data->num_primaries = params.primaries.size(); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Resize and initialize track initializer data on host. | ||
*/ | ||
void resize( | ||
TrackInitStateData<Ownership::value, MemSpace::host>*, | ||
const TrackInitParamsData<Ownership::const_reference, MemSpace::host>&, | ||
size_type) | ||
{ | ||
CELER_NOT_IMPLEMENTED("Host track initializer state"); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace celeritas |
Oops, something went wrong.