Skip to content

Commit

Permalink
Add optical launch action
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Sep 1, 2024
1 parent 964f989 commit 3fca57f
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ list(APPEND SOURCES
optical/TrackData.cc
optical/ScintillationParams.cc
optical/detail/OffloadParams.cc
optical/detail/OpticalLaunchAction.cc
phys/CutoffParams.cc
phys/ImportedModelAdapter.cc
phys/ImportedProcessAdapter.cc
Expand Down
24 changes: 1 addition & 23 deletions src/celeritas/optical/CoreParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ CoreScalars build_actions(ActionRegistry* reg)
/*!
* Construct with all problem data, creating some actions too.
*/
CoreParams::CoreParams(AuxId aux_id, Input&& input)
: aux_id_{aux_id}, input_(std::move(input))
CoreParams::CoreParams(Input&& input) : input_(std::move(input))
{
#define CP_VALIDATE_INPUT(MEMBER) \
CELER_VALIDATE(input_.MEMBER, \
Expand Down Expand Up @@ -136,27 +135,6 @@ CoreParams::CoreParams(AuxId aux_id, Input&& input)
CELER_ENSURE(host_ref_.scalars.max_streams == this->max_streams());
}

//---------------------------------------------------------------------------//
/*!
* Build state data for a stream.
*/
auto CoreParams::create_state(MemSpace m,
StreamId sid,
size_type size) const -> UPState
{
if (m == MemSpace::host)
{
return UPState{
std::make_unique<CoreState<MemSpace::host>>(*this, sid, size)};
}
else if (m == MemSpace::device)
{
return UPState{
std::make_unique<CoreState<MemSpace::device>>(*this, sid, size)};
}
CELER_ASSERT_UNREACHABLE();
}

//---------------------------------------------------------------------------//
} // namespace optical
} // namespace celeritas
23 changes: 2 additions & 21 deletions src/celeritas/optical/CoreParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#pragma once

#include "corecel/Assert.hh"
#include "corecel/data/AuxInterface.hh"
#include "corecel/data/DeviceVector.hh"
#include "corecel/data/ObserverPtr.hh"
#include "corecel/data/ParamsDataInterface.hh"
Expand All @@ -34,12 +33,8 @@ class MaterialParams;
//---------------------------------------------------------------------------//
/*!
* Shared parameters for the optical photon loop.
*
* Because a copy of the core params can be stored in the main tracking loop,
* this class conforms to the "aux params" interface.
*/
class CoreParams final : public AuxParamsInterface,
public ParamsDataInterface<CoreParamsData>
class CoreParams final : public ParamsDataInterface<CoreParamsData>
{
public:
//!@{
Expand Down Expand Up @@ -81,20 +76,7 @@ class CoreParams final : public AuxParamsInterface,

public:
// Construct with all problem data, creating some actions too
CoreParams(AuxId aux_id, Input&& inp);

//! Construct for execution in a standalone loop (no aux ID)
explicit CoreParams(Input&& inp) : CoreParams{{}, std::move(inp)} {}

//!@{
//! \name Aux interface
//! Short name for the action
std::string_view label() const final { return "optical-offload"; }
//! Index of this class instance in its registry
AuxId aux_id() const final { return aux_id_; }
// Build state data for a stream
UPState create_state(MemSpace, StreamId, size_type) const final;
//!@}
CoreParams(Input&& inp);

//!@{
//! \name Data interface
Expand Down Expand Up @@ -124,7 +106,6 @@ class CoreParams final : public AuxParamsInterface,
size_type max_streams() const { return input_.max_streams; }

private:
AuxId aux_id_;
Input input_;
HostRef host_ref_;
DeviceRef device_ref_;
Expand Down
61 changes: 27 additions & 34 deletions src/celeritas/optical/OpticalCollector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
#include "OffloadData.hh"
#include "ScintillationParams.hh"

#include "detail/CerenkovOffloadAction.hh"
#include "detail/OffloadGatherAction.hh"
#include "detail/OffloadParams.hh"
#include "detail/OpticalLaunchAction.hh"
#include "detail/ScintOffloadAction.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Construct with core data and optical data.
*
* This adds several actions and auxiliary data to the registry.
*/
OpticalCollector::OpticalCollector(CoreParams const& core, Input&& inp)
{
Expand All @@ -37,21 +43,9 @@ OpticalCollector::OpticalCollector(CoreParams const& core, Input&& inp)
setup.capacity = inp.buffer_capacity;

// Create offload params
gen_params_ = std::make_shared<detail::OffloadParams>(
core.aux_reg()->next_id(), setup);
core.aux_reg()->insert(gen_params_);

// Create optical params
optical_params_ = std::make_shared<optical::CoreParams>(
core.aux_reg()->next_id(), [&inp, &core] {
optical::CoreParams::Input oinp;
oinp.geometry = core.geometry();
oinp.material = inp.material;
oinp.rng = {}; // TODO: need independent streams
oinp.sim = std::make_shared<SimParams>();
return oinp;
}());
core.aux_reg()->insert(gen_params_);
AuxParamsRegistry& aux = *core.aux_reg();
gen_params_ = std::make_shared<detail::OffloadParams>(aux.next_id(), setup);
aux.insert(gen_params_);

// Action to gather pre-step data needed to generate optical distributions
ActionRegistry& actions = *core.action_reg();
Expand All @@ -62,26 +56,34 @@ OpticalCollector::OpticalCollector(CoreParams const& core, Input&& inp)
if (setup.cerenkov)
{
// Action to generate Cerenkov optical distributions
cerenkov_offload_action_
= std::make_shared<detail::CerenkovOffloadAction>(
actions.next_id(),
gen_params_->aux_id(),
inp.material,
std::move(inp.cerenkov));
actions.insert(cerenkov_offload_action_);
cerenkov_action_ = std::make_shared<detail::CerenkovOffloadAction>(
actions.next_id(),
gen_params_->aux_id(),
inp.material,
std::move(inp.cerenkov));
actions.insert(cerenkov_action_);
}

if (setup.scintillation)
{
// Action to generate scintillation optical distributions
scint_offload_action_ = std::make_shared<detail::ScintOffloadAction>(
scint_action_ = std::make_shared<detail::ScintOffloadAction>(
actions.next_id(),
gen_params_->aux_id(),
std::move(inp.scintillation));
actions.insert(scint_offload_action_);
actions.insert(scint_action_);
}

// TODO: add an action to launch optical tracking loop
// Create launch action with optical params+state and access to gen data
launch_action_ = detail::OpticalLaunchAction::make_and_insert(
core, inp.material, gen_params_);

// Launch action must be *after* generator actions
CELER_ENSURE(!cerenkov_action_
|| launch_action_->action_id()
> cerenkov_action_->action_id());
CELER_ENSURE(!scint_action_
|| launch_action_->action_id() > scint_action_->action_id());
}

//---------------------------------------------------------------------------//
Expand All @@ -93,14 +95,5 @@ AuxId OpticalCollector::offload_aux_id() const
return gen_params_->aux_id();
}

//---------------------------------------------------------------------------//
/*!
* Aux ID for optical core data used for the optical loop.
*/
AuxId OpticalCollector::optical_aux_id() const
{
return optical_params_->aux_id();
}

//---------------------------------------------------------------------------//
} // namespace celeritas
29 changes: 12 additions & 17 deletions src/celeritas/optical/OpticalCollector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@

