Skip to content

Commit

Permalink
Add track_order option to celer-g4 and default to partitioning by c…
Browse files Browse the repository at this point in the history
…harge on GPU (#1433)

* Add track order option to celer-g4
* Default to partitioning tracks by charge on the GPU
  • Loading branch information
amandalund authored Sep 28, 2024
1 parent bec9f4c commit 7e52dc4
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/celer-g4/GlobalSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void GlobalSetup::ReadInput(std::string const& filename)
options_->action_times = input_.action_times;
options_->default_stream = input_.default_stream;
options_->auto_flush = input_.auto_flush;
options_->track_order = input_.track_order;
options_->max_field_substeps = input_.field_options.max_substeps;
}
else if (ends_with(filename, ".mac"))
Expand Down
5 changes: 5 additions & 0 deletions app/celer-g4/RunInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "corecel/Types.hh"
#include "corecel/cont/Array.hh"
#include "corecel/sys/Device.hh"
#include "celeritas/ext/GeantPhysicsOptions.hh"
#include "celeritas/field/FieldDriverOptions.hh"
#include "celeritas/phys/PrimaryGeneratorOptions.hh"
Expand Down Expand Up @@ -72,6 +73,10 @@ struct RunInput
bool action_times{false};
bool default_stream{false}; //!< Launch all kernels on the default stream

// Track reordering options
TrackOrder track_order{Device::num_devices() ? TrackOrder::partition_charge
: TrackOrder::unsorted};

// Physics setup options
PhysicsListSelection physics_list{PhysicsListSelection::celer_ftfp_bert};
GeantPhysicsOptions physics_options;
Expand Down
5 changes: 5 additions & 0 deletions app/celer-g4/RunInputIO.json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "corecel/io/StringEnumMapper.hh"
#include "corecel/sys/Environment.hh"
#include "celeritas/Types.hh"
#include "celeritas/TypesIO.hh"
#include "celeritas/ext/GeantPhysicsOptionsIO.json.hh"
#include "celeritas/field/FieldDriverOptionsIO.json.hh"
#include "celeritas/phys/PrimaryGeneratorOptionsIO.json.hh"
Expand Down Expand Up @@ -94,6 +95,8 @@ void from_json(nlohmann::json const& j, RunInput& v)
v.auto_flush = v.num_track_slots;
}

RI_LOAD_OPTION(track_order);

RI_LOAD_OPTION(physics_list);
RI_LOAD_OPTION(physics_options);

Expand Down Expand Up @@ -185,6 +188,8 @@ void to_json(nlohmann::json& j, RunInput const& v)
RI_SAVE(default_stream);
RI_SAVE(auto_flush);

RI_SAVE(track_order);

RI_SAVE(physics_list);
if (v.physics_list != PhysicsListSelection::ftfp_bert)
{
Expand Down
4 changes: 2 additions & 2 deletions app/celer-sim/RunnerInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct RunnerInput
bool action_times{};
bool merge_events{false}; //!< Run all events at once on a single stream
bool default_stream{false}; //!< Launch all kernels on the default stream
bool warm_up{CELER_USE_DEVICE}; //!< Run a nullop step first
bool warm_up{false}; //!< Run a nullop step first

// Magnetic field vector [* 1/Tesla] and associated field options
Real3 field{no_field()};
Expand All @@ -118,7 +118,7 @@ struct RunnerInput
// Options for physics
bool brem_combined{false};

// Track init options
// Track reordering options
TrackOrder track_order{TrackOrder::unsorted};

// Optional setup options if loading directly from Geant4
Expand Down
38 changes: 17 additions & 21 deletions app/celer-sim/RunnerInputIO.json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,12 @@
#include "corecel/io/StringUtils.hh"
#include "corecel/sys/EnvironmentIO.json.hh"
#include "celeritas/Types.hh"
#include "celeritas/TypesIO.hh"
#include "celeritas/ext/GeantPhysicsOptionsIO.json.hh"
#include "celeritas/field/FieldDriverOptionsIO.json.hh"
#include "celeritas/phys/PrimaryGeneratorOptionsIO.json.hh"
#include "celeritas/user/RootStepWriterIO.json.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
void from_json(nlohmann::json const& j, TrackOrder& value)
{
static auto const from_string
= StringEnumMapper<TrackOrder>::from_cstring_func(to_cstring,
"track order");
value = from_string(j.get<std::string>());
}

void to_json(nlohmann::json& j, TrackOrder const& value)
{
j = std::string{to_cstring(value)};
}

//---------------------------------------------------------------------------//
} // namespace celeritas

namespace celeritas
{
namespace app
Expand Down Expand Up @@ -109,7 +91,14 @@ void from_json(nlohmann::json const& j, RunnerInput& v)
LDIO_LOAD_OPTION(action_times);
LDIO_LOAD_OPTION(merge_events);
LDIO_LOAD_OPTION(default_stream);
LDIO_LOAD_OPTION(warm_up);
if (auto iter = j.find("warm_up"); iter != j.end())
{
iter->get_to(v.warm_up);
}
else if (v.use_device)
{
v.warm_up = true;
}

LDIO_LOAD_DEPRECATED(mag_field, field);

Expand All @@ -120,7 +109,14 @@ void from_json(nlohmann::json const& j, RunnerInput& v)

LDIO_LOAD_OPTION(step_limiter);
LDIO_LOAD_OPTION(brem_combined);
LDIO_LOAD_OPTION(track_order);
if (auto iter = j.find("track_order"); iter != j.end())
{
iter->get_to(v.track_order);
}
else if (v.use_device)
{
v.track_order = TrackOrder::partition_charge;
}
LDIO_LOAD_OPTION(physics_options);

LDIO_LOAD_OPTION(optical);
Expand Down
12 changes: 7 additions & 5 deletions src/accel/SetupOptions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <unordered_set>
#include <vector>

#include "corecel/sys/Device.hh"
#include "celeritas/Types.hh"
#include "celeritas/global/ActionInterface.hh"

Expand Down Expand Up @@ -130,6 +131,12 @@ struct SetupOptions
size_type auto_flush{};
//!@}

//!@{
//! \name Track reordering options
TrackOrder track_order{Device::num_devices() ? TrackOrder::partition_charge
: TrackOrder::unsorted};
//!@}

//! Set the number of streams (defaults to run manager # threads)
IntAccessor get_num_streams;

Expand Down Expand Up @@ -163,11 +170,6 @@ struct SetupOptions
//! Launch all kernels on the default stream
bool default_stream{false};
//!@}

//!@{
//! \name Track init options
TrackOrder track_order{TrackOrder::unsorted};
//!@}
};

//---------------------------------------------------------------------------//
Expand Down
40 changes: 40 additions & 0 deletions src/celeritas/TypesIO.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//----------------------------------*-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/TypesIO.hh
//---------------------------------------------------------------------------//
#pragma once

#include <nlohmann/json.hpp>

#include "corecel/io/JsonUtils.json.hh"

#include "Types.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
/*!
* Read options from JSON.
*/
void from_json(nlohmann::json const& j, TrackOrder& value)
{
static auto const from_string
= StringEnumMapper<TrackOrder>::from_cstring_func(to_cstring,
"track order");
value = from_string(j.get<std::string>());
}

//---------------------------------------------------------------------------//
/*!
* Write options to JSON.
*/
void to_json(nlohmann::json& j, TrackOrder const& value)
{
j = std::string{to_cstring(value)};
}

//---------------------------------------------------------------------------//
} // namespace celeritas

0 comments on commit 7e52dc4

Please sign in to comment.