From 98989e9cc316c22ee61e6ce467368e1224a8e96f 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 3b998dac1b..d1128c2060 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/read_cells.hpp" #include "traccc/io/read_detector.hpp" @@ -68,6 +71,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; @@ -226,6 +231,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; @@ -235,6 +241,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 acf50ff2a4..f46ed0c405 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/read_cells.hpp" #include "traccc/io/read_detector.hpp" @@ -58,6 +61,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; @@ -168,6 +173,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; @@ -177,6 +183,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;