Skip to content

Commit bf5554d

Browse files
committed
Write out optical size diagnostic (#1597)
* Rename diagnostic for consistency * Add optical size diagnostic * Only add optical loop parameters when running an optical problem * Don't write optical loop input when disabled * Fix app test names * Add assertions for sizes * Account for multithreading * Make initializers more reproducible * Improve debug message and doc * Fix build errors with old GCC/Geant4/nljson (const char* was ambiguous) * Use divisible-into-100 events
1 parent 909e2d1 commit bf5554d

13 files changed

+157
-34
lines changed

app/celer-export-geant.cc

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include <vector>
1616
#include <nlohmann/json.hpp>
1717

18-
#include "corecel/Config.hh"
19-
2018
#include "corecel/Assert.hh"
2119
#include "corecel/io/Logger.hh"
2220
#include "corecel/io/StringUtils.hh"

app/celer-sim/CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ function(celer_sim_test test_ext gdml_inp_name hepmc3_inp_name mctruth_name)
7676
set(_needs_deps DISABLED true)
7777
endif()
7878

79-
add_test(NAME "app/celer-sim-${test_ext}:gpu"
79+
set(_name "app/celer-sim:${test_ext}:gpu")
80+
add_test(NAME "${_name}"
8081
COMMAND "${CELER_PYTHON}"
8182
"${_driver}" "${_gdml_inp}" "${_hepmc3_inp}" "${_mctruth_out}"
8283
)
83-
set_tests_properties("app/celer-sim-${test_ext}:gpu" PROPERTIES
84+
set_tests_properties("${_name}" PROPERTIES
8485
ENVIRONMENT "${_env};${CELER_G4ENV}"
8586
RESOURCE_LOCK gpu
8687
REQUIRED_FILES "${_driver};${_gdml_inp};${_hepmc3_inp}"
@@ -100,7 +101,8 @@ function(celer_sim_test test_ext gdml_inp_name hepmc3_inp_name mctruth_name)
100101
set(CELER_GEO "${CELER_CORE_GEO}-JSON")
101102
endif()
102103

103-
add_test(NAME "app/celer-sim-${test_ext}:cpu"
104+
set(_name "app/celer-sim:${test_ext}:cpu")
105+
add_test(NAME "${_name}"
104106
COMMAND "${CELER_PYTHON}"
105107
"${_driver}" "${_gdml_inp}" "${_hepmc3_inp}" "${_mctruth_out}"
106108
)
@@ -118,7 +120,7 @@ function(celer_sim_test test_ext gdml_inp_name hepmc3_inp_name mctruth_name)
118120
set(CELER_OMP_ENV "OMP_NUM_THREADS=1")
119121
set(CELER_PROCESSORS)
120122
endif()
121-
set_tests_properties("app/celer-sim-${test_ext}:cpu" PROPERTIES
123+
set_tests_properties("${_name}" PROPERTIES
122124
ENVIRONMENT "${_env};${CELER_G4ENV};${CELER_OMP_ENV}"
123125
REQUIRED_FILES "${_driver};${_gdml_inp};${_hepmc3_inp}"
124126
LABELS "app;nomemcheck"
@@ -130,13 +132,13 @@ endfunction()
130132
#-----------------------------------------------------------------------------#
131133

132134
celer_sim_test(cms
133-
simple-cms.gdml gamma-3evt-15prim.hepmc3 simple-cms-mctruth.root
135+
simple-cms.gdml gamma-4evt-15prim.hepmc3 simple-cms-mctruth.root
134136
)
135137

136138
# TODO: Currently simple-driver.py uses the same Runner input parameters on
137139
# both celer-sim-cms and celer-sim-lar tests. Some may need to be updated.
138140
celer_sim_test(lar
139-
lar-sphere.gdml gamma-3evt-15prim.hepmc3 lar-mctruth.root
141+
lar-sphere.gdml gamma-4evt-15prim.hepmc3 lar-mctruth.root
140142
)
141143

142144
#-----------------------------------------------------------------------------#

app/celer-sim/RunnerInput.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct RunnerInput
101101
// Control
102102
unsigned int seed{};
103103
size_type num_track_slots{}; //!< Divided among streams
104-
size_type max_steps = static_cast<size_type>(-1);
104+
size_type max_steps = static_cast<size_type>(-1); //!< Step *iterations*
105105
size_type initializer_capacity{}; //!< Divided among streams
106106
real_type secondary_stack_factor{};
107107
bool use_device{};

app/celer-sim/RunnerInputIO.json.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void to_json(nlohmann::json& j, RunnerInput const& v)
200200
v.physics_file.empty()
201201
|| !ends_with(v.physics_file, ".root"));
202202

203-
LDIO_SAVE(optical);
203+
LDIO_SAVE_WHEN(optical, v.optical);
204204

205205
#undef LDIO_SAVE_OPTION
206206
#undef LDIO_SAVE_WHEN

app/celer-sim/simple-driver.py

+36-12
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,6 @@ def strtobool(text):
8686
# shorten to an unreasonably small number to reduce test time.
8787
max_steps = 256
8888

89-
# TODO: Update once tracking loop is implemented
90-
optical_options = {
91-
'buffer_capacity': 3 * max_steps * num_tracks,
92-
'primary_capacity': num_tracks,
93-
'auto_flush': 2**31, # Large enough to never launch optical loop
94-
}
95-
9689
inp = {
9790
'use_device': use_device,
9891
'geometry_file': geometry_filename,
@@ -102,7 +95,7 @@ def strtobool(text):
10295
'seed': 12345,
10396
'num_track_slots': num_tracks,
10497
'max_steps': max_steps,
105-
'initializer_capacity': 100 * max([num_tracks, num_primaries]),
98+
'initializer_capacity': 100 * num_tracks,
10699
'secondary_stack_factor': 3,
107100
'action_diagnostic': True,
108101
'step_diagnostic': True,
@@ -115,10 +108,19 @@ def strtobool(text):
115108
'brem_combined': True,
116109
'physics_options': physics_options,
117110
'field': None,
118-
'optical': optical_options,
119111
'slot_diagnostic_prefix': f"slot-diag-{run_name}-",
120112
}
121113

114+
if "lar" in geometry_filename:
115+
inp['optical'] = {
116+
'buffer_capacity': 3 * max_steps * num_tracks,
117+
'primary_capacity': num_tracks,
118+
'auto_flush': 2**31, # Large enough to never launch optical loop
119+
}
120+
121+
if physics_filename:
122+
inp['physics_file'] = physics_filename
123+
122124
inp_file = f'{run_name}.inp.json'
123125
with open(inp_file, 'w') as f:
124126
json.dump(inp, f, indent=1)
@@ -159,14 +161,36 @@ def strtobool(text):
159161
json.dump(j, f, indent=1)
160162
print("Results written to", out_file, file=stderr)
161163

162-
run_output =j['result']['runner']
164+
run_output = j['result']['runner']
163165
time = run_output['time'].copy()
164166
steps = time.pop('steps')
165167
if use_device:
166168
assert steps
167-
assert len(steps[0]) == run_output['num_step_iterations'][0]
169+
assert len(steps[0]) == run_output['num_step_iterations'][0], steps[0]
168170
else:
169171
# Step times disabled on CPU from input
170-
assert steps is None
172+
assert steps is None, steps
173+
174+
internal = j["internal"]
175+
if "lar" in geometry_filename and not use_device:
176+
core_sizes = internal["core-sizes"].copy()
177+
num_streams = internal["core-sizes"].pop("streams")
178+
if "openmp" not in j["system"]["build"]["config"]["use"]:
179+
assert num_streams == 1
180+
assert internal["core-sizes"] == {
181+
"events": 4,
182+
"initializers": 3200,
183+
"processes": 1,
184+
"secondaries": 96,
185+
"tracks": 32
186+
}, core_sizes
187+
188+
opt_sizes = internal["optical-sizes"].copy()
189+
assert num_streams == opt_sizes.pop("streams")
190+
assert opt_sizes == {
191+
"generators": 24576 * num_streams,
192+
"initializers": 32 * num_streams,
193+
"tracks": 0,
194+
}, opt_sizes
171195

172196
print(json.dumps(time, indent=1))
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
HepMC::Version 3.02.02
22
HepMC::Asciiv3-START_EVENT_LISTING
3-
E 0 0 5
3+
E 0 0 3
44
U MEV CM
55
P 1 0 22 5.1986662883182282e+02 -4.2922054653912312e+02 -7.3858541188930360e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
66
P 2 0 22 7.3395459362460701e+02 1.8726575230281321e+02 6.5287226354915663e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
77
P 3 0 22 -4.0053358241288629e+02 -8.1839341451526892e+01 9.1261994913012950e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
8-
P 4 0 22 -5.1571621404849338e+02 1.2578032388599880e+02 8.4747631040084048e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
9-
P 5 0 22 -5.0829382297517975e+02 5.1523183959000494e+02 -6.9005328852051423e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
10-
E 1 0 5
8+
E 1 0 4
119
U MEV CM
1210
P 1 0 22 2.5183128938864547e+02 -2.0216120822226654e+02 -9.4642054477645695e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
1311
P 2 0 22 -2.5247976713163627e+02 9.4617275706343776e+02 -2.0251192799469257e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
1412
P 3 0 22 3.4066344768752202e+02 -9.0517210955885571e+02 2.5418864547107884e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
1513
P 4 0 22 8.3192692739205529e+02 -5.4330006880869769e+02 1.1279460409291821e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
16-
P 5 0 22 2.3445050379268079e+02 -3.6984950141988622e+02 -8.9902408620171002e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
17-
E 2 0 5
14+
E 2 0 4
15+
U MEV CM
16+
P 1 0 22 1.7562103525403742e+02 -4.7618127524473937e+02 8.6163138585046556e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
17+
P 2 0 22 -6.0694965222663632e+02 6.9697036165837198e+02 3.8189584264791790e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
18+
P 3 0 22 5.1336099422574807e+02 5.4197742781708928e+02 6.6537279576514345e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
19+
P 4 0 22 -3.6655746358147650e+02 8.0035990693978067e+02 4.7440451647940733e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
20+
E 3 0 4
1821
U MEV CM
1922
P 1 0 22 1.7562103525403742e+02 -4.7618127524473937e+02 8.6163138585046556e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
2023
P 2 0 22 -6.0694965222663632e+02 6.9697036165837198e+02 3.8189584264791790e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
2124
P 3 0 22 5.1336099422574807e+02 5.4197742781708928e+02 6.6537279576514345e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
2225
P 4 0 22 -3.6655746358147650e+02 8.0035990693978067e+02 4.7440451647940733e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
23-
P 5 0 22 -7.8969793730748802e+02 -5.4961247282688134e+02 -2.7258631206540650e+02 1.0000000000000000e+03 0.0000000000000000e+00 1
2426
HepMC::Asciiv3-END_EVENT_LISTING
2527

src/accel/detail/HitManagerOutput.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void HitManagerOutput::output(JsonPimpl* j) const
5959
G4VSensitiveDetector const* sd{nullptr};
6060
if (lv)
6161
{
62-
gv_names.push_back(lv->GetName());
62+
gv_names.push_back(std::string(lv->GetName()));
6363
sd = lv->GetSensitiveDetector();
6464
}
6565
else
@@ -69,7 +69,7 @@ void HitManagerOutput::output(JsonPimpl* j) const
6969

7070
if (sd)
7171
{
72-
sd_names.push_back(sd->GetName());
72+
sd_names.push_back(std::string(sd->GetName()));
7373
sd_types.push_back(demangle_sd(*sd));
7474
}
7575
else

src/celeritas/Types.cc

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include "corecel/io/EnumStringMapper.hh"
1111

12-
#include "UnitTypes.hh"
13-
1412
namespace celeritas
1513
{
1614
//---------------------------------------------------------------------------//

src/celeritas/global/CoreParams.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ CoreParams::CoreParams(Input input) : input_(std::move(input))
341341
input_.output_reg->insert(
342342
OutputInterfaceAdapter<detail::CoreSizes>::from_rvalue_ref(
343343
OutputInterface::Category::internal,
344-
"core_sizes",
344+
"core-sizes",
345345
get_core_sizes(*this)));
346346

347347
// Save core diagnostic information

src/celeritas/optical/TrackInitParams.hh

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class TrackInitParams final : public ParamsDataInterface<TrackInitParamsData>
3333
//! Access data on device
3434
DeviceRef const& device_ref() const final { return data_.device_ref(); }
3535

36+
//! Maximum number of initializers
37+
size_type capacity() const { return host_ref().capacity; }
38+
3639
private:
3740
// Host/device storage and reference
3841
CollectionMirror<TrackInitParamsData> data_;

src/celeritas/optical/detail/OpticalLaunchAction.cc

+34
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "corecel/data/AuxParamsRegistry.hh"
1111
#include "corecel/data/AuxStateVec.hh"
1212
#include "corecel/io/Logger.hh"
13+
#include "corecel/io/OutputInterfaceAdapter.hh"
14+
#include "corecel/io/OutputRegistry.hh"
1315
#include "corecel/sys/ActionRegistry.hh"
1416
#include "celeritas/global/CoreParams.hh"
1517
#include "celeritas/global/CoreState.hh"
@@ -21,11 +23,36 @@
2123
#include "celeritas/track/TrackInitParams.hh"
2224

2325
#include "OffloadParams.hh"
26+
#include "OpticalSizes.json.hh"
2427

2528
namespace celeritas
2629
{
2730
namespace detail
2831
{
32+
namespace
33+
{
34+
//---------------------------------------------------------------------------//
35+
auto get_core_sizes(OpticalLaunchAction const& ola)
36+
{
37+
// Optical core params
38+
auto const& cp = ola.optical_params();
39+
40+
OpticalSizes result;
41+
result.streams = cp.max_streams();
42+
43+
// NOTE: quantities are *per-process* quantities: integrated over streams,
44+
// but not processes
45+
result.generators = result.streams
46+
* ola.offload_params().host_ref().setup.capacity;
47+
result.initializers = result.streams * cp.init()->capacity();
48+
result.tracks = 0;
49+
50+
return result;
51+
}
52+
53+
//---------------------------------------------------------------------------//
54+
} // namespace
55+
2956
//---------------------------------------------------------------------------//
3057
/*!
3158
* Construct and add to core params.
@@ -84,6 +111,13 @@ OpticalLaunchAction::OpticalLaunchAction(ActionId action_id,
84111
return inp;
85112
}());
86113

114+
// Add optical sizes
115+
core.output_reg()->insert(
116+
OutputInterfaceAdapter<detail::OpticalSizes>::from_rvalue_ref(
117+
OutputInterface::Category::internal,
118+
"optical-sizes",
119+
get_core_sizes(*this)));
120+
87121
// TODO: add generators to the *optical* stepping loop instead of part of
88122
// the main loop; for now just make sure enough track initializers are
89123
// allocated so that we can initialize them all at the beginning of step

src/celeritas/optical/detail/OpticalLaunchAction.hh

+16
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ class OpticalLaunchAction : public AuxParamsInterface,
100100

101101
// TODO: local end run to flush initializers??
102102

103+
//!@{
104+
//! \name Accessors
105+
106+
//! Optical core params
107+
optical::CoreParams const& optical_params() const
108+
{
109+
return *optical_params_;
110+
}
111+
//! Offload params
112+
detail::OffloadParams const& offload_params() const
113+
{
114+
return *offload_params_;
115+
}
116+
117+
//!@}
118+
103119
private:
104120
using ActionGroupsT = ActionGroups<optical::CoreParams, optical::CoreState>;
105121
using SPOpticalParams = std::shared_ptr<optical::CoreParams>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//------------------------------- -*- C++ -*- -------------------------------//
2+
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
3+
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
4+
//---------------------------------------------------------------------------//
5+
//! \file celeritas/optical/detail/OpticalSizes.json.hh
6+
//---------------------------------------------------------------------------//
7+
#pragma once
8+
9+
#include <nlohmann/json.hpp>
10+
11+
#include "corecel/Types.hh"
12+
#include "corecel/io/JsonUtils.json.hh"
13+
14+
namespace celeritas
15+
{
16+
namespace detail
17+
{
18+
//---------------------------------------------------------------------------//
19+
/*!
20+
* Save state size/capacity counters.
21+
*
22+
* These should be *integrated* across streams, *per process*.
23+
*/
24+
struct OpticalSizes
25+
{
26+
size_type generators{};
27+
size_type initializers{};
28+
size_type tracks{};
29+
size_type streams{};
30+
};
31+
32+
//---------------------------------------------------------------------------//
33+
34+
void to_json(nlohmann::json& j, OpticalSizes const& inp)
35+
{
36+
j = {
37+
CELER_JSON_PAIR(inp, generators),
38+
CELER_JSON_PAIR(inp, initializers),
39+
CELER_JSON_PAIR(inp, tracks),
40+
CELER_JSON_PAIR(inp, streams),
41+
};
42+
}
43+
44+
//---------------------------------------------------------------------------//
45+
} // namespace detail
46+
} // namespace celeritas

0 commit comments

Comments
 (0)