From 2b0b03a78b5881017e97f900e602cd941742b68a Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay <30694331+krasznaa@users.noreply.github.com> Date: Mon, 6 May 2024 17:17:58 +0200 Subject: [PATCH] CUDA Throughput Improvement, main branch (2024.05.06.) (#576) * Made I/O functions use traccc::io::get_absolute_path(...) during reading. This is to make it possible to pick up files from anywhere, as long as the user provides an absolute file name. * Returning a reduced amount of info about the fitted tracks. This is to avoid the (currently) very expensive copy of the jagged vector of track states back to the host. * Fixed the geometry file locations for the tests. So that they would not be treated as absolute path names by the updated I/O code. * Removed the comparison of chi2 values from the fit results. This is a temporary measure, until the chi2 values "start behaving". But for now it's not completely ridiculous that the CPU and GPU code would produce different values for that parameter. --- examples/run/cuda/full_chain_algorithm.cpp | 8 ++-- examples/run/cuda/full_chain_algorithm.hpp | 12 +++--- io/src/event_map2.cpp | 31 +++++++++++----- io/src/mapper.cpp | 33 ++++++++++++----- io/src/read_cells.cpp | 28 ++++++++++---- io/src/read_digitization_config.cpp | 4 +- io/src/read_geometry.cpp | 2 +- io/src/read_measurements.cpp | 24 ++++++++---- io/src/read_particles.cpp | 11 ++++-- io/src/read_spacepoints.cpp | 37 +++++++++++++------ .../performance/details/is_same_object.cpp | 5 +-- tests/io/test_mapper.cpp | 6 +-- 12 files changed, 132 insertions(+), 69 deletions(-) diff --git a/examples/run/cuda/full_chain_algorithm.cpp b/examples/run/cuda/full_chain_algorithm.cpp index 7c0063f1a4..63a341cc8d 100644 --- a/examples/run/cuda/full_chain_algorithm.cpp +++ b/examples/run/cuda/full_chain_algorithm.cpp @@ -62,7 +62,6 @@ full_chain_algorithm::full_chain_algorithm( m_fitting(fitting_config, memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy, m_stream), - m_result_copy(memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy), m_finder_config(finder_config), m_grid_config(grid_config), m_filter_config(filter_config), @@ -113,7 +112,6 @@ full_chain_algorithm::full_chain_algorithm(const full_chain_algorithm& parent) m_fitting(parent.m_fitting_config, memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy, m_stream), - m_result_copy(memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy), m_finder_config(parent.m_finder_config), m_grid_config(parent.m_grid_config), m_filter_config(parent.m_filter_config), @@ -179,8 +177,10 @@ full_chain_algorithm::output_type full_chain_algorithm::operator()( m_fitting(m_device_detector_view, m_field, navigation_buffer, track_candidates); - // Return the final container, copied back to the host. - return m_result_copy(track_states); + // Copy a limited amount of result data back to the host. + output_type result{&m_host_mr}; + m_copy(track_states.headers, result)->wait(); + return result; } // If not, copy the track parameters back to the host, and return a dummy diff --git a/examples/run/cuda/full_chain_algorithm.hpp b/examples/run/cuda/full_chain_algorithm.hpp index c2c7b2e817..78171e08b7 100644 --- a/examples/run/cuda/full_chain_algorithm.hpp +++ b/examples/run/cuda/full_chain_algorithm.hpp @@ -16,7 +16,6 @@ #include "traccc/cuda/seeding/seeding_algorithm.hpp" #include "traccc/cuda/seeding/track_params_estimation.hpp" #include "traccc/cuda/utils/stream.hpp" -#include "traccc/device/container_d2h_copy_alg.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/track_state.hpp" #include "traccc/fitting/kalman_filter/kalman_fitter.hpp" @@ -30,6 +29,7 @@ #include "detray/propagator/rk_stepper.hpp" // VecMem include(s). +#include #include #include #include @@ -44,9 +44,10 @@ namespace traccc::cuda { /// /// At least as much as is implemented in the project at any given moment. /// -class full_chain_algorithm : public algorithm { +class full_chain_algorithm + : public algorithm>( + const cell_collection_types::host&, + const cell_module_collection_types::host&)> { public: /// @name Type declaration(s) @@ -161,9 +162,6 @@ class full_chain_algorithm : public algorithm m_result_copy; - /// @} /// @name Algorithm configurations diff --git a/io/src/event_map2.cpp b/io/src/event_map2.cpp index 6a4e07a557..ad982f8f01 100644 --- a/io/src/event_map2.cpp +++ b/io/src/event_map2.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2022 CERN for the benefit of the ACTS project + * (c) 2022-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -13,6 +13,10 @@ #include "traccc/io/csv/make_measurement_reader.hpp" #include "traccc/io/csv/make_particle_reader.hpp" #include "traccc/io/utils.hpp" + +// System include(s). +#include + namespace traccc { event_map2::event_map2(std::size_t event, const std::string& measurement_dir, @@ -20,19 +24,26 @@ event_map2::event_map2(std::size_t event, const std::string& measurement_dir, const std::string particle_dir) { std::string io_measurement_hit_id_file = - io::data_directory() + hit_dir + - io::get_event_filename(event, "-measurement-simhit-map.csv"); + io::get_absolute_path((std::filesystem::path(hit_dir) / + std::filesystem::path(io::get_event_filename( + event, "-measurement-simhit-map.csv"))) + .native()); - std::string io_particle_file = - io::data_directory() + particle_dir + - io::get_event_filename(event, "-particles.csv"); + std::string io_particle_file = io::get_absolute_path( + (std::filesystem::path(particle_dir) / + std::filesystem::path(io::get_event_filename(event, "-particles.csv"))) + .native()); - std::string io_hit_file = io::data_directory() + hit_dir + - io::get_event_filename(event, "-hits.csv"); + std::string io_hit_file = io::get_absolute_path( + (std::filesystem::path(hit_dir) / + std::filesystem::path(io::get_event_filename(event, "-hits.csv"))) + .native()); std::string io_measurement_file = - io::data_directory() + measurement_dir + - io::get_event_filename(event, "-measurements.csv"); + io::get_absolute_path((std::filesystem::path(measurement_dir) / + std::filesystem::path(io::get_event_filename( + event, "-measurements.csv"))) + .native()); auto mreader = io::csv::make_measurement_reader(io_measurement_file); diff --git a/io/src/mapper.cpp b/io/src/mapper.cpp index 501bbaa307..53f0768110 100644 --- a/io/src/mapper.cpp +++ b/io/src/mapper.cpp @@ -22,6 +22,9 @@ #include "traccc/clusterization/measurement_creation_algorithm.hpp" #include "traccc/clusterization/sparse_ccl_algorithm.hpp" +// System include(s). +#include + namespace traccc { particle_map generate_particle_map(std::size_t event, @@ -31,8 +34,10 @@ particle_map generate_particle_map(std::size_t event, // Read the particles from the relevant event file std::string io_particles_file = - io::data_directory() + particle_dir + - io::get_event_filename(event, "-particles_initial.csv"); + io::get_absolute_path((std::filesystem::path(particle_dir) / + std::filesystem::path(io::get_event_filename( + event, "-particles_initial.csv"))) + .native()); auto preader = io::csv::make_particle_reader(io_particles_file); @@ -61,8 +66,10 @@ hit_particle_map generate_hit_particle_map(std::size_t event, auto pmap = generate_particle_map(event, particle_dir); // Read the hits from the relevant event file - std::string io_hits_file = io::data_directory() + hits_dir + - io::get_event_filename(event, "-hits.csv"); + std::string io_hits_file = io::get_absolute_path( + (std::filesystem::path(hits_dir) / + std::filesystem::path(io::get_event_filename(event, "-hits.csv"))) + .native()); auto hreader = io::csv::make_hit_reader(io_hits_file); @@ -93,8 +100,10 @@ hit_map generate_hit_map(std::size_t event, const std::string& hits_dir) { hit_map result; // Read the hits from the relevant event file - std::string io_hits_file = io::data_directory() + hits_dir + - io::get_event_filename(event, "-hits.csv"); + std::string io_hits_file = io::get_absolute_path( + (std::filesystem::path(hits_dir) / + std::filesystem::path(io::get_event_filename(event, "-hits.csv"))) + .native()); auto hreader = io::csv::make_hit_reader(io_hits_file); @@ -102,8 +111,10 @@ hit_map generate_hit_map(std::size_t event, const std::string& hits_dir) { // Read the hits from the relevant event file std::string io_measurement_hit_id_file = - io::data_directory() + hits_dir + - io::get_event_filename(event, "-measurement-simhit-map.csv"); + io::get_absolute_path((std::filesystem::path(hits_dir) / + std::filesystem::path(io::get_event_filename( + event, "-measurement-simhit-map.csv"))) + .native()); auto mhid_reader = io::csv::make_measurement_hit_id_reader(io_measurement_hit_id_file); @@ -141,8 +152,10 @@ hit_cell_map generate_hit_cell_map(std::size_t event, auto hmap = generate_hit_map(event, hits_dir); // Read the cells from the relevant event file - std::string io_cells_file = io::data_directory() + cells_dir + - io::get_event_filename(event, "-cells.csv"); + std::string io_cells_file = io::get_absolute_path( + (std::filesystem::path(cells_dir) / + std::filesystem::path(io::get_event_filename(event, "-cells.csv"))) + .native()); auto creader = io::csv::make_cell_reader(io_cells_file); diff --git a/io/src/read_cells.cpp b/io/src/read_cells.cpp index 16c86a415e..f3dda25b2b 100644 --- a/io/src/read_cells.cpp +++ b/io/src/read_cells.cpp @@ -12,6 +12,9 @@ #include "read_binary.hpp" #include "traccc/io/utils.hpp" +// System include(s). +#include + namespace traccc::io { void read_cells( @@ -23,19 +26,28 @@ void read_cells( switch (format) { case data_format::csv: { - read_cells(out, - data_directory() + directory.data() + - get_event_filename(event, "-cells.csv"), - format, geom, dconfig, barcode_map, deduplicate); + read_cells( + out, + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path( + get_event_filename(event, "-cells.csv"))) + .native()), + format, geom, dconfig, barcode_map, deduplicate); break; } case data_format::binary: { details::read_binary_collection( - out.cells, data_directory() + directory.data() + - get_event_filename(event, "-cells.dat")); + out.cells, + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path( + get_event_filename(event, "-cells.dat"))) + .native())); details::read_binary_collection( - out.modules, data_directory() + directory.data() + - get_event_filename(event, "-modules.dat")); + out.modules, + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-modules.dat"))) + .native())); break; } default: diff --git a/io/src/read_digitization_config.cpp b/io/src/read_digitization_config.cpp index 19c86cc27a..f5485a54d1 100644 --- a/io/src/read_digitization_config.cpp +++ b/io/src/read_digitization_config.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2022 CERN for the benefit of the ACTS project + * (c) 2022-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -64,7 +64,7 @@ digitization_config read_digitization_config(std::string_view filename, data_format format) { // Construct the full filename. - std::string full_filename = data_directory() + filename.data(); + std::string full_filename = get_absolute_path(filename); // Decide how to read the file. switch (format) { diff --git a/io/src/read_geometry.cpp b/io/src/read_geometry.cpp index c88e8fe172..a73dad881d 100644 --- a/io/src/read_geometry.cpp +++ b/io/src/read_geometry.cpp @@ -67,7 +67,7 @@ std::pair + namespace traccc::io { void read_measurements(measurement_reader_output& out, std::size_t event, @@ -21,8 +24,10 @@ void read_measurements(measurement_reader_output& out, std::size_t event, case data_format::csv: { read_measurements( out, - data_directory() + directory.data() + - get_event_filename(event, "-measurements.csv"), + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-measurements.csv"))) + .native()), format); break; } @@ -30,11 +35,16 @@ void read_measurements(measurement_reader_output& out, std::size_t event, details::read_binary_collection( out.measurements, - data_directory() + directory.data() + - get_event_filename(event, "-measurements.dat")); + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-measurements.dat"))) + .native())); details::read_binary_collection( - out.modules, data_directory() + directory.data() + - get_event_filename(event, "-modules.dat")); + out.modules, + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-modules.dat"))) + .native())); break; } default: diff --git a/io/src/read_particles.cpp b/io/src/read_particles.cpp index 406cc8b0fd..670c932ec5 100644 --- a/io/src/read_particles.cpp +++ b/io/src/read_particles.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2022 CERN for the benefit of the ACTS project + * (c) 2022-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -11,6 +11,9 @@ #include "csv/read_particles.hpp" #include "traccc/io/utils.hpp" +// System include(s). +#include + namespace traccc::io { particle_collection_types::host read_particles(std::size_t event, @@ -21,8 +24,10 @@ particle_collection_types::host read_particles(std::size_t event, switch (format) { case data_format::csv: return read_particles( - data_directory() + directory.data() + - get_event_filename(event, "-particles.csv"), + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-particles.csv"))) + .native()), format, mr); default: throw std::invalid_argument("Unsupported data format"); diff --git a/io/src/read_spacepoints.cpp b/io/src/read_spacepoints.cpp index 52e13ec6eb..fae5004dea 100644 --- a/io/src/read_spacepoints.cpp +++ b/io/src/read_spacepoints.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2022 CERN for the benefit of the ACTS project + * (c) 2022-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -12,6 +12,9 @@ #include "read_binary.hpp" #include "traccc/io/utils.hpp" +// System include(s). +#include + namespace traccc::io { void read_spacepoints(spacepoint_reader_output& out, std::size_t event, @@ -22,22 +25,34 @@ void read_spacepoints(spacepoint_reader_output& out, std::size_t event, case data_format::csv: { read_spacepoints( out, - data_directory() + directory.data() + - get_event_filename(event, "-hits.csv"), - data_directory() + directory.data() + - get_event_filename(event, "-measurements.csv"), - data_directory() + directory.data() + - get_event_filename(event, "-measurement-simhit-map.csv"), + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path( + get_event_filename(event, "-hits.csv"))) + .native()), + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-measurements.csv"))) + .native()), + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-measurement-simhit-map.csv"))) + .native()), geom, format); break; } case data_format::binary: { details::read_binary_collection( - out.spacepoints, data_directory() + directory.data() + - get_event_filename(event, "-hits.dat")); + out.spacepoints, + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path( + get_event_filename(event, "-hits.dat"))) + .native())); details::read_binary_collection( - out.modules, data_directory() + directory.data() + - get_event_filename(event, "-modules.dat")); + out.modules, + get_absolute_path((std::filesystem::path(directory) / + std::filesystem::path(get_event_filename( + event, "-modules.dat"))) + .native())); break; } default: diff --git a/performance/src/performance/details/is_same_object.cpp b/performance/src/performance/details/is_same_object.cpp index a3958b3b44..7081349828 100644 --- a/performance/src/performance/details/is_same_object.cpp +++ b/performance/src/performance/details/is_same_object.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2022-2023 CERN for the benefit of the ACTS project + * (c) 2022-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -141,8 +141,7 @@ bool is_same_object>::operator()( return (is_same_object(m_ref.get().fit_params, m_unc)(obj.fit_params) && - is_same_angle(obj.ndf, m_ref.get().ndf, m_unc) && - is_same_angle(obj.chi2, m_ref.get().chi2, m_unc)); + is_same_scalar(obj.ndf, m_ref.get().ndf, m_unc)); } /// @} diff --git a/tests/io/test_mapper.cpp b/tests/io/test_mapper.cpp index 8521098b59..9b2ad3e933 100644 --- a/tests/io/test_mapper.cpp +++ b/tests/io/test_mapper.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2022 CERN for the benefit of the ACTS project + * (c) 2022-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -16,9 +16,9 @@ std::size_t event = 0; -std::string detector_file = "/tml_detector/trackml-detector.csv"; +std::string detector_file = "tml_detector/trackml-detector.csv"; std::string digi_config_file = - "/tml_detector/default-geometric-config-generic.json"; + "tml_detector/default-geometric-config-generic.json"; std::string hits_dir = "../tests/io/mock_data/"; std::string cells_dir = "../tests/io/mock_data/"; std::string particles_dir = "../tests/io/mock_data/";