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

Add along-step and tracking cut optical executors #1540

Merged
merged 9 commits into from
Dec 10, 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
4 changes: 3 additions & 1 deletion src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ celeritas_polysource(neutron/model/ChipsNeutronElasticModel)
celeritas_polysource(neutron/model/NeutronInelasticModel)
celeritas_polysource(optical/model/AbsorptionModel)
celeritas_polysource(optical/model/RayleighModel)
celeritas_polysource(optical/action/AlongStepAction)
celeritas_polysource(optical/action/BoundaryAction)
celeritas_polysource(optical/action/detail/TrackInitAlgorithms)
celeritas_polysource(optical/action/InitializeTracksAction)
celeritas_polysource(optical/action/PreStepAction)
celeritas_polysource(optical/action/TrackingCutAction)
celeritas_polysource(optical/action/detail/TrackInitAlgorithms)
celeritas_polysource(optical/detail/CherenkovGeneratorAction)
celeritas_polysource(optical/detail/CherenkovOffloadAction)
celeritas_polysource(optical/detail/OpticalGenAlgorithms)
Expand Down
18 changes: 14 additions & 4 deletions src/celeritas/optical/CoreParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#include "CoreState.hh"
#include "MaterialParams.hh"
#include "TrackInitParams.hh"
#include "action/AlongStepAction.hh"
#include "action/BoundaryAction.hh"
#include "action/InitializeTracksAction.hh"
#include "action/LocateVacanciesAction.hh"
#include "action/PreStepAction.hh"
#include "action/TrackingCutAction.hh"

