Skip to content

Commit

Permalink
Issue warnings for non-Release builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stephenswat committed Sep 16, 2024
1 parent e7a03e9 commit fd34bb2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/run/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 27 additions & 0 deletions examples/run/common/optimization_warning.hpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

#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
7 changes: 7 additions & 0 deletions examples/run/common/throughput_mt.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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") {
Expand Down
7 changes: 7 additions & 0 deletions examples/run/common/throughput_st.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit fd34bb2

Please sign in to comment.