#include "OffloadData.hh"

#include "detail/CerenkovOffloadAction.hh"
#include "detail/OffloadGatherAction.hh"
#include "detail/ScintOffloadAction.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class ActionRegistry;
class CerenkovParams;
class ScintillationParams;
class CoreParams;

namespace optical
{
class CerenkovParams;
class MaterialParams;
class CoreParams;
class ScintillationParams;
}

namespace detail
{
class CerenkovOffloadAction;
class OffloadGatherAction;
class OpticalLaunchAction;
class OffloadParams;
class ScintOffloadAction;
} // namespace detail

//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -92,27 +91,23 @@ class OpticalCollector
// Aux ID for optical offload data
AuxId offload_aux_id() const;

// Aux ID for optical params data
AuxId optical_aux_id() const;

private:
//// TYPES ////

using SPOffloadParams = std::shared_ptr<detail::OffloadParams>;
using SPCerenkovOffloadAction
= std::shared_ptr<detail::CerenkovOffloadAction>;
using SPScintOffloadAction = std::shared_ptr<detail::ScintOffloadAction>;
using SPCerenkovAction = std::shared_ptr<detail::CerenkovOffloadAction>;
using SPScintAction = std::shared_ptr<detail::ScintOffloadAction>;
using SPGatherAction = std::shared_ptr<detail::OffloadGatherAction>;
using SPOpticalParams = std::shared_ptr<optical::CoreParams>;
using SPLaunchAction = std::shared_ptr<detail::OpticalLaunchAction>;

//// DATA ////

SPOffloadParams gen_params_;
SPOpticalParams optical_params_;

SPGatherAction gather_action_;
SPCerenkovOffloadAction cerenkov_offload_action_;
SPScintOffloadAction scint_offload_action_;
SPCerenkovAction cerenkov_action_;
SPScintAction scint_action_;
SPLaunchAction launch_action_;

// TODO: tracking loop launch action
};
Expand Down
2 changes: 1 addition & 1 deletion src/celeritas/optical/detail/OffloadParams.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace detail
{
//---------------------------------------------------------------------------//
/*!
* Manage metadata about optical offloading.
* Manage metadata for optical offload generation.
*/
class OffloadParams final : public AuxParamsInterface,
public ParamsDataInterface<OffloadParamsData>
Expand Down
Loading

0 comments on commit 3fca57f

Please sign in to comment.