namespace celeritas
{
Expand Down Expand Up @@ -71,15 +73,23 @@ CoreScalars build_actions(ActionRegistry* reg)

reg->insert(make_shared<PreStepAction>(reg->next_id()));

//// ALONG-STEP ACTIONS ////

reg->insert(make_shared<AlongStepAction>(reg->next_id()));

//// POST-STEP ACTIONS ////

// Construct geometry boundary action
// TODO: it might make more sense to build these actions right before
// making the action group: re-examine once we add a surface physics
// manager
// TODO: process selection action (or constructed by physics?)

// TODO: it might make more sense to build the surface crossing action
// right before making the action group: re-examine once we add a surface
// physics manager
scalars.boundary_action = reg->next_id();
reg->insert(make_shared<BoundaryAction>(scalars.boundary_action));

scalars.tracking_cut_action = reg->next_id();
reg->insert(make_shared<TrackingCutAction>(scalars.tracking_cut_action));

//// END ACTIONS ////

reg->insert(make_shared<LocateVacanciesAction>(reg->next_id()));
Expand Down
1 change: 1 addition & 0 deletions src/celeritas/optical/CoreTrackData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct CoreScalars
// TODO: maybe replace with a surface crossing manager to handle boundary
// conditions (see CoreParams.cc)
ActionId boundary_action;
ActionId tracking_cut_action;

StreamId::size_type max_streams{0};

Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/optical/OffloadData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace celeritas
/*!
* Current sizes of the buffers of distribution data.
*
* These sizes are updated by value on the host at each step.
* These sizes are updated by value on the host at each core step.
*/
struct OffloadBufferSize
{
Expand Down
6 changes: 3 additions & 3 deletions src/celeritas/optical/ParticleTrackView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Properties of a single particle track.
* Properties of a single optical photon.
*/
class ParticleTrackView
{
Expand Down Expand Up @@ -49,10 +49,10 @@ class ParticleTrackView
// Access the polarization
CELER_FORCEINLINE_FUNCTION Real3 const& polarization() const;

// Change the particle's energy [MeV]
// Change the photon's energy [MeV]
inline CELER_FUNCTION void energy(Energy);

// Change the particle's polarization
// Change the photon's polarization
inline CELER_FUNCTION void polarization(Real3 const&);

private:
Expand Down
56 changes: 56 additions & 0 deletions src/celeritas/optical/action/AlongStepAction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//----------------------------------*-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/optical/action/AlongStepAction.cc
//---------------------------------------------------------------------------//
#include "AlongStepAction.hh"

#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"

#include "ActionLauncher.hh"
#include "TrackSlotExecutor.hh"

#include "detail/AlongStepExecutor.hh"
#include "detail/PropagateExecutor.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Construct with action ID.
*/
AlongStepAction::AlongStepAction(ActionId aid)
: StaticConcreteAction(aid, "along-step", "move to interaction or boundary")
{
}

//---------------------------------------------------------------------------//
/*!
* Launch the boundary action on host.
*/
void AlongStepAction::step(CoreParams const& params, CoreStateHost& state) const
{
auto propagate_and_update = [](CoreTrackView& track) {
detail::PropagateExecutor{}(track);
detail::AlongStepExecutor{}(track);
};
auto execute = make_active_thread_executor(
params.ptr<MemSpace::native>(), state.ptr(), propagate_and_update);
return launch_action(state, execute);
}

#if !CELER_USE_DEVICE
void AlongStepAction::step(CoreParams const&, CoreStateDevice&) const
{
CELER_NOT_CONFIGURED("CUDA OR HIP");
}
#endif

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
56 changes: 56 additions & 0 deletions src/celeritas/optical/action/AlongStepAction.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//---------------------------------*-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/optical/action/AlongStepAction.cu
//---------------------------------------------------------------------------//
#include "AlongStepAction.hh"

#include "corecel/io/Logger.hh"
#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"

#include "ActionLauncher.device.hh"
#include "TrackSlotExecutor.hh"

#include "detail/AlongStepExecutor.hh"
#include "detail/PropagateExecutor.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Launch the along-step action on device.
*/
void AlongStepAction::step(CoreParams const& params,
CoreStateDevice& state) const
{
{
// Propagate
auto execute
= make_active_thread_executor(params.ptr<MemSpace::native>(),
state.ptr(),
detail::PropagateExecutor{});

static ActionLauncher<decltype(execute)> const launch_kernel(
*this, "propagate");
launch_kernel(state, execute);
}
{
// Update state
auto execute
= make_active_thread_executor(params.ptr<MemSpace::native>(),
state.ptr(),
detail::AlongStepExecutor{});

static ActionLauncher<decltype(execute)> const launch_kernel(*this);
launch_kernel(state, execute);
}
}

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
39 changes: 39 additions & 0 deletions src/celeritas/optical/action/AlongStepAction.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//----------------------------------*-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/optical/action/AlongStepAction.hh
//---------------------------------------------------------------------------//
#pragma once

#include "ActionInterface.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Move a track to the next boundary or interaction.
*/
class AlongStepAction final : public OpticalStepActionInterface,
public StaticConcreteAction
{
public:
// Construct with ID
explicit AlongStepAction(ActionId);

// Launch kernel with host data
void step(CoreParams const&, CoreStateHost&) const final;

// Launch kernel with device data
void step(CoreParams const&, CoreStateDevice&) const final;

//! Dependency ordering of the action
StepActionOrder order() const final { return StepActionOrder::along; }
};

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
56 changes: 56 additions & 0 deletions src/celeritas/optical/action/TrackingCutAction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//----------------------------------*-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/optical/action/TrackingCutAction.cc
//---------------------------------------------------------------------------//
#include "TrackingCutAction.hh"

#include "corecel/io/Logger.hh"
#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"

#include "ActionLauncher.hh"
#include "TrackSlotExecutor.hh"

#include "detail/TrackingCutExecutor.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Construct with action ID.
*/
TrackingCutAction::TrackingCutAction(ActionId aid)
: StaticConcreteAction(
aid, "tracking-cut", "kill a track and deposit its energy")
{
}

//---------------------------------------------------------------------------//
/*!
* Launch the boundary action on host.
sethrj marked this conversation as resolved.
Show resolved Hide resolved
*/
void TrackingCutAction::step(CoreParams const& params,
CoreStateHost& state) const
{
auto execute = make_action_thread_executor(params.ptr<MemSpace::native>(),
state.ptr(),
this->action_id(),
detail::TrackingCutExecutor{});
return launch_action(state, execute);
}

#if !CELER_USE_DEVICE
void TrackingCutAction::step(CoreParams const&, CoreStateDevice&) const
{
CELER_NOT_CONFIGURED("CUDA OR HIP");
}
#endif

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
41 changes: 41 additions & 0 deletions src/celeritas/optical/action/TrackingCutAction.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//---------------------------------*-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/optical/action/TrackingCutAction.cu
//---------------------------------------------------------------------------//
#include "TrackingCutAction.hh"

#include "corecel/io/Logger.hh"
#include "celeritas/optical/CoreParams.hh"
#include "celeritas/optical/CoreState.hh"

#include "ActionLauncher.device.hh"
#include "TrackSlotExecutor.hh"

#include "detail/TrackingCutExecutor.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Launch the tracking cut action on device.
*/
void TrackingCutAction::step(CoreParams const& params,
CoreStateDevice& state) const
{
auto execute = make_action_thread_executor(params.ptr<MemSpace::native>(),
state.ptr(),
this->action_id(),
detail::TrackingCutExecutor{});

static ActionLauncher<decltype(execute)> const launch_kernel(*this);
launch_kernel(state, execute);
}

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
39 changes: 39 additions & 0 deletions src/celeritas/optical/action/TrackingCutAction.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//----------------------------------*-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/optical/action/TrackingCutAction.hh
//---------------------------------------------------------------------------//
#pragma once

#include "ActionInterface.hh"

namespace celeritas
{
namespace optical
{
//---------------------------------------------------------------------------//
/*!
* Kill misbehaving photons and deposit energy locally.
*/
class TrackingCutAction final : public OpticalStepActionInterface,
public StaticConcreteAction
{
public:
// Construct with ID
explicit TrackingCutAction(ActionId);

// Launch kernel with host data
void step(CoreParams const&, CoreStateHost&) const final;

// Launch kernel with device data
void step(CoreParams const&, CoreStateDevice&) const final;

//! Dependency ordering of the action
StepActionOrder order() const final { return StepActionOrder::post; }
};

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
Loading
Loading