Skip to content

Commit f59c69f

Browse files
authored
feat: Add multilevel host/device logging to propagation (#1071)
Fixes the logging and adds logging output to the propagation (stepper, navigator and actors). The detector building logging is cleaned up a bit and new logging features are introduced: - Different log levels: NONE, WARN, INFO, VERBOSE and DEBUG, which can be set in the cmake configuration via the DETRAY_SET_LOGGING flag - Logging is done via clog and stderr, so that it can easily be piped into a file (except device logging, which has to go to stdout) - Introduced logging for device: HOST logging uses streaming operators to print detailed object information, HOST_DEVICE logging appears in both compilations and uses printf and DEVICE logging only appears in device code and prints the respective backend (CUDA, HIP, SYCL) that issued the message. Any of the HOST, HOST_DEVICE or DEVICE logging macros can be used anywhere in the code, but will only print messages when appropriate. The default level is INFO, with VERBOSE adding some messages from inside the propagation loop. DEBUG output is for expert level of information. The DEBUG logging is turned on in the build-only parts of the CI to make sure it continues to compile.
1 parent 35e490d commit f59c69f

File tree

127 files changed

+1572
-986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1572
-986
lines changed

.github/workflows/builds.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
run: cmake --preset full-fp64
4141
-DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }}
4242
-DDETRAY_FAIL_ON_WARNINGS=ON
43+
-DDETRAY_SET_LOGGING=DEBUG
4344
-S ${{ github.workspace }} -B build
4445
-G "${{ matrix.PLATFORM.GENERATOR }}"
4546
# Perform the build.
@@ -125,19 +126,19 @@ jobs:
125126
- NAME: "CUDA"
126127
CXX_STANDARD: "20"
127128
CONTAINER: "ghcr.io/acts-project/ubuntu2404_cuda:67"
128-
OPTIONS: -DDETRAY_BUILD_CUDA=ON -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
129+
OPTIONS: -DDETRAY_BUILD_CUDA=ON -DDETRAY_SET_LOGGING=DEBUG -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
129130
- NAME: "HIP-AMD"
130131
CXX_STANDARD: "20"
131132
CONTAINER: "ghcr.io/acts-project/ubuntu2404_rocm_oneapi:69"
132-
OPTIONS: -DCMAKE_PREFIX_PATH=/opt/rocm/lib/cmake/ -DCMAKE_HIP_PLATFORM=amd -DDETRAY_BUILD_HIP=ON -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
133+
OPTIONS: -DCMAKE_PREFIX_PATH=/opt/rocm/lib/cmake/ -DCMAKE_HIP_PLATFORM=amd -DDETRAY_BUILD_HIP=ON -DDETRAY_SET_LOGGING=DEBUG -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
133134
#- NAME: "HIP-NVIDIA"
134135
# CXX_STANDARD: "20"
135136
# CONTAINER:
136137
# OPTIONS: -DCMAKE_HIP_PLATFORM=nvidia -DDETRAY_BUILD_HIP=ON -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
137138
- NAME: "SYCL"
138139
CXX_STANDARD: "20"
139140
CONTAINER: "ghcr.io/acts-project/ubuntu2404_oneapi:56"
140-
OPTIONS: -DDETRAY_BUILD_CUDA=OFF -DDETRAY_BUILD_SYCL=ON -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
141+
OPTIONS: -DDETRAY_BUILD_CUDA=OFF -DDETRAY_BUILD_SYCL=ON -DDETRAY_SET_LOGGING=DEBUG -DDETRAY_EIGEN_PLUGIN=ON -DDETRAY_SMATRIX_PLUGIN=OFF -DDETRAY_VC_AOS_PLUGIN=OFF -DDETRAY_VC_SOA_PLUGIN=OFF
141142

