Skip to content

Commit 2b0b03a

Browse files
authored
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.
1 parent 592231d commit 2b0b03a

12 files changed

+132
-69
lines changed

examples/run/cuda/full_chain_algorithm.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ full_chain_algorithm::full_chain_algorithm(
6262
m_fitting(fitting_config,
6363
memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy,
6464
m_stream),
65-
m_result_copy(memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy),
6665
m_finder_config(finder_config),
6766
m_grid_config(grid_config),
6867
m_filter_config(filter_config),
@@ -113,7 +112,6 @@ full_chain_algorithm::full_chain_algorithm(const full_chain_algorithm& parent)
113112
m_fitting(parent.m_fitting_config,
114113
memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy,
115114
m_stream),
116-
m_result_copy(memory_resource{*m_cached_device_mr, &m_host_mr}, m_copy),
117115
m_finder_config(parent.m_finder_config),
118116
m_grid_config(parent.m_grid_config),
119117
m_filter_config(parent.m_filter_config),
@@ -179,8 +177,10 @@ full_chain_algorithm::output_type full_chain_algorithm::operator()(
179177
m_fitting(m_device_detector_view, m_field, navigation_buffer,
180178
track_candidates);
181179

182-
// Return the final container, copied back to the host.
183-
return m_result_copy(track_states);
180+
// Copy a limited amount of result data back to the host.
181+
output_type result{&m_host_mr};
182+
m_copy(track_states.headers, result)->wait();
183+
return result;
184184

185185
}
186186
// If not, copy the track parameters back to the host, and return a dummy

examples/run/cuda/full_chain_algorithm.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "traccc/cuda/seeding/seeding_algorithm.hpp"
1717
#include "traccc/cuda/seeding/track_params_estimation.hpp"
1818
#include "traccc/cuda/utils/stream.hpp"
19-
#include "traccc/device/container_d2h_copy_alg.hpp"
2019
#include "traccc/edm/cell.hpp"
2120
#include "traccc/edm/track_state.hpp"
2221
#include "traccc/fitting/kalman_filter/kalman_fitter.hpp"
@@ -30,6 +29,7 @@
3029
#include "detray/propagator/rk_stepper.hpp"
3130

3231
// VecMem include(s).
32+
#include <vecmem/containers/vector.hpp>
3333
#include <vecmem/memory/binary_page_memory_resource.hpp>
3434
#include <vecmem/memory/cuda/device_memory_resource.hpp>
3535
#include <vecmem/memory/memory_resource.hpp>
@@ -44,9 +44,10 @@ namespace traccc::cuda {
4444
///
4545
/// At least as much as is implemented in the project at any given moment.
4646
///
47-
class full_chain_algorithm : public algorithm<track_state_container_types::host(
48-
const cell_collection_types::host&,
49-
const cell_module_collection_types::host&)> {
47+
class full_chain_algorithm
48+
: public algorithm<vecmem::vector<fitting_result<default_algebra>>(
49+
const cell_collection_types::host&,
50+
const cell_module_collection_types::host&)> {
5051

5152
public:
5253
/// @name Type declaration(s)
@@ -161,9 +162,6 @@ class full_chain_algorithm : public algorithm<track_state_container_types::host(
161162
/// Track fitting algorithm
162163
fitting_algorithm m_fitting;
163164

164-
/// Algorithm copying the result container back to the host
165-
device::container_d2h_copy_alg<track_state_container_types> m_result_copy;
166-
167165
/// @}
168166

169167
/// @name Algorithm configurations

io/src/event_map2.cpp

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022 CERN for the benefit of the ACTS project
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -13,26 +13,37 @@
1313
#include "traccc/io/csv/make_measurement_reader.hpp"
1414
#include "traccc/io/csv/make_particle_reader.hpp"
1515
#include "traccc/io/utils.hpp"
16+
17+
// System include(s).
18+
#include <filesystem>
19+
1620
namespace traccc {
1721

1822
event_map2::event_map2(std::size_t event, const std::string& measurement_dir,
1923
const std::string& hit_dir,
2024
const std::string particle_dir) {
2125

2226
std::string io_measurement_hit_id_file =
23-
io::data_directory() + hit_dir +
24-
io::get_event_filename(event, "-measurement-simhit-map.csv");
27+
io::get_absolute_path((std::filesystem::path(hit_dir) /
28+
std::filesystem::path(io::get_event_filename(
29+
event, "-measurement-simhit-map.csv")))
30+
.native());
2531

26-
std::string io_particle_file =
27-
io::data_directory() + particle_dir +
28-
io::get_event_filename(event, "-particles.csv");
32+
std::string io_particle_file = io::get_absolute_path(
33+
(std::filesystem::path(particle_dir) /
34+
std::filesystem::path(io::get_event_filename(event, "-particles.csv")))
35+
.native());
2936

30-
std::string io_hit_file = io::data_directory() + hit_dir +
31-
io::get_event_filename(event, "-hits.csv");
37+
std::string io_hit_file = io::get_absolute_path(
38+
(std::filesystem::path(hit_dir) /
39+
std::filesystem::path(io::get_event_filename(event, "-hits.csv")))
40+
.native());
3241

3342
std::string io_measurement_file =
34-
io::data_directory() + measurement_dir +
35-
io::get_event_filename(event, "-measurements.csv");
43+
io::get_absolute_path((std::filesystem::path(measurement_dir) /
44+
std::filesystem::path(io::get_event_filename(
45+
event, "-measurements.csv")))
46+
.native());
3647

3748
auto mreader = io::csv::make_measurement_reader(io_measurement_file);
3849

io/src/mapper.cpp

+23-10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "traccc/clusterization/measurement_creation_algorithm.hpp"
2323
#include "traccc/clusterization/sparse_ccl_algorithm.hpp"
2424

25+
// System include(s).
26+
#include <filesystem>
27+
2528
namespace traccc {
2629

2730
particle_map generate_particle_map(std::size_t event,
@@ -31,8 +34,10 @@ particle_map generate_particle_map(std::size_t event,
3134

3235
// Read the particles from the relevant event file
3336
std::string io_particles_file =
34-
io::data_directory() + particle_dir +
35-
io::get_event_filename(event, "-particles_initial.csv");
37+
io::get_absolute_path((std::filesystem::path(particle_dir) /
38+
std::filesystem::path(io::get_event_filename(
39+
event, "-particles_initial.csv")))
40+
.native());
3641

3742
auto preader = io::csv::make_particle_reader(io_particles_file);
3843

@@ -61,8 +66,10 @@ hit_particle_map generate_hit_particle_map(std::size_t event,
6166
auto pmap = generate_particle_map(event, particle_dir);
6267

6368
// Read the hits from the relevant event file
64-
std::string io_hits_file = io::data_directory() + hits_dir +
65-
io::get_event_filename(event, "-hits.csv");
69+
std::string io_hits_file = io::get_absolute_path(
70+
(std::filesystem::path(hits_dir) /
71+
std::filesystem::path(io::get_event_filename(event, "-hits.csv")))
72+
.native());
6673

6774
auto hreader = io::csv::make_hit_reader(io_hits_file);
6875

@@ -93,17 +100,21 @@ hit_map generate_hit_map(std::size_t event, const std::string& hits_dir) {
93100
hit_map result;
94101

95102
// Read the hits from the relevant event file
96-
std::string io_hits_file = io::data_directory() + hits_dir +
97-
io::get_event_filename(event, "-hits.csv");
103+
std::string io_hits_file = io::get_absolute_path(
104+
(std::filesystem::path(hits_dir) /
105+
std::filesystem::path(io::get_event_filename(event, "-hits.csv")))
106+
.native());
98107

99108
auto hreader = io::csv::make_hit_reader(io_hits_file);
100109

101110
io::csv::hit iohit;
102111

103112
// Read the hits from the relevant event file
104113
std::string io_measurement_hit_id_file =
105-
io::data_directory() + hits_dir +
106-
io::get_event_filename(event, "-measurement-simhit-map.csv");
114+
io::get_absolute_path((std::filesystem::path(hits_dir) /
115+
std::filesystem::path(io::get_event_filename(
116+
event, "-measurement-simhit-map.csv")))
117+
.native());
107118

108119
auto mhid_reader =
109120
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,
141152
auto hmap = generate_hit_map(event, hits_dir);
142153

143154
// Read the cells from the relevant event file
144-
std::string io_cells_file = io::data_directory() + cells_dir +
145-
io::get_event_filename(event, "-cells.csv");
155+
std::string io_cells_file = io::get_absolute_path(
156+
(std::filesystem::path(cells_dir) /
157+
std::filesystem::path(io::get_event_filename(event, "-cells.csv")))
158+
.native());
146159

147160
auto creader = io::csv::make_cell_reader(io_cells_file);
148161

io/src/read_cells.cpp

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "read_binary.hpp"
1313
#include "traccc/io/utils.hpp"
1414

15+
// System include(s).
16+
#include <filesystem>
17+
1518
namespace traccc::io {
1619

1720
void read_cells(
@@ -23,19 +26,28 @@ void read_cells(
2326

2427
switch (format) {
2528
case data_format::csv: {
26-
read_cells(out,
27-
data_directory() + directory.data() +
28-
get_event_filename(event, "-cells.csv"),
29-
format, geom, dconfig, barcode_map, deduplicate);
29+
read_cells(
30+
out,
31+
get_absolute_path((std::filesystem::path(directory) /
32+
std::filesystem::path(
33+
get_event_filename(event, "-cells.csv")))
34+
.native()),
35+
format, geom, dconfig, barcode_map, deduplicate);
3036
break;
3137
}
3238
case data_format::binary: {
3339
details::read_binary_collection<cell_collection_types::host>(
34-
out.cells, data_directory() + directory.data() +
35-
get_event_filename(event, "-cells.dat"));
40+
out.cells,
41+
get_absolute_path((std::filesystem::path(directory) /
42+
std::filesystem::path(
43+
get_event_filename(event, "-cells.dat")))
44+
.native()));
3645
details::read_binary_collection<cell_module_collection_types::host>(
37-
out.modules, data_directory() + directory.data() +
38-
get_event_filename(event, "-modules.dat"));
46+
out.modules,
47+
get_absolute_path((std::filesystem::path(directory) /
48+
std::filesystem::path(get_event_filename(
49+
event, "-modules.dat")))
50+
.native()));
3951
break;
4052
}
4153
default:

io/src/read_digitization_config.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022 CERN for the benefit of the ACTS project
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -64,7 +64,7 @@ digitization_config read_digitization_config(std::string_view filename,
6464
data_format format) {
6565

6666
// Construct the full filename.
67-
std::string full_filename = data_directory() + filename.data();
67+
std::string full_filename = get_absolute_path(filename);
6868

6969
// Decide how to read the file.
7070
switch (format) {

io/src/read_geometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ std::pair<geometry,
6767
read_geometry(std::string_view filename, data_format format) {
6868

6969
// Construct the full file name.
70-
const std::string full_filename = data_directory() + filename.data();
70+
const std::string full_filename = get_absolute_path(filename);
7171

7272
// Decide how to read the file.
7373
switch (format) {

io/src/read_measurements.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022 CERN for the benefit of the ACTS project
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -12,6 +12,9 @@
1212
#include "read_binary.hpp"
1313
#include "traccc/io/utils.hpp"
1414

15+
// System include(s).
16+
#include <filesystem>
17+
1518
namespace traccc::io {
1619

1720
void read_measurements(measurement_reader_output& out, std::size_t event,
@@ -21,20 +24,27 @@ void read_measurements(measurement_reader_output& out, std::size_t event,
2124
case data_format::csv: {
2225
read_measurements(
2326
out,
24-
data_directory() + directory.data() +
25-
get_event_filename(event, "-measurements.csv"),
27+
get_absolute_path((std::filesystem::path(directory) /
28+
std::filesystem::path(get_event_filename(
29+
event, "-measurements.csv")))
30+
.native()),
2631
format);
2732
break;
2833
}
2934
case data_format::binary: {
3035

3136
details::read_binary_collection<measurement_collection_types::host>(
3237
out.measurements,
33-
data_directory() + directory.data() +
34-
get_event_filename(event, "-measurements.dat"));
38+
get_absolute_path((std::filesystem::path(directory) /
39+
std::filesystem::path(get_event_filename(
40+
event, "-measurements.dat")))
41+
.native()));
3542
details::read_binary_collection<cell_module_collection_types::host>(
36-
out.modules, data_directory() + directory.data() +
37-
get_event_filename(event, "-modules.dat"));
43+
out.modules,
44+
get_absolute_path((std::filesystem::path(directory) /
45+
std::filesystem::path(get_event_filename(
46+
event, "-modules.dat")))
47+
.native()));
3848
break;
3949
}
4050
default:

io/src/read_particles.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022 CERN for the benefit of the ACTS project
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -11,6 +11,9 @@
1111
#include "csv/read_particles.hpp"
1212
#include "traccc/io/utils.hpp"
1313

14+
// System include(s).
15+
#include <filesystem>
16+
1417
namespace traccc::io {
1518

1619
particle_collection_types::host read_particles(std::size_t event,
@@ -21,8 +24,10 @@ particle_collection_types::host read_particles(std::size_t event,
2124
switch (format) {
2225
case data_format::csv:
2326
return read_particles(
24-
data_directory() + directory.data() +
25-
get_event_filename(event, "-particles.csv"),
27+
get_absolute_path((std::filesystem::path(directory) /
28+
std::filesystem::path(get_event_filename(
29+
event, "-particles.csv")))
30+
.native()),
2631
format, mr);
2732
default:
2833
throw std::invalid_argument("Unsupported data format");

0 commit comments

Comments
 (0)