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 a838186
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ set(TRACCC_ALGEBRA_PLUGINS ARRAY CACHE STRING "Algebra plugin to use in the buil
message(STATUS "Building with plugin type: " ${TRACCC_ALGEBRA_PLUGINS})
add_definitions(-DALGEBRA_PLUGINS_INCLUDE_${TRACCC_ALGEBRA_PLUGINS})

# Inform the code that it is being build in Release mode.
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_definitions(-DTRACCC_BUILD_TYPE_IS_RELEASE)
endif()

# Build the traccc code.
add_subdirectory( core )
add_subdirectory( device/common )
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, with out 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 "../common/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 "../common/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
7 changes: 7 additions & 0 deletions examples/run/cpu/ccl_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "traccc/edm/cell.hpp"
#include "traccc/io/read_cells.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>

Expand Down Expand Up @@ -95,6 +98,8 @@ int main(int argc, char* argv[]) {
return -1;
}

TRACCC_OPTIMIZATION_WARNING();

std::string event_file = std::string(argv[1]);

std::cout << "Running " << argv[0] << " on " << event_file << std::endl;
Expand Down Expand Up @@ -129,6 +134,7 @@ int main(int argc, char* argv[]) {

auto time_process_p4 = std::chrono::high_resolution_clock::now();

TRACCC_OPTIMIZATION_WARNING();
std::cout << "\nCPU budget allocation" << std::endl;
std::cout << std::fixed;
std::cout << std::setw(13) << "Component"
Expand All @@ -155,6 +161,7 @@ int main(int argc, char* argv[]) {
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_read_start, time_process_p4) << " ms"
<< std::endl;
TRACCC_OPTIMIZATION_WARNING();

return 0;
}
5 changes: 5 additions & 0 deletions examples/run/cpu/seeding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "traccc/definitions/common.hpp"
#include "traccc/definitions/primitives.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// io
#include "traccc/io/read_geometry.hpp"
#include "traccc/io/read_measurements.hpp"
Expand Down Expand Up @@ -261,6 +264,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
}
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_spacepoints << " spacepoints" << std::endl;
std::cout << "- read " << n_measurements << " measurements" << std::endl;
Expand All @@ -276,6 +280,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
} else {
std::cout << "- ambiguity resolution: deactivated" << std::endl;
}
TRACCC_OPTIMIZATION_WARNING();