142143
# The system to run on.
143144
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ cmake_dependent_option(
8989
"DETRAY_BUILD_CUDA OR DETRAY_BUILD_SYCL OR DETRAY_BUILD_HIP"
9090
ON
9191
)
92+
set(DETRAY_SET_LOGGING "INFO" CACHE STRING "Set the log level")
93+
set_property(
94+
CACHE DETRAY_SET_LOGGING
95+
PROPERTY STRINGS "NONE" "WARNING" "INFO" "VERBOSE" "DEBUG"
96+
)
9297
option(DETRAY_BUILD_TEST_UTILS "Build the test utility library of Detray" OFF)
9398
option(DETRAY_BUILD_VALIDATION_TOOLS "Build the validation tools of Detray" OFF)
9499
option(DETRAY_BUILD_UNITTESTS "Build the unit tests of Detray" OFF)
@@ -301,11 +306,18 @@ if(DETRAY_SETUP_COVFIE)
301306
add_subdirectory(extern/covfie)
302307
endif()
303308
endif()
304-
option(
305-
DETRAY_ENABLE_LOGGING
306-
"Enable logging output to stdout. Useful for debugging"
307-
OFF
308-
)
309+
310+
# Resolve the internal log level from user input
311+
set(DETRAY_LOG_LVL -1 CACHE INTERNAL "Disable logging")
312+
if(DETRAY_SET_LOGGING STREQUAL "WARN")
313+
set(DETRAY_LOG_LVL 0 CACHE INTERNAL "Print warnings and errors" FORCE)
314+
elseif(DETRAY_SET_LOGGING STREQUAL "INFO")
315+
set(DETRAY_LOG_LVL 1 CACHE INTERNAL "Print general information" FORCE)
316+
elseif(DETRAY_SET_LOGGING STREQUAL "VERBOSE")
317+
set(DETRAY_LOG_LVL 2 CACHE INTERNAL "Print detailed information" FORCE)
318+
elseif(DETRAY_SET_LOGGING STREQUAL "DEBUG")
319+
set(DETRAY_LOG_LVL 3 CACHE INTERNAL "Print expert information" FORCE)
320+
endif()
309321

310322
# Set up all of the libraries of the project.
311323
add_subdirectory(core)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The following cmake options are available and can also be specified explicitly f
5959

6060
| Option | Description | Default |
6161
| --- | --- | --- |
62+
| DETRAY_SET_LOGGING | Set log level (NONE, WARN, INFO, VERBOSE, DEBUG) | INFO |
6263
| DETRAY_BUILD_CUDA | Build the CUDA sources included in detray | ON (if available) |
6364
| DETRAY_BUILD_SYCL | Build the SYCL sources included in detray | OFF |
6465
| DETRAY_BUILD_TEST_UTILS | Build the detray test utilities library (contains e.g. test detectors) | OFF |

core/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ detray_add_library( detray_core core
4141
)
4242
target_link_libraries(detray_core INTERFACE vecmem::core)
4343

44-
if(DETRAY_ENABLE_LOGGING)
45-
message(STATUS "Enabling debug logging output")
46-
target_compile_definitions(detray_core INTERFACE DETRAY_ENABLE_LOGGING)
47-
endif()
44+
message(STATUS "Setting detray log level: ${DETRAY_SET_LOGGING}")
45+
target_compile_definitions(
46+
detray_core
47+
INTERFACE DETRAY_LOG_LVL=${DETRAY_LOG_LVL}
48+
)
4849

