From fd34bb2dda007d0f0f190e47ddb50f5ef4b8859a Mon Sep 17 00:00:00 2001 From: Stephen Nicholas Swatman Date: Mon, 16 Sep 2024 11:06:01 +0200 Subject: [PATCH] Issue warnings for non-Release builds A common pitfall when using traccc seems to be that people build it in non-Release mode and then get poor performance. This commit adds a bunch of warning prints to make sure that the code will inform you if you try to run it in non-Release mode. --- examples/run/CMakeLists.txt | 5 ++++ examples/run/common/optimization_warning.hpp | 27 ++++++++++++++++++++ examples/run/common/throughput_mt.ipp | 7 +++++ examples/run/common/throughput_st.ipp | 7 +++++ 4 files changed, 46 insertions(+) create mode 100644 examples/run/common/optimization_warning.hpp diff --git a/examples/run/CMakeLists.txt b/examples/run/CMakeLists.txt index ace69ff7be..593fcfe1dc 100644 --- a/examples/run/CMakeLists.txt +++ b/examples/run/CMakeLists.txt @@ -7,6 +7,11 @@ # Project include(s). include( traccc-compiler-options-cpp ) +# Inform the code that it is being built in Release mode. +if (${CMAKE_BUILD_TYPE} STREQUAL "Release") + add_definitions(-DTRACCC_BUILD_TYPE_IS_RELEASE) +endif() + # Add all the subdirectories that can be built. add_subdirectory(cpu) diff --git a/examples/run/common/optimization_warning.hpp b/examples/run/common/optimization_warning.hpp new file mode 100644 index 0000000000..87e7cc2ac5 --- /dev/null +++ b/examples/run/common/optimization_warning.hpp @@ -0,0 +1,27 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +#include + +#if !defined(TRACCC_BUILD_TYPE_IS_RELEASE) || !defined(NDEBUG) || \ + defined(_DEBUG) +#define TRACCC_OPTIMIZATION_WARNING() \ + do { \ + std::cout \ + << "WARNING: traccc was built without Release mode, without the " \ + "`NDEBUG` flag, or (on MSVC) with the `_DEBUG` flag. " \ + "Performance is guaranteed to be much lower and compute " \ + "performance results should be considered unreliable!" \ + << std::endl; \ + } while (false) +#else +#define TRACCC_OPTIMIZATION_WARNING() \ + do { \ + } while (false) +#endif diff --git a/examples/run/common/throughput_mt.ipp b/examples/run/common/throughput_mt.ipp index 5e679b941c..c5cbcbee25 100644 --- a/examples/run/common/throughput_mt.ipp +++ b/examples/run/common/throughput_mt.ipp @@ -18,6 +18,9 @@ #include "traccc/options/track_propagation.hpp" #include "traccc/options/track_seeding.hpp" +// Local include(s) +#include "optimization_warning.hpp" + // I/O include(s). #include "traccc/io/demonstrator_edm.hpp" #include "traccc/io/read.hpp" @@ -72,6 +75,8 @@ int throughput_mt(std::string_view description, int argc, char* argv[], argc, argv}; + TRACCC_OPTIMIZATION_WARNING(); + // Set up the timing info holder. performance::timing_info times; @@ -242,6 +247,7 @@ int throughput_mt(std::string_view description, int argc, char* argv[], // Print some results. std::cout << "Reconstructed track parameters: " << rec_track_params.load() << std::endl; + TRACCC_OPTIMIZATION_WARNING(); std::cout << "Time totals:" << std::endl; std::cout << times << std::endl; std::cout << "Throughput:" << std::endl; @@ -251,6 +257,7 @@ int throughput_mt(std::string_view description, int argc, char* argv[], << performance::throughput{throughput_opts.processed_events, times, "Event processing"} << std::endl; + TRACCC_OPTIMIZATION_WARNING(); // Print results to log file if (throughput_opts.log_file != "\0") { diff --git a/examples/run/common/throughput_st.ipp b/examples/run/common/throughput_st.ipp index ad605e4f56..1ce8f9c478 100644 --- a/examples/run/common/throughput_st.ipp +++ b/examples/run/common/throughput_st.ipp @@ -17,6 +17,9 @@ #include "traccc/options/track_propagation.hpp" #include "traccc/options/track_seeding.hpp" +// Local include(s) +#include "optimization_warning.hpp" + // I/O include(s). #include "traccc/io/demonstrator_edm.hpp" #include "traccc/io/read.hpp" @@ -62,6 +65,8 @@ int throughput_st(std::string_view description, int argc, char* argv[], argc, argv}; + TRACCC_OPTIMIZATION_WARNING(); + // Set up the timing info holder. performance::timing_info times; @@ -192,6 +197,7 @@ int throughput_st(std::string_view description, int argc, char* argv[], // Print some results. std::cout << "Reconstructed track parameters: " << rec_track_params << std::endl; + TRACCC_OPTIMIZATION_WARNING(); std::cout << "Time totals:" << std::endl; std::cout << times << std::endl; std::cout << "Throughput:" << std::endl; @@ -201,6 +207,7 @@ int throughput_st(std::string_view description, int argc, char* argv[], << performance::throughput{throughput_opts.processed_events, times, "Event processing"} << std::endl; + TRACCC_OPTIMIZATION_WARNING(); // Return gracefully. return 0;