return EXIT_SUCCESS;
}
Expand Down
5 changes: 5 additions & 0 deletions examples/run/cpu/seq_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "traccc/io/utils.hpp"
#include "traccc/io/write.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// algorithms
#include "traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp"
#include "traccc/clusterization/clusterization_algorithm.hpp"
Expand Down Expand Up @@ -336,6 +339,7 @@ int seq_run(const traccc::opts::input_data& input_opts,
}
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_cells << " cells from " << n_modules
<< " modules" << std::endl;
Expand All @@ -349,6 +353,7 @@ int seq_run(const traccc::opts::input_data& input_opts,
std::cout << "- resolved " << n_ambiguity_free_tracks << " tracks"
<< std::endl;
std::cout << "==> Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return EXIT_SUCCESS;
}
Expand Down
5 changes: 5 additions & 0 deletions examples/run/cuda/seeding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include "traccc/seeding/seeding_algorithm.hpp"
#include "traccc/seeding/track_params_estimation.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// Detray include(s).
#include "detray/core/detector.hpp"
#include "detray/core/detector_metadata.hpp"
Expand Down Expand Up @@ -455,6 +458,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
std::cout << nsd_performance_writer.generate_report_str();
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_spacepoints << " spacepoints from "
<< n_modules << " modules" << std::endl;
Expand All @@ -469,6 +473,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
std::cout << "- created (cuda) " << n_fitted_tracks_cuda << " fitted tracks"
<< std::endl;
std::cout << "==>Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions examples/run/cuda/seq_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "traccc/seeding/seeding_algorithm.hpp"
#include "traccc/seeding/track_params_estimation.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// Detray include(s).
#include "detray/core/detector.hpp"
#include "detray/detectors/bfield.hpp"
Expand Down Expand Up @@ -492,6 +495,7 @@ int seq_run(const traccc::opts::detector& detector_opts,
sd_performance_writer.finalize();
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_cells << " cells from " << n_modules
<< " modules" << std::endl;
Expand All @@ -515,6 +519,7 @@ int seq_run(const traccc::opts::detector& detector_opts,
std::cout << "- fitted (cuda) " << n_fitted_tracks_cuda << " tracks"
<< std::endl;
std::cout << "==>Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions examples/run/cuda/truth_finding_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "traccc/resolution/fitting_performance_writer.hpp"
#include "traccc/utils/seed_generator.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// detray include(s).
#include "detray/core/detector.hpp"
#include "detray/core/detector_metadata.hpp"
Expand Down Expand Up @@ -331,6 +334,7 @@ int seq_run(const traccc::opts::track_finding& finding_opts,
fit_performance_writer.finalize();
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- created (cuda) " << n_found_tracks_cuda << " found tracks"
<< std::endl;
Expand All @@ -341,6 +345,7 @@ int seq_run(const traccc::opts::track_finding& finding_opts,
std::cout << "- created (cpu) " << n_fitted_tracks << " fitted tracks"
<< std::endl;
std::cout << "==>Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return 1;
}
Expand Down
5 changes: 5 additions & 0 deletions examples/run/cuda/truth_fitting_example_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "traccc/resolution/fitting_performance_writer.hpp"
#include "traccc/utils/seed_generator.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// detray include(s).
#include "detray/core/detector.hpp"
#include "detray/core/detector_metadata.hpp"
Expand Down Expand Up @@ -249,12 +252,14 @@ int main(int argc, char* argv[]) {
fit_performance_writer.finalize();
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- created (cuda) " << n_fitted_tracks_cuda << " fitted tracks"
<< std::endl;
std::cout << "- created (cpu) " << n_fitted_tracks << " fitted tracks"
<< std::endl;
std::cout << "==>Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return EXIT_SUCCESS;
}
5 changes: 5 additions & 0 deletions examples/run/kokkos/seeding_example_kokkos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "traccc/seeding/seeding_algorithm.hpp"
#include "traccc/seeding/track_params_estimation.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>

Expand Down Expand Up @@ -135,13 +138,15 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
sd_performance_writer.finalize();
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_spacepoints << " spacepoints from "
<< n_modules << " modules" << std::endl;
std::cout << "- created (cpu) " << n_seeds << " seeds" << std::endl;
std::cout << "- created (kokkos) " << n_seeds_kokkos << " seeds"
<< std::endl;
std::cout << "==>Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return 0;
}
Expand Down
7 changes: 7 additions & 0 deletions examples/run/openmp/io_dec_par_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "traccc/edm/spacepoint.hpp"
#include "traccc/io/demonstrator_edm.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>

Expand Down Expand Up @@ -88,8 +91,10 @@ traccc::demonstrator_result run(traccc::demonstrator_input input_data,

auto endAlgorithms = std::chrono::system_clock::now();
std::chrono::duration<double> diffAlgo = endAlgorithms - startAlgorithms;
TRACCC_OPTIMIZATION_WARNING();
std::cout << "Algorithms time: " << diffAlgo.count() << " sec."
<< std::endl;
TRACCC_OPTIMIZATION_WARNING();

std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_cells << " cells from " << n_modules
Expand Down Expand Up @@ -148,6 +153,8 @@ int main(int argc, char* argv[]) {

auto end = std::chrono::system_clock::now();
std::chrono::duration<double> diff = end - start;
TRACCC_OPTIMIZATION_WARNING();
std::cout << "Total execution time: " << diff.count() << " sec."
<< std::endl;
TRACCC_OPTIMIZATION_WARNING();
}
5 changes: 5 additions & 0 deletions examples/run/openmp/par_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "traccc/io/read_digitization_config.hpp"
#include "traccc/io/read_geometry.hpp"

// Local include(s).
#include "../common/optimization_warning.hpp"

// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>

Expand Down Expand Up @@ -163,6 +166,8 @@ int main(int argc, char *argv[]) {
auto end = std::chrono::system_clock::now();

std::chrono::duration<double> diff = end - start;
TRACCC_OPTIMIZATION_WARNING();
std::cout << "Execution time: " << diff.count() << " sec." << std::endl;
TRACCC_OPTIMIZATION_WARNING();
return result;
}
5 changes: 5 additions & 0 deletions examples/run/sycl/seeding_example_sycl.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// SYCL include(s)
#include <CL/sycl.hpp>

// Local include(s).
#include "../common/optimization_warning.hpp"

// algorithms
#include "traccc/seeding/seeding_algorithm.hpp"
#include "traccc/seeding/track_params_estimation.hpp"
Expand Down Expand Up @@ -264,12 +267,14 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
sd_performance_writer.finalize();
}

TRACCC_OPTIMIZATION_WARNING();
std::cout << "==> Statistics ... " << std::endl;
std::cout << "- read " << n_spacepoints << " spacepoints from "
<< n_modules << " modules" << std::endl;
std::cout << "- created (cpu) " << n_seeds << " seeds" << std::endl;
std::cout << "- created (sycl) " << n_seeds_sycl << " seeds" << std::endl;
std::cout << "==>Elapsed times...\n" << elapsedTimes << std::endl;
TRACCC_OPTIMIZATION_WARNING();

return 0;
}
Expand Down
Loading

0 comments on commit a838186

Please sign in to comment.