4950
# Generate a version header for the project.
5051
configure_file(

core/include/detray/builders/cuboid_portal_generator.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "detray/definitions/math.hpp"
1717
#include "detray/geometry/shapes/cuboid3D.hpp"
1818
#include "detray/utils/bounding_volume.hpp"
19+
#include "detray/utils/log.hpp"
1920
#include "detray/utils/ranges.hpp"
2021

2122
// System include(s)
@@ -91,6 +92,8 @@ class cuboid_portal_generator final
9192
typename detector_t::geometry_context ctx = {})
9293
-> dindex_range override {
9394

95+
DETRAY_VERBOSE_HOST("Generate cuboid portals...");
96+
9497
using point3_t = dpoint3D<algebra_type>;
9598
using vector3_t = dvector3D<algebra_type>;
9699

core/include/detray/builders/cylinder_portal_generator.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "detray/definitions/indexing.hpp"
1818
#include "detray/geometry/shapes/cuboid3D.hpp"
1919
#include "detray/utils/bounding_volume.hpp"
20+
#include "detray/utils/log.hpp"
2021

2122
// System include(s)
2223
#include <cassert>
@@ -193,6 +194,8 @@ class cylinder_portal_generator final
193194
typename detector_t::geometry_context ctx = {})
194195
-> dindex_range override {
195196

197+
DETRAY_VERBOSE_HOST("Generate cylinder portals...");
198+
196199
using aabb_t = axis_aligned_bounding_volume<cuboid3D, algebra_t>;
197200

198201
// Only build portals for cylinder volumes

core/include/detray/builders/detector_builder.hpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#include "detray/core/detector.hpp"
1515
#include "detray/definitions/geometry.hpp"
1616
#include "detray/utils/grid/detail/concepts.hpp"
17+
#include "detray/utils/log.hpp"
1718
#include "detray/utils/type_traits.hpp"
1819

1920
// Vecmem include(s)
20-
#include <detray/utils/log.hpp>
2121
#include <vecmem/memory/memory_resource.hpp>
2222

2323
// System include(s)
@@ -44,9 +44,14 @@ class detector_builder {
4444
using algebra_type = typename detector_type::algebra_type;
4545
using scalar_type = dscalar<algebra_type>;
4646

47+
DETRAY_HOST detector_builder() {
48+
DETRAY_VERBOSE_HOST("New builder created");
49+
}
50+
4751
/// Set the name of the detector under construction to @param det_name
4852
DETRAY_HOST void set_name(std::string det_name) {
4953
m_detector_name = std::move(det_name);
54+
DETRAY_VERBOSE_HOST("Set detector name: " << m_detector_name);
5055
}
5156

5257
/// @returns the name of the detector under construction
@@ -58,6 +63,8 @@ class detector_builder {
5863
DETRAY_HOST auto new_volume(const volume_id id, Args&&... args)
5964
-> volume_builder_interface<detector_type>* {
6065

66+
DETRAY_VERBOSE_HOST("Adding new volume: " << m_volumes.size());
67+
6168
m_volumes.push_back(std::make_unique<volume_builder_t<detector_type>>(
6269
id, static_cast<dindex>(m_volumes.size()),
6370
std::forward<Args>(args)...));
@@ -110,23 +117,25 @@ class detector_builder {
110117
DETRAY_HOST
111118
auto build(vecmem::memory_resource& resource) -> detector_type {
112119

113-
DETRAY_DEBUG("detray: building detector " << name());
120+
DETRAY_INFO_HOST("Building detector: " << name() << "... ");
114121

115122
detector_type det{resource};
116123

117-
DETRAY_DEBUG("Have " << m_volumes.size()
118-
<< " configured volume builders");
124+
DETRAY_INFO_HOST("Have " << m_volumes.size()
125+
<< " configured volume builders");
126+
DETRAY_VERBOSE_HOST("Start building the volumes...");
119127
for (auto& vol_builder : m_volumes) {
120128

121-
DETRAY_DEBUG("- builder: " << vol_builder->name());
129+
DETRAY_VERBOSE_HOST("-> Build: " << vol_builder->name());
122130
vol_builder->build(det);
123131
}
124132

125133
det.set_volume_finder(std::move(m_vol_finder));
126134

127135
// TODO: Add sorting, data deduplication etc. here later...
128136

129-
DETRAY_DEBUG("detray: detector building complete");
137+
DETRAY_INFO_HOST("Detector building complete: " << name());
138+
130139
return det;
131140
}
132141

@@ -136,7 +145,7 @@ class detector_builder {
136145
auto build(vecmem::memory_resource& resource,
137146
typename detector_type::name_map& name_map) -> detector_type {
138147

139-
DETRAY_DEBUG("detray: filling names for detector " << name());
148+
DETRAY_VERBOSE_HOST("detray: filling names for detector " << name());
140149

141150
assert(name_map.empty());
142151

@@ -154,7 +163,7 @@ class detector_builder {
154163
/// Put the volumes into a search data structure
155164
template <typename... Args>
156165
DETRAY_HOST void set_volume_finder([[maybe_unused]] Args&&... args) {
157-
DETRAY_DEBUG("Setting volume finder for detector " << name());
166+
DETRAY_VERBOSE_HOST("Setting volume finder for detector " << name());
158167

159168
using vol_finder_t = typename detector_type::volume_finder;
160169

core/include/detray/builders/grid_builder.hpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class grid_builder : public volume_decorator<detector_t> {
4646
explicit grid_builder(
4747
std::unique_ptr<volume_builder_interface<detector_t>> vol_builder)
4848
: volume_decorator<detector_t>(std::move(vol_builder)) {
49-
DETRAY_DEBUG("Grid builder created");
49+
50+
DETRAY_VERBOSE_HOST("Add grid builder to volume: " << this->name());
51+
5052
// The grid builder provides an acceleration structure to the
5153
// volume, so don't add sensitive surfaces to the brute force method
5254
if (this->get_builder()) {
@@ -55,8 +57,12 @@ class grid_builder : public volume_decorator<detector_t> {
5557
}
5658

5759
/// Should the passive surfaces be added to the grid ?
58-
void set_add_passives(bool is_add_passive = true) {
60+
void set_add_passives(bool is_add_passive = false) {
5961
m_add_passives = is_add_passive;
62+
63+
DETRAY_VERBOSE_HOST("Add passive surfaces to grid: "
64+
<< std::boolalpha << m_add_passives
65+
<< std::noboolalpha);
6066
}
6167

6268
/// Set the surface category this grid should contain (type id in the
@@ -86,6 +92,8 @@ class grid_builder : public volume_decorator<detector_t> {
8692
const darray<std::vector<scalar_type>, grid_t::dim> &ax_bin_edges =
8793
darray<std::vector<scalar_type>, grid_t::dim>()) {
8894

95+
DETRAY_VERBOSE_HOST("Intialize surface grid...");
96+
8997
static_assert(
9098
std::is_same_v<typename grid_shape_t::template local_frame_type<
9199
typename detector_t::algebra_type>,
@@ -94,6 +102,10 @@ class grid_builder : public volume_decorator<detector_t> {
94102

95103
m_grid = m_factory.template new_grid<grid_t>(m, n_bins, bin_capacities,
96104
ax_bin_edges);
105+
106+
DETRAY_VERBOSE_HOST("Created empty grid:\n"
107+
<< DETRAY_TYPENAME(grid_t) << "\n"
108+
<< m_grid.axes());
97109
}
98110

99111
/// Build the empty grid from axis parameters
@@ -105,8 +117,14 @@ class grid_builder : public volume_decorator<detector_t> {
105117
const std::vector<std::vector<scalar_type>> &ax_bin_edges =
106118
std::vector<std::vector<scalar_type>>()) {
107119

120+
DETRAY_VERBOSE_HOST("Intialize surface grid...");
121+
108122
m_grid = m_factory.template new_grid<grid_t>(
109123
spans, n_bins, bin_capacities, ax_bin_edges);
124+
125+
DETRAY_VERBOSE_HOST("Created empty grid:\n"
126+
<< DETRAY_TYPENAME(grid_t) << "\n"
127+
<< m_grid.axes());
110128
}
111129

112130
/// Fill grid from existing volume using a bin filling strategy
@@ -140,7 +158,7 @@ class grid_builder : public volume_decorator<detector_t> {
140158
typename detector_t::geometry_context ctx = {}) ->
141159
typename detector_t::volume_type * override {
142160

143-
DETRAY_DEBUG("grid_builder::build called");
161+
DETRAY_VERBOSE_HOST("Build surface grid...");
144162

145163
using surface_desc_t = typename detector_t::surface_type;
146164

@@ -153,7 +171,7 @@ class grid_builder : public volume_decorator<detector_t> {
153171

154172
// Grid has not been filled previously, fill it automatically
155173
if (m_grid.size() == 0u) {
156-
DETRAY_DEBUG("-> Filling grid automatically");
174+
DETRAY_DEBUG_HOST("-> Filling grid automatically...");
157175

158176
std::vector<surface_desc_t> surfaces{};
159177
for (auto &sf_desc : vol.surfaces()) {
@@ -169,7 +187,7 @@ class grid_builder : public volume_decorator<detector_t> {
169187
volume_decorator<detector_t>::operator()()},
170188
surfaces, det.transform_store(), det.mask_store(), ctx);
171189
} else {
172-
DETRAY_DEBUG("-> Grid is prefilled");
190+
DETRAY_DEBUG_HOST("-> Grid is prefilled...");
173191

174192
// The grid is prefilled with surface descriptors that contain the
175193
// correct LOCAL surface indices per bin (e.g. from file IO).
@@ -185,22 +203,23 @@ class grid_builder : public volume_decorator<detector_t> {
185203
assert(new_sf_desc.index() == glob_idx);
186204
assert(!new_sf_desc.barcode().is_invalid());
187205

188-
DETRAY_DEBUG("--> resetting sf_desc \n old: "
189-
<< sf_desc << "\n->\n new: " << new_sf_desc
190-
<< "");
191206
sf_desc = new_sf_desc;
192207
}
193208
}
194209

195210
// Add the grid to the detector and link it to its volume
196211
constexpr auto gid{detector_t::accel::template get_id<grid_t>()};
197-
DETRAY_DEBUG("Adding grid to volume in detector. m_id="
198-
<< m_id << ", gid=" << gid);
212+
DETRAY_DEBUG_HOST("Grid indices: m_id=" << m_id << ", gid=" << gid);
213+
199214
det._accelerators.template push_back<gid>(m_grid);
200215
vol_ptr->set_link(m_id, gid,
201216
det.accelerator_store().template size<gid>() - 1);
202217

203-
DETRAY_DEBUG("Accelerator link: " << vol_ptr->accel_link());
218+
DETRAY_DEBUG_HOST("Accelerator link: " << vol_ptr->accel_link());
219+
DETRAY_DEBUG_HOST("Finished grid building: " << m_grid);
220+
221+
DETRAY_VERBOSE_HOST("Successfully built "
222+
<< gid << " for volume: " << this->name());
204223

205224
return vol_ptr;
206225
}

0 commit comments

Comments
 (0)