From 7ec55837f70dde78d28319b32750a70fad5ce345 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Mon, 15 Apr 2024 15:17:36 +0200 Subject: [PATCH 1/4] Re-worked the (host) component connection algorithm. Renamed the class, and made sure that it would work with "device types" instead of using templating unnecessarily. --- core/CMakeLists.txt | 7 +- .../clusterization_algorithm.hpp | 4 +- ...hpp => component_connection_algorithm.hpp} | 16 ++- .../clusterization/detail/sparse_ccl.hpp | 136 ------------------ .../clusterization/details/sparse_ccl.hpp | 79 ++++++++++ .../traccc/clusterization/impl/sparse_ccl.ipp | 92 ++++++++++++ .../clusterization_algorithm.cpp | 2 +- .../clusterization/component_connection.cpp | 39 ----- .../component_connection_algorithm.cpp | 47 ++++++ examples/run/cpu/ccl_example.cpp | 10 +- io/src/mapper.cpp | 6 +- tests/cpu/seq_single_module.cpp | 8 +- 12 files changed, 246 insertions(+), 200 deletions(-) rename core/include/traccc/clusterization/{component_connection.hpp => component_connection_algorithm.hpp} (75%) delete mode 100644 core/include/traccc/clusterization/detail/sparse_ccl.hpp create mode 100644 core/include/traccc/clusterization/details/sparse_ccl.hpp create mode 100644 core/include/traccc/clusterization/impl/sparse_ccl.ipp delete mode 100644 core/src/clusterization/component_connection.cpp create mode 100644 core/src/clusterization/component_connection_algorithm.cpp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e5bda88eb6..a4f2800bd3 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -41,9 +41,10 @@ traccc_add_library( traccc_core core TYPE SHARED "include/traccc/utils/subspace.hpp" # Clusterization algorithmic code. "include/traccc/clusterization/detail/measurement_creation_helper.hpp" - "include/traccc/clusterization/detail/sparse_ccl.hpp" - "include/traccc/clusterization/component_connection.hpp" - "src/clusterization/component_connection.cpp" + "include/traccc/clusterization/details/sparse_ccl.hpp" + "include/traccc/clusterization/impl/sparse_ccl.ipp" + "include/traccc/clusterization/component_connection_algorithm.hpp" + "src/clusterization/component_connection_algorithm.cpp" "include/traccc/clusterization/clusterization_algorithm.hpp" "src/clusterization/clusterization_algorithm.cpp" "include/traccc/clusterization/spacepoint_formation.hpp" diff --git a/core/include/traccc/clusterization/clusterization_algorithm.hpp b/core/include/traccc/clusterization/clusterization_algorithm.hpp index 2f31191103..497d17e79e 100644 --- a/core/include/traccc/clusterization/clusterization_algorithm.hpp +++ b/core/include/traccc/clusterization/clusterization_algorithm.hpp @@ -8,7 +8,7 @@ #pragma once // Library include(s). -#include "traccc/clusterization/component_connection.hpp" +#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/measurement.hpp" @@ -54,7 +54,7 @@ class clusterization_algorithm /// @{ /// Per-module cluster creation algorithm - component_connection m_cc; + component_connection_algorithm m_cc; /// Per-module measurement creation algorithm measurement_creation m_mc; diff --git a/core/include/traccc/clusterization/component_connection.hpp b/core/include/traccc/clusterization/component_connection_algorithm.hpp similarity index 75% rename from core/include/traccc/clusterization/component_connection.hpp rename to core/include/traccc/clusterization/component_connection_algorithm.hpp index 06059fe47c..0cf0ac8f07 100644 --- a/core/include/traccc/clusterization/component_connection.hpp +++ b/core/include/traccc/clusterization/component_connection_algorithm.hpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -30,14 +30,16 @@ namespace traccc { /// the host- and device versions of the EDM, making use of a single /// implementation internally. /// -class component_connection : public algorithm { +class component_connection_algorithm + : public algorithm { public: /// Constructor for component_connection /// /// @param mr is the memory resource - component_connection(vecmem::memory_resource& mr) : m_mr(mr) {} + /// + component_connection_algorithm(vecmem::memory_resource& mr); /// @name Operator(s) to use in host code /// @{ @@ -45,13 +47,13 @@ class component_connection : public algorithm m_mr; -}; // class component_connection +}; // class component_connection_algorithm } // namespace traccc diff --git a/core/include/traccc/clusterization/detail/sparse_ccl.hpp b/core/include/traccc/clusterization/detail/sparse_ccl.hpp deleted file mode 100644 index 89f55e1287..0000000000 --- a/core/include/traccc/clusterization/detail/sparse_ccl.hpp +++ /dev/null @@ -1,136 +0,0 @@ -/** TRACCC library, part of the ACTS project (R&D line) - * - * (c) 2021-2022 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Library include(s). -#include "traccc/definitions/qualifiers.hpp" -#include "traccc/edm/cell.hpp" - -// VecMem include(s). -#include - -// System include(s). -#include - -namespace traccc { - -/// Implemementation of SparseCCL, following -/// [DOI: 10.1109/DASIP48288.2019.9049184] -/// -/// Requires cells to be sorted in column major -namespace detail { - -/// Find root of the tree for entry @param e -/// -/// @param L an equivalance table -/// -/// @return the root of @param e -template -TRACCC_HOST_DEVICE inline unsigned int find_root(const ccl_vector_t& L, - unsigned int e) { - - unsigned int r = e; - assert(r < L.size()); - while (L[r] != r) { - r = L[r]; - assert(r < L.size()); - } - return r; -} - -/// Create a union of two entries @param e1 and @param e2 -/// -/// @param L an equivalance table -/// -/// @return the rleast common ancestor of the entries -template -TRACCC_HOST_DEVICE inline unsigned int make_union(ccl_vector_t& L, - unsigned int e1, - unsigned int e2) { - - int e; - if (e1 < e2) { - e = e1; - assert(e2 < L.size()); - L[e2] = e; - } else { - e = e2; - assert(e1 < L.size()); - L[e1] = e; - } - return e; -} - -/// Helper method to find adjacent cells -/// -/// @param a the first cell -/// @param b the second cell -/// -/// @return boolan to indicate 8-cell connectivity -TRACCC_HOST_DEVICE inline bool is_adjacent(traccc::cell a, traccc::cell b) { - return (a.channel0 - b.channel0) * (a.channel0 - b.channel0) <= 1 and - (a.channel1 - b.channel1) * (a.channel1 - b.channel1) <= 1 and - a.module_link == b.module_link; -} - -/// Helper method to find define distance, -/// does not need abs, as channels are sorted in -/// column major -/// -/// @param a the first cell -/// @param b the second cell -/// -/// @return boolan to indicate !8-cell connectivity -TRACCC_HOST_DEVICE inline bool is_far_enough(traccc::cell a, traccc::cell b) { - return (a.channel1 - b.channel1) > 1 || a.module_link != b.module_link; -} - -/// Sparce CCL algorithm -/// -/// @param cells is the cell collection -/// @param L is the vector of the output indices (to which cluster a cell -/// belongs to) -/// @param labels is the number of clusters found -/// @return number of clusters -template -TRACCC_HOST_DEVICE inline unsigned int sparse_ccl( - const cell_collection_t& cells, ccl_vector_t& L) { - - unsigned int labels = 0; - - // The number of cells. - const unsigned int n_cells = cells.size(); - - // first scan: pixel association - unsigned int start_j = 0; - for (unsigned int i = 0; i < n_cells; ++i) { - L[i] = i; - unsigned int ai = i; - for (unsigned int j = start_j; j < i; ++j) { - if (is_adjacent(cells[i], cells[j])) { - ai = make_union(L, ai, find_root(L, j)); - } else if (is_far_enough(cells[i], cells[j])) { - ++start_j; - } - } - } - - // second scan: transitive closure - for (unsigned int i = 0; i < n_cells; ++i) { - if (L[i] == i) { - L[i] = labels++; - } else { - L[i] = L[L[i]]; - } - } - - return labels; -} -} // namespace detail - -} // namespace traccc diff --git a/core/include/traccc/clusterization/details/sparse_ccl.hpp b/core/include/traccc/clusterization/details/sparse_ccl.hpp new file mode 100644 index 0000000000..e108c3217d --- /dev/null +++ b/core/include/traccc/clusterization/details/sparse_ccl.hpp @@ -0,0 +1,79 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2021-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Library include(s). +#include "traccc/definitions/qualifiers.hpp" +#include "traccc/edm/cell.hpp" + +// VecMem include(s). +#include + +namespace traccc::details { + +/// Implemementation of SparseCCL, following +/// [DOI: 10.1109/DASIP48288.2019.9049184] +/// +/// Requires cells to be sorted in column major + +/// Find root of the tree for entry @param e +/// +/// @param labels an equivalance table +/// +/// @return the root of @param e +/// +TRACCC_HOST_DEVICE inline unsigned int find_root( + const vecmem::device_vector& labels, unsigned int e); + +/// Create a union of two entries @param e1 and @param e2 +/// +/// @param labels an equivalance table +/// +/// @return the rleast common ancestor of the entries +/// +TRACCC_HOST_DEVICE inline unsigned int make_union( + vecmem::device_vector& labels, unsigned int e1, + unsigned int e2); + +/// Helper method to find adjacent cells +/// +/// @param a the first cell +/// @param b the second cell +/// +/// @return boolan to indicate 8-cell connectivity +/// +TRACCC_HOST_DEVICE inline bool is_adjacent(const traccc::cell& a, + const traccc::cell& b); + +/// Helper method to find define distance, +/// does not need abs, as channels are sorted in +/// column major +/// +/// @param a the first cell +/// @param b the second cell +/// +/// @return boolan to indicate !8-cell connectivity +/// +TRACCC_HOST_DEVICE inline bool is_far_enough(const traccc::cell& a, + const traccc::cell& b); + +/// Sparce CCL algorithm +/// +/// @param cells is the cell collection +/// @param labels is the vector of the output indices (to which cluster a cell +/// belongs to) +/// @return number of clusters +/// +TRACCC_HOST_DEVICE inline unsigned int sparse_ccl( + const cell_collection_types::const_device& cells, + vecmem::device_vector& labels); + +} // namespace traccc::details + +// Include the implementation. +#include "traccc/clusterization/impl/sparse_ccl.ipp" diff --git a/core/include/traccc/clusterization/impl/sparse_ccl.ipp b/core/include/traccc/clusterization/impl/sparse_ccl.ipp new file mode 100644 index 0000000000..6573a167e9 --- /dev/null +++ b/core/include/traccc/clusterization/impl/sparse_ccl.ipp @@ -0,0 +1,92 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2021-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// System include(s). +#include + +namespace traccc::details { + +TRACCC_HOST_DEVICE inline unsigned int find_root( + const vecmem::device_vector& labels, unsigned int e) { + + unsigned int r = e; + assert(r < labels.size()); + while (labels[r] != r) { + r = labels[r]; + assert(r < labels.size()); + } + return r; +} + +TRACCC_HOST_DEVICE inline unsigned int make_union( + vecmem::device_vector& labels, unsigned int e1, + unsigned int e2) { + + int e; + if (e1 < e2) { + e = e1; + assert(e2 < labels.size()); + labels[e2] = e; + } else { + e = e2; + assert(e1 < labels.size()); + labels[e1] = e; + } + return e; +} + +TRACCC_HOST_DEVICE inline bool is_adjacent(const traccc::cell& a, + const traccc::cell& b) { + + return (a.channel0 - b.channel0) * (a.channel0 - b.channel0) <= 1 and + (a.channel1 - b.channel1) * (a.channel1 - b.channel1) <= 1 and + a.module_link == b.module_link; +} + +TRACCC_HOST_DEVICE inline bool is_far_enough(const traccc::cell& a, + const traccc::cell& b) { + return (a.channel1 - b.channel1) > 1 || a.module_link != b.module_link; +} + +TRACCC_HOST_DEVICE inline unsigned int sparse_ccl( + const cell_collection_types::const_device& cells, + vecmem::device_vector& labels) { + + unsigned int nlabels = 0; + + // The number of cells. + const unsigned int n_cells = cells.size(); + + // first scan: pixel association + unsigned int start_j = 0; + for (unsigned int i = 0; i < n_cells; ++i) { + labels[i] = i; + unsigned int ai = i; + for (unsigned int j = start_j; j < i; ++j) { + if (is_adjacent(cells[i], cells[j])) { + ai = make_union(labels, ai, find_root(labels, j)); + } else if (is_far_enough(cells[i], cells[j])) { + ++start_j; + } + } + } + + // second scan: transitive closure + for (unsigned int i = 0; i < n_cells; ++i) { + if (labels[i] == i) { + labels[i] = nlabels++; + } else { + labels[i] = labels[labels[i]]; + } + } + + return nlabels; +} + +} // namespace traccc::details diff --git a/core/src/clusterization/clusterization_algorithm.cpp b/core/src/clusterization/clusterization_algorithm.cpp index 2ac184d637..10af3b6bea 100644 --- a/core/src/clusterization/clusterization_algorithm.cpp +++ b/core/src/clusterization/clusterization_algorithm.cpp @@ -17,7 +17,7 @@ clusterization_algorithm::output_type clusterization_algorithm::operator()( const cell_collection_types::host& cells, const cell_module_collection_types::host& modules) const { - return m_mc(m_cc(cells), modules); + return m_mc(m_cc(vecmem::get_data(cells)), modules); } } // namespace traccc diff --git a/core/src/clusterization/component_connection.cpp b/core/src/clusterization/component_connection.cpp deleted file mode 100644 index 9de137ee85..0000000000 --- a/core/src/clusterization/component_connection.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** 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 - */ - -// Library include(s). -#include "traccc/clusterization/component_connection.hpp" - -#include "traccc/clusterization/detail/sparse_ccl.hpp" - -// VecMem include(s). -#include -#include - -namespace traccc { - -component_connection::output_type component_connection::operator()( - const cell_collection_types::host& cells) const { - - unsigned int num_clusters = 0; - std::vector CCL_indices(cells.size()); - - // Run SparseCCL to fill CCL indices - num_clusters = detail::sparse_ccl(cells, CCL_indices); - - // Create the result container. - output_type result(num_clusters, &(m_mr.get())); - - // Add cells to their clusters - for (std::size_t i = 0; i < CCL_indices.size(); ++i) { - result.get_items()[CCL_indices[i]].push_back(cells[i]); - } - - return result; -} - -} // namespace traccc diff --git a/core/src/clusterization/component_connection_algorithm.cpp b/core/src/clusterization/component_connection_algorithm.cpp new file mode 100644 index 0000000000..1159aeb16f --- /dev/null +++ b/core/src/clusterization/component_connection_algorithm.cpp @@ -0,0 +1,47 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Library include(s). +#include "traccc/clusterization/component_connection_algorithm.hpp" + +#include "traccc/clusterization/details/sparse_ccl.hpp" + +// VecMem include(s). +#include +#include + +namespace traccc { + +component_connection_algorithm::component_connection_algorithm( + vecmem::memory_resource& mr) + : m_mr(mr) {} + +component_connection_algorithm::output_type +component_connection_algorithm::operator()( + const cell_collection_types::const_view& cells_view) const { + + // Run SparseCCL to fill CCL indices. + const cell_collection_types::const_device cells{cells_view}; + vecmem::vector cluster_indices{cells.size(), &(m_mr.get())}; + vecmem::device_vector cluster_indices_device{ + vecmem::get_data(cluster_indices)}; + const unsigned int num_clusters = + details::sparse_ccl(cells, cluster_indices_device); + + // Create the result container. + output_type clusters(num_clusters, &(m_mr.get())); + + // Add cells to their clusters. + for (std::size_t i = 0; i < cluster_indices.size(); ++i) { + clusters.get_items()[cluster_indices[i]].push_back(cells[i]); + } + + // Return the clusters. + return clusters; +} + +} // namespace traccc diff --git a/examples/run/cpu/ccl_example.cpp b/examples/run/cpu/ccl_example.cpp index d4407280c0..f24e6dab54 100644 --- a/examples/run/cpu/ccl_example.cpp +++ b/examples/run/cpu/ccl_example.cpp @@ -1,13 +1,13 @@ /* * TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ // Project include(s). -#include "traccc/clusterization/component_connection.hpp" +#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/io/read_cells.hpp" @@ -83,9 +83,9 @@ void print_statistics(const traccc::cell_collection_types::host& data) { } } -void run_on_event(traccc::component_connection& cc, +void run_on_event(traccc::component_connection_algorithm& cc, traccc::cell_collection_types::host& data) { - traccc::cluster_container_types::host clusters = cc(data); + traccc::cluster_container_types::host clusters = cc(vecmem::get_data(data)); } int main(int argc, char* argv[]) { @@ -101,7 +101,7 @@ int main(int argc, char* argv[]) { vecmem::host_memory_resource mem; - traccc::component_connection cc(mem); + traccc::component_connection_algorithm cc(mem); auto time_read_start = std::chrono::high_resolution_clock::now(); diff --git a/io/src/mapper.cpp b/io/src/mapper.cpp index 0af34b79b7..9380ec187f 100644 --- a/io/src/mapper.cpp +++ b/io/src/mapper.cpp @@ -19,7 +19,7 @@ #include "traccc/io/utils.hpp" // Project include(s). -#include "traccc/clusterization/component_connection.hpp" +#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation.hpp" namespace traccc { @@ -195,7 +195,7 @@ generate_measurement_cell_map(std::size_t event, measurement_cell_map result; // CCA algorithms - component_connection cc(resource); + component_connection_algorithm cc(resource); measurement_creation mc(resource); // Read the surface transforms @@ -211,7 +211,7 @@ generate_measurement_cell_map(std::size_t event, cell_collection_types::host& cells_per_event = readOut.cells; cell_module_collection_types::host& modules_per_event = readOut.modules; - auto clusters_per_event = cc(cells_per_event); + auto clusters_per_event = cc(vecmem::get_data(cells_per_event)); auto measurements_per_event = mc(clusters_per_event, modules_per_event); assert(measurements_per_event.size() == clusters_per_event.size()); diff --git a/tests/cpu/seq_single_module.cpp b/tests/cpu/seq_single_module.cpp index 61c65e678b..d1aab40e5e 100644 --- a/tests/cpu/seq_single_module.cpp +++ b/tests/cpu/seq_single_module.cpp @@ -1,12 +1,12 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ // Project include(s). -#include "traccc/clusterization/component_connection.hpp" +#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation.hpp" #include "traccc/clusterization/spacepoint_formation.hpp" #include "traccc/edm/cell.hpp" @@ -26,7 +26,7 @@ TEST(algorithms, seq_single_module) { // Memory resource used in the test. vecmem::host_memory_resource resource; - traccc::component_connection cc(resource); + traccc::component_connection_algorithm cc(resource); traccc::measurement_creation mc(resource); /// Following [DOI: 10.1109/DASIP48288.2019.9049184] @@ -44,7 +44,7 @@ TEST(algorithms, seq_single_module) { traccc::cell_module_collection_types::host modules(&resource); modules.push_back(module); - auto clusters = cc(cells); + auto clusters = cc(vecmem::get_data(cells)); EXPECT_EQ(clusters.size(), 4u); auto measurements = mc(clusters, modules); From 5b9f5f4f42c500a60f7e83e556d06d4053cffa88 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Mon, 15 Apr 2024 17:23:49 +0200 Subject: [PATCH 2/4] Re-worked the (host) measurement creation algorithm. Renamed the class, and made sure that it would work with "device types" instead of using templating unnecessarily. --- core/CMakeLists.txt | 9 +-- .../clusterization_algorithm.hpp | 4 +- .../details/measurement_creation.hpp | 60 ++++++++++++++++++ .../measurement_creation.ipp} | 62 ++++++------------- ...hpp => measurement_creation_algorithm.hpp} | 17 ++--- .../clusterization_algorithm.cpp | 5 +- ...cpp => measurement_creation_algorithm.cpp} | 33 ++++++---- .../device/impl/aggregate_cluster.ipp | 8 +-- io/src/mapper.cpp | 10 +-- tests/cpu/seq_single_module.cpp | 7 ++- 10 files changed, 132 insertions(+), 83 deletions(-) create mode 100644 core/include/traccc/clusterization/details/measurement_creation.hpp rename core/include/traccc/clusterization/{detail/measurement_creation_helper.hpp => impl/measurement_creation.ipp} (59%) rename core/include/traccc/clusterization/{measurement_creation.hpp => measurement_creation_algorithm.hpp} (74%) rename core/src/clusterization/{measurement_creation.cpp => measurement_creation_algorithm.cpp} (50%) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a4f2800bd3..a51d709b0b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,6 +1,6 @@ # TRACCC library, part of the ACTS project (R&D line) # -# (c) 2021-2023 CERN for the benefit of the ACTS project +# (c) 2021-2024 CERN for the benefit of the ACTS project # # Mozilla Public License Version 2.0 @@ -40,17 +40,18 @@ traccc_add_library( traccc_core core TYPE SHARED "include/traccc/utils/seed_generator.hpp" "include/traccc/utils/subspace.hpp" # Clusterization algorithmic code. - "include/traccc/clusterization/detail/measurement_creation_helper.hpp" "include/traccc/clusterization/details/sparse_ccl.hpp" "include/traccc/clusterization/impl/sparse_ccl.ipp" "include/traccc/clusterization/component_connection_algorithm.hpp" "src/clusterization/component_connection_algorithm.cpp" + "include/traccc/clusterization/details/measurement_creation.hpp" + "include/traccc/clusterization/impl/measurement_creation.ipp" + "include/traccc/clusterization/measurement_creation_algorithm.hpp" + "src/clusterization/measurement_creation_algorithm.cpp" "include/traccc/clusterization/clusterization_algorithm.hpp" "src/clusterization/clusterization_algorithm.cpp" "include/traccc/clusterization/spacepoint_formation.hpp" "src/clusterization/spacepoint_formation.cpp" - "include/traccc/clusterization/measurement_creation.hpp" - "src/clusterization/measurement_creation.cpp" # Finding algorithmic code "include/traccc/finding/candidate_link.hpp" "include/traccc/finding/finding_algorithm.hpp" diff --git a/core/include/traccc/clusterization/clusterization_algorithm.hpp b/core/include/traccc/clusterization/clusterization_algorithm.hpp index 497d17e79e..cd338acdfb 100644 --- a/core/include/traccc/clusterization/clusterization_algorithm.hpp +++ b/core/include/traccc/clusterization/clusterization_algorithm.hpp @@ -9,7 +9,7 @@ // Library include(s). #include "traccc/clusterization/component_connection_algorithm.hpp" -#include "traccc/clusterization/measurement_creation.hpp" +#include "traccc/clusterization/measurement_creation_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/measurement.hpp" #include "traccc/utils/algorithm.hpp" @@ -57,7 +57,7 @@ class clusterization_algorithm component_connection_algorithm m_cc; /// Per-module measurement creation algorithm - measurement_creation m_mc; + measurement_creation_algorithm m_mc; /// @} diff --git a/core/include/traccc/clusterization/details/measurement_creation.hpp b/core/include/traccc/clusterization/details/measurement_creation.hpp new file mode 100644 index 0000000000..bde209e29f --- /dev/null +++ b/core/include/traccc/clusterization/details/measurement_creation.hpp @@ -0,0 +1,60 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2021-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "traccc/definitions/primitives.hpp" +#include "traccc/definitions/qualifiers.hpp" +#include "traccc/edm/cell.hpp" +#include "traccc/edm/measurement.hpp" + +namespace traccc::details { + +/// Function used for retrieving the cell signal based on the module id +TRACCC_HOST_DEVICE +inline scalar signal_cell_modelling(scalar signal_in, + const cell_module& module); + +/// Function for pixel segmentation +TRACCC_HOST_DEVICE +inline vector2 position_from_cell(const cell& cell, const cell_module& module); + +/// Function used for calculating the properties of the cluster during +/// measurement creation +/// +/// @param[in] cluster The vector of cells describing the identified cluster +/// @param[in] module The cell module +/// @param[out] mean The mean position of the cluster/measurement +/// @param[out] var The variation on the mean position of the +/// cluster/measurement +/// @param[out] totalWeight The total weight of the cluster/measurement +/// +TRACCC_HOST_DEVICE inline void calc_cluster_properties( + const cell_collection_types::const_device& cluster, + const cell_module& module, point2& mean, point2& var, scalar& totalWeight); + +/// Function used for calculating the properties of the cluster during +/// measurement creation +/// +/// @param[out] measurements is the measurement collection where the measurement +/// object will be filled +/// @param[in] measurement_index is the index of the measurement object to fill +/// @param[in] cluster is the input cell vector +/// @param[in] module is the cell module where the cluster belongs to +/// @param[in] module_link is the module index +/// +TRACCC_HOST_DEVICE inline void fill_measurement( + measurement_collection_types::device& measurements, + std::size_t measurement_index, + const cell_collection_types::const_device& cluster, + const cell_module& module, const unsigned int module_link); + +} // namespace traccc::details + +// Include the implementation. +#include "traccc/clusterization/impl/measurement_creation.ipp" diff --git a/core/include/traccc/clusterization/detail/measurement_creation_helper.hpp b/core/include/traccc/clusterization/impl/measurement_creation.ipp similarity index 59% rename from core/include/traccc/clusterization/detail/measurement_creation_helper.hpp rename to core/include/traccc/clusterization/impl/measurement_creation.ipp index 06e83ba064..8608d0ec44 100644 --- a/core/include/traccc/clusterization/detail/measurement_creation_helper.hpp +++ b/core/include/traccc/clusterization/impl/measurement_creation.ipp @@ -1,50 +1,31 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2023 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ #pragma once -// Project include(s). -#include "traccc/definitions/primitives.hpp" -#include "traccc/definitions/qualifiers.hpp" -#include "traccc/edm/cell.hpp" -#include "traccc/edm/cluster.hpp" -#include "traccc/edm/measurement.hpp" +namespace traccc::details { -namespace traccc::detail { - -/// Function used for retrieving the cell signal based on the module id TRACCC_HOST_DEVICE inline scalar signal_cell_modelling(scalar signal_in, const cell_module& /*module*/) { return signal_in; } -/// Function for pixel segmentation TRACCC_HOST_DEVICE inline vector2 position_from_cell(const cell& cell, const cell_module& module) { + // Retrieve the specific values based on module idx return {module.pixel.min_center_x + cell.channel0 * module.pixel.pitch_x, module.pixel.min_center_y + cell.channel1 * module.pixel.pitch_y}; } -/// Function used for calculating the properties of the cluster during -/// measurement creation -/// -/// @param[in] cluster The vector of cells describing the identified cluster -/// @param[in] module The cell module -/// @param[out] mean The mean position of the cluster/measurement -/// @param[out] var The variation on the mean position of the -/// cluster/measurement -/// @param[out] totalWeight The total weight of the cluster/measurement -/// -template -TRACCC_HOST inline void calc_cluster_properties( - const cell_collection_t& cluster, const cell_module& module, point2& mean, - point2& var, scalar& totalWeight) { +TRACCC_HOST_DEVICE inline void calc_cluster_properties( + const cell_collection_types::const_device& cluster, + const cell_module& module, point2& mean, point2& var, scalar& totalWeight) { // Loop over the cells of the cluster. for (const cell& cell : cluster) { @@ -70,19 +51,11 @@ TRACCC_HOST inline void calc_cluster_properties( } } -/// Function used for calculating the properties of the cluster during -/// measurement creation -/// -/// @param[out] measurements is the measurement collection where the measurement -/// object will be filled -/// @param[in] cluster is the input cell vector -/// @param[in] module is the cell module where the cluster belongs to -/// @param[in] module_link is the module index -/// -TRACCC_HOST inline void fill_measurement( - measurement_collection_types::host& measurements, - const cell_collection_types::host& cluster, const cell_module& module, - const unsigned int module_link) { +TRACCC_HOST_DEVICE inline void fill_measurement( + measurement_collection_types::device& measurements, + std::size_t measurement_index, + const cell_collection_types::const_device& cluster, + const cell_module& module, const unsigned int module_link) { // To calculate the mean and variance with high numerical stability // we use a weighted variant of Welford's algorithm. This is a @@ -97,10 +70,13 @@ TRACCC_HOST inline void fill_measurement( // Calculate the cluster properties scalar totalWeight = 0.; point2 mean{0., 0.}, var{0., 0.}; - detail::calc_cluster_properties(cluster, module, mean, var, totalWeight); + calc_cluster_properties(cluster, module, mean, var, totalWeight); if (totalWeight > 0.) { - measurement m; + + // Access the measurement in question. + measurement& m = measurements[measurement_index]; + m.module_link = module_link; m.surface_link = module.surface_link; // normalize the cell position @@ -116,10 +92,8 @@ TRACCC_HOST inline void fill_measurement( // @todo add variance estimation // For the ambiguity resolution algorithm, give a unique measurement ID - m.measurement_id = measurements.size(); - - measurements.push_back(std::move(m)); + m.measurement_id = measurement_index; } } -} // namespace traccc::detail +} // namespace traccc::details diff --git a/core/include/traccc/clusterization/measurement_creation.hpp b/core/include/traccc/clusterization/measurement_creation_algorithm.hpp similarity index 74% rename from core/include/traccc/clusterization/measurement_creation.hpp rename to core/include/traccc/clusterization/measurement_creation_algorithm.hpp index f7bdecab9b..632626864a 100644 --- a/core/include/traccc/clusterization/measurement_creation.hpp +++ b/core/include/traccc/clusterization/measurement_creation_algorithm.hpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -27,17 +27,17 @@ namespace traccc { /// for all of the clusters that were identified in that one detector /// module. /// -class measurement_creation +class measurement_creation_algorithm : public algorithm { + const cluster_container_types::const_view &, + const cell_module_collection_types::const_view &)> { public: /// Measurement_creation algorithm constructor /// /// @param mr The memory resource to use in the algorithm /// - measurement_creation(vecmem::memory_resource &mr); + measurement_creation_algorithm(vecmem::memory_resource &mr); /// Callable operator for the connected component, based on one single /// module @@ -51,13 +51,14 @@ class measurement_creation /// @return a measurement collection - usually same size or sometime /// slightly smaller than the input output_type operator()( - const cluster_container_types::host &clusters, - const cell_module_collection_types::host &modules) const override; + const cluster_container_types::const_view &clusters_view, + const cell_module_collection_types::const_view &modules_view) + const override; private: /// The memory resource used by the algorithm std::reference_wrapper m_mr; -}; // class measurement_creation +}; // class measurement_creation_algorithm } // namespace traccc diff --git a/core/src/clusterization/clusterization_algorithm.cpp b/core/src/clusterization/clusterization_algorithm.cpp index 10af3b6bea..fd05d59bfc 100644 --- a/core/src/clusterization/clusterization_algorithm.cpp +++ b/core/src/clusterization/clusterization_algorithm.cpp @@ -17,7 +17,10 @@ clusterization_algorithm::output_type clusterization_algorithm::operator()( const cell_collection_types::host& cells, const cell_module_collection_types::host& modules) const { - return m_mc(m_cc(vecmem::get_data(cells)), modules); + const component_connection_algorithm::output_type clusters = + m_cc(vecmem::get_data(cells)); + const auto clusters_data = get_data(clusters); + return m_mc(clusters_data, vecmem::get_data(modules)); } } // namespace traccc diff --git a/core/src/clusterization/measurement_creation.cpp b/core/src/clusterization/measurement_creation_algorithm.cpp similarity index 50% rename from core/src/clusterization/measurement_creation.cpp rename to core/src/clusterization/measurement_creation_algorithm.cpp index 4102d1e5a0..169f2a6225 100644 --- a/core/src/clusterization/measurement_creation.cpp +++ b/core/src/clusterization/measurement_creation_algorithm.cpp @@ -1,28 +1,34 @@ /** 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 */ // Library include(s). -#include "traccc/clusterization/measurement_creation.hpp" +#include "traccc/clusterization/measurement_creation_algorithm.hpp" -#include "traccc/clusterization/detail/measurement_creation_helper.hpp" +#include "traccc/clusterization/details/measurement_creation.hpp" #include "traccc/definitions/primitives.hpp" namespace traccc { -measurement_creation::measurement_creation(vecmem::memory_resource &mr) +measurement_creation_algorithm::measurement_creation_algorithm( + vecmem::memory_resource &mr) : m_mr(mr) {} -measurement_creation::output_type measurement_creation::operator()( - const cluster_container_types::host &clusters, - const cell_module_collection_types::host &modules) const { +measurement_creation_algorithm::output_type +measurement_creation_algorithm::operator()( + const cluster_container_types::const_view &clusters_view, + const cell_module_collection_types::const_view &modules_view) const { + + // Create device containers for the input variables. + const cluster_container_types::const_device clusters{clusters_view}; + const cell_module_collection_types::const_device modules{modules_view}; // Create the result object. - output_type result(&(m_mr.get())); - result.reserve(clusters.size()); + output_type result(clusters.size(), &(m_mr.get())); + measurement_collection_types::device measurements{vecmem::get_data(result)}; // Process the clusters one-by-one. for (std::size_t i = 0; i < clusters.size(); ++i) { @@ -37,18 +43,19 @@ measurement_creation::output_type measurement_creation::operator()( // edition, chapter 4.2.2. // Get the cluster. - cluster_container_types::host::item_vector::const_reference cluster = - clusters.at(i).items; + cluster_container_types::device::item_vector::const_reference cluster = + clusters.get_items()[i]; // A security check. assert(cluster.empty() == false); // Get the cell module - const auto module_link = cluster.at(0).module_link; + const unsigned int module_link = cluster.at(0).module_link; const auto &module = modules.at(module_link); // Fill measurement from cluster - detail::fill_measurement(result, cluster, module, module_link); + details::fill_measurement(measurements, i, cluster, module, + module_link); } return result; diff --git a/device/common/include/traccc/clusterization/device/impl/aggregate_cluster.ipp b/device/common/include/traccc/clusterization/device/impl/aggregate_cluster.ipp index 0663e43768..10469b3757 100644 --- a/device/common/include/traccc/clusterization/device/impl/aggregate_cluster.ipp +++ b/device/common/include/traccc/clusterization/device/impl/aggregate_cluster.ipp @@ -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 */ @@ -8,7 +8,7 @@ #pragma once // Project include(s) -#include "traccc/clusterization/detail/measurement_creation_helper.hpp" +#include "traccc/clusterization/details/measurement_creation.hpp" namespace traccc::device { @@ -64,13 +64,13 @@ inline void aggregate_cluster( maxChannel1 = this_cell.channel1; } - const float weight = traccc::detail::signal_cell_modelling( + const float weight = details::signal_cell_modelling( this_cell.activation, this_module); if (weight > this_module.threshold) { totalWeight += this_cell.activation; const point2 cell_position = - traccc::detail::position_from_cell(this_cell, this_module); + details::position_from_cell(this_cell, this_module); const point2 prev = mean; const point2 diff = cell_position - prev; diff --git a/io/src/mapper.cpp b/io/src/mapper.cpp index 9380ec187f..6f341399c9 100644 --- a/io/src/mapper.cpp +++ b/io/src/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 */ @@ -20,7 +20,7 @@ // Project include(s). #include "traccc/clusterization/component_connection_algorithm.hpp" -#include "traccc/clusterization/measurement_creation.hpp" +#include "traccc/clusterization/measurement_creation_algorithm.hpp" namespace traccc { @@ -196,7 +196,7 @@ generate_measurement_cell_map(std::size_t event, // CCA algorithms component_connection_algorithm cc(resource); - measurement_creation mc(resource); + measurement_creation_algorithm mc(resource); // Read the surface transforms auto [surface_transforms, _] = io::read_geometry(detector_file); @@ -212,7 +212,9 @@ generate_measurement_cell_map(std::size_t event, cell_module_collection_types::host& modules_per_event = readOut.modules; auto clusters_per_event = cc(vecmem::get_data(cells_per_event)); - auto measurements_per_event = mc(clusters_per_event, modules_per_event); + auto clusters_data = traccc::get_data(clusters_per_event); + auto measurements_per_event = + mc(clusters_data, vecmem::get_data(modules_per_event)); assert(measurements_per_event.size() == clusters_per_event.size()); for (unsigned int i = 0; i < measurements_per_event.size(); ++i) { diff --git a/tests/cpu/seq_single_module.cpp b/tests/cpu/seq_single_module.cpp index d1aab40e5e..95df6ce456 100644 --- a/tests/cpu/seq_single_module.cpp +++ b/tests/cpu/seq_single_module.cpp @@ -7,7 +7,7 @@ // Project include(s). #include "traccc/clusterization/component_connection_algorithm.hpp" -#include "traccc/clusterization/measurement_creation.hpp" +#include "traccc/clusterization/measurement_creation_algorithm.hpp" #include "traccc/clusterization/spacepoint_formation.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/cluster.hpp" @@ -27,7 +27,7 @@ TEST(algorithms, seq_single_module) { vecmem::host_memory_resource resource; traccc::component_connection_algorithm cc(resource); - traccc::measurement_creation mc(resource); + traccc::measurement_creation_algorithm mc(resource); /// Following [DOI: 10.1109/DASIP48288.2019.9049184] traccc::cell_collection_types::host cells = {{{1, 0, 1., 0., 0}, @@ -47,7 +47,8 @@ TEST(algorithms, seq_single_module) { auto clusters = cc(vecmem::get_data(cells)); EXPECT_EQ(clusters.size(), 4u); - auto measurements = mc(clusters, modules); + auto clusters_data = traccc::get_data(clusters); + auto measurements = mc(clusters_data, vecmem::get_data(modules)); EXPECT_EQ(measurements.size(), 4u); } From c2c9b6c37715f25c700ec1ff4dd1c682df44214f Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Tue, 16 Apr 2024 10:07:13 +0200 Subject: [PATCH 3/4] Re-worked the (host) spacepoint formation algorithm. Renamed the class, and made sure that it would work with "device types". While extracting its core calculation into a helper function that the device code could reuse. --- core/CMakeLists.txt | 6 ++- .../details/spacepoint_formation.hpp | 31 +++++++++++++ .../impl/spacepoint_formation.ipp | 27 ++++++++++++ ...hpp => spacepoint_formation_algorithm.hpp} | 23 +++++----- .../clusterization/spacepoint_formation.cpp | 43 ------------------ .../spacepoint_formation_algorithm.cpp | 44 +++++++++++++++++++ examples/run/cpu/full_chain_algorithm.cpp | 8 ++-- examples/run/cpu/full_chain_algorithm.hpp | 6 +-- examples/run/cpu/seq_example.cpp | 7 +-- examples/run/cuda/seq_example_cuda.cpp | 10 +++-- examples/run/openmp/io_dec_par_example.cpp | 12 ++--- examples/run/openmp/par_example.cpp | 10 +++-- examples/run/sycl/seq_example_sycl.sycl | 10 +++-- tests/cpu/seq_single_module.cpp | 2 - tests/cpu/test_clusterization_resolution.cpp | 7 +-- 15 files changed, 160 insertions(+), 86 deletions(-) create mode 100644 core/include/traccc/clusterization/details/spacepoint_formation.hpp create mode 100644 core/include/traccc/clusterization/impl/spacepoint_formation.ipp rename core/include/traccc/clusterization/{spacepoint_formation.hpp => spacepoint_formation_algorithm.hpp} (60%) delete mode 100644 core/src/clusterization/spacepoint_formation.cpp create mode 100644 core/src/clusterization/spacepoint_formation_algorithm.cpp diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index a51d709b0b..afd6f4ffea 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -50,8 +50,10 @@ traccc_add_library( traccc_core core TYPE SHARED "src/clusterization/measurement_creation_algorithm.cpp" "include/traccc/clusterization/clusterization_algorithm.hpp" "src/clusterization/clusterization_algorithm.cpp" - "include/traccc/clusterization/spacepoint_formation.hpp" - "src/clusterization/spacepoint_formation.cpp" + "include/traccc/clusterization/details/spacepoint_formation.hpp" + "include/traccc/clusterization/impl/spacepoint_formation.ipp" + "include/traccc/clusterization/spacepoint_formation_algorithm.hpp" + "src/clusterization/spacepoint_formation_algorithm.cpp" # Finding algorithmic code "include/traccc/finding/candidate_link.hpp" "include/traccc/finding/finding_algorithm.hpp" diff --git a/core/include/traccc/clusterization/details/spacepoint_formation.hpp b/core/include/traccc/clusterization/details/spacepoint_formation.hpp new file mode 100644 index 0000000000..922b1dd70f --- /dev/null +++ b/core/include/traccc/clusterization/details/spacepoint_formation.hpp @@ -0,0 +1,31 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "traccc/definitions/qualifiers.hpp" +#include "traccc/edm/cell.hpp" +#include "traccc/edm/measurement.hpp" +#include "traccc/edm/spacepoint.hpp" + +namespace traccc::details { + +/// Function helping with filling/setting up a spacepoint object +/// +/// @param sp The spacepoint to fill / set up +/// @param measurement The measurement to create the spacepoint out of +/// @param module The module that the measurement belongs to +/// +TRACCC_HOST_DEVICE inline void fill_spacepoint(spacepoint& sp, + const measurement& meas, + const cell_module& module); + +} // namespace traccc::details + +// Include the implementation. +#include "traccc/clusterization/impl/spacepoint_formation.ipp" diff --git a/core/include/traccc/clusterization/impl/spacepoint_formation.ipp b/core/include/traccc/clusterization/impl/spacepoint_formation.ipp new file mode 100644 index 0000000000..483dbbb6f2 --- /dev/null +++ b/core/include/traccc/clusterization/impl/spacepoint_formation.ipp @@ -0,0 +1,27 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Project include(s). +#include "traccc/definitions/primitives.hpp" + +namespace traccc::details { + +TRACCC_HOST_DEVICE inline void fill_spacepoint(spacepoint& sp, + const measurement& meas, + const cell_module& module) { + + // Transform measurement position to 3D + point3 local_3d = {meas.local[0], meas.local[1], 0.f}; + point3 global = module.placement.point_to_global(local_3d); + + // Fill spacepoint with this spacepoint + sp = {global, meas}; +} + +} // namespace traccc::details diff --git a/core/include/traccc/clusterization/spacepoint_formation.hpp b/core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp similarity index 60% rename from core/include/traccc/clusterization/spacepoint_formation.hpp rename to core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp index 48598a9c2f..912e214911 100644 --- a/core/include/traccc/clusterization/spacepoint_formation.hpp +++ b/core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -25,31 +25,34 @@ namespace traccc { /// This algorithm performs the local-to-global transformation of the 2D /// measurements made on every detector module, into 3D spacepoint coordinates. /// -class spacepoint_formation : public algorithm { +class spacepoint_formation_algorithm + : public algorithm { public: /// Constructor for spacepoint_formation /// /// @param mr is the memory resource /// - spacepoint_formation(vecmem::memory_resource& mr); + spacepoint_formation_algorithm(vecmem::memory_resource& mr); /// Callable operator for the space point formation, based on one single /// module /// - /// @param measurements A collection of measurements - /// @param modules A collection of modules the measurements link to + /// @param measurements_view A collection of measurements + /// @param modules_view A collection of modules the measurements link to /// @return A spacepoint container, with one spacepoint for every /// measurement /// output_type operator()( - const measurement_collection_types::host& measurements, - const cell_module_collection_types::host& modules) const override; + const measurement_collection_types::const_view& measurements_view, + const cell_module_collection_types::const_view& modules_view) + const override; private: std::reference_wrapper m_mr; -}; + +}; // class spacepoint_formation_algorithm } // namespace traccc diff --git a/core/src/clusterization/spacepoint_formation.cpp b/core/src/clusterization/spacepoint_formation.cpp deleted file mode 100644 index af27603542..0000000000 --- a/core/src/clusterization/spacepoint_formation.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/** 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 - */ - -// Library include(s). -#include "traccc/clusterization/spacepoint_formation.hpp" - -namespace traccc { - -spacepoint_formation::spacepoint_formation(vecmem::memory_resource& mr) - : m_mr(mr) {} - -spacepoint_formation::output_type spacepoint_formation::operator()( - const measurement_collection_types::host& measurements, - const cell_module_collection_types::host& modules) const { - - // Create the result container. - output_type result(&(m_mr.get())); - - // Iterate over the measurements. - for (std::size_t i = 0; i < measurements.size(); ++i) { - - // Access the measurements of the current module. - const measurement& this_measurement = measurements.at(i); - const cell_module& module = modules.at(this_measurement.module_link); - - // Transform measurement position to 3D - point3 local_3d = {this_measurement.local[0], this_measurement.local[1], - 0.}; - point3 global = module.placement.point_to_global(local_3d); - - // Fill result with this spacepoint - result.push_back({global, this_measurement}); - } - - // Return the created container. - return result; -} - -} // namespace traccc diff --git a/core/src/clusterization/spacepoint_formation_algorithm.cpp b/core/src/clusterization/spacepoint_formation_algorithm.cpp new file mode 100644 index 0000000000..c3da820f9e --- /dev/null +++ b/core/src/clusterization/spacepoint_formation_algorithm.cpp @@ -0,0 +1,44 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +// Library include(s). +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" + +#include "traccc/clusterization/details/spacepoint_formation.hpp" + +namespace traccc { + +spacepoint_formation_algorithm::spacepoint_formation_algorithm( + vecmem::memory_resource& mr) + : m_mr(mr) {} + +spacepoint_formation_algorithm::output_type +spacepoint_formation_algorithm::operator()( + const measurement_collection_types::const_view& measurements_view, + const cell_module_collection_types::const_view& modules_view) const { + + // Create device containers for the inputs. + const measurement_collection_types::const_device measurements{ + measurements_view}; + const cell_module_collection_types::const_device modules{modules_view}; + + // Create the result container. + output_type result(measurements.size(), &(m_mr.get())); + + // Set up each spacepoint in the result container. + for (measurement_collection_types::const_device::size_type i = 0; + i < measurements.size(); ++i) { + + const measurement& meas = measurements.at(i); + details::fill_spacepoint(result[i], meas, modules.at(meas.module_link)); + } + + // Return the created container. + return result; +} + +} // namespace traccc diff --git a/examples/run/cpu/full_chain_algorithm.cpp b/examples/run/cpu/full_chain_algorithm.cpp index 5632bbe247..2306f3aaef 100644 --- a/examples/run/cpu/full_chain_algorithm.cpp +++ b/examples/run/cpu/full_chain_algorithm.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 */ @@ -27,8 +27,10 @@ full_chain_algorithm::output_type full_chain_algorithm::operator()( const cell_collection_types::host& cells, const cell_module_collection_types::host& modules) const { - const spacepoint_formation::output_type spacepoints = - m_spacepoint_formation(m_clusterization(cells, modules), modules); + const spacepoint_formation_algorithm::output_type spacepoints = + m_spacepoint_formation( + vecmem::get_data(m_clusterization(cells, modules)), + vecmem::get_data(modules)); return m_track_parameter_estimation(spacepoints, m_seeding(spacepoints), {0.f, 0.f, m_finder_config.bFieldInZ}); } diff --git a/examples/run/cpu/full_chain_algorithm.hpp b/examples/run/cpu/full_chain_algorithm.hpp index eadd740217..57dede402b 100644 --- a/examples/run/cpu/full_chain_algorithm.hpp +++ b/examples/run/cpu/full_chain_algorithm.hpp @@ -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 */ @@ -9,7 +9,7 @@ // Project include(s). #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/seeding/seeding_algorithm.hpp" #include "traccc/seeding/track_params_estimation.hpp" @@ -59,7 +59,7 @@ class full_chain_algorithm /// Clusterization algorithm clusterization_algorithm m_clusterization; /// Spacepoint formation algorithm - spacepoint_formation m_spacepoint_formation; + spacepoint_formation_algorithm m_spacepoint_formation; /// Seeding algorithm seeding_algorithm m_seeding; /// Track parameter estimation algorithm diff --git a/examples/run/cpu/seq_example.cpp b/examples/run/cpu/seq_example.cpp index c8090c5599..1256816f12 100644 --- a/examples/run/cpu/seq_example.cpp +++ b/examples/run/cpu/seq_example.cpp @@ -14,7 +14,7 @@ // algorithms #include "traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp" #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/finding/finding_algorithm.hpp" #include "traccc/fitting/fitting_algorithm.hpp" #include "traccc/seeding/seeding_algorithm.hpp" @@ -140,7 +140,7 @@ int seq_run(const traccc::opts::input_data& input_opts, // Algorithms traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation sf(host_mr); + traccc::spacepoint_formation_algorithm sf(host_mr); traccc::seeding_algorithm sa(seeding_opts.seedfinder, {seeding_opts.seedfinder}, seeding_opts.seedfilter, host_mr); @@ -186,7 +186,8 @@ int seq_run(const traccc::opts::input_data& input_opts, ------------------------*/ auto spacepoints_per_event = - sf(measurements_per_event, modules_per_event); + sf(vecmem::get_data(measurements_per_event), + vecmem::get_data(modules_per_event)); /*----------------------- Seeding algorithm diff --git a/examples/run/cuda/seq_example_cuda.cpp b/examples/run/cuda/seq_example_cuda.cpp index 87e39ce15e..b204ad21e0 100644 --- a/examples/run/cuda/seq_example_cuda.cpp +++ b/examples/run/cuda/seq_example_cuda.cpp @@ -7,7 +7,7 @@ // Project include(s). #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/cuda/clusterization/clusterization_algorithm.hpp" #include "traccc/cuda/seeding/seeding_algorithm.hpp" #include "traccc/cuda/seeding/track_params_estimation.hpp" @@ -80,7 +80,7 @@ int seq_run(const traccc::opts::detector& detector_opts, traccc::memory_resource mr{device_mr, &cuda_host_mr}; traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation sf(host_mr); + traccc::spacepoint_formation_algorithm sf(host_mr); traccc::seeding_algorithm sa(seeding_opts.seedfinder, {seeding_opts.seedfinder}, seeding_opts.seedfilter, host_mr); @@ -110,7 +110,8 @@ int seq_run(const traccc::opts::detector& detector_opts, // Instantiate host containers/collections traccc::io::cell_reader_output read_out_per_event(mr.host); traccc::clusterization_algorithm::output_type measurements_per_event; - traccc::spacepoint_formation::output_type spacepoints_per_event; + traccc::spacepoint_formation_algorithm::output_type + spacepoints_per_event; traccc::seeding_algorithm::output_type seeds; traccc::track_params_estimation::output_type params; @@ -180,7 +181,8 @@ int seq_run(const traccc::opts::detector& detector_opts, traccc::performance::timer t("Spacepoint formation (cpu)", elapsedTimes); spacepoints_per_event = - sf(measurements_per_event, modules_per_event); + sf(vecmem::get_data(measurements_per_event), + vecmem::get_data(modules_per_event)); } // stop measuring spacepoint formation cpu timer } diff --git a/examples/run/openmp/io_dec_par_example.cpp b/examples/run/openmp/io_dec_par_example.cpp index 83cd577860..50df6147f3 100644 --- a/examples/run/openmp/io_dec_par_example.cpp +++ b/examples/run/openmp/io_dec_par_example.cpp @@ -1,13 +1,13 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ // Project include(s). #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/measurement.hpp" #include "traccc/edm/spacepoint.hpp" @@ -35,7 +35,7 @@ traccc::demonstrator_result run(traccc::demonstrator_input input_data, // Algorithms traccc::clusterization_algorithm ca(resource); - traccc::spacepoint_formation sf(resource); + traccc::spacepoint_formation_algorithm sf(resource); // Output stats uint64_t n_modules = 0; @@ -48,7 +48,8 @@ traccc::demonstrator_result run(traccc::demonstrator_input input_data, traccc::demonstrator_result aggregated_results(input_data.size(), &resource); -#pragma omp parallel for reduction (+:n_modules, n_cells, n_measurements, n_spacepoints) +#pragma omp parallel for reduction(+ : n_modules, n_cells, n_measurements, \ + n_spacepoints) for (size_t event = 0; event < input_data.size(); ++event) { traccc::cell_collection_types::host& cells_per_event = input_data.operator[](event).cells; @@ -67,7 +68,8 @@ traccc::demonstrator_result run(traccc::demonstrator_input input_data, ------------------------*/ auto spacepoints_per_event = - sf(measurements_per_event, modules_per_event); + sf(vecmem::get_data(measurements_per_event), + vecmem::get_data(modules_per_event)); /*---------------------------- Statistics diff --git a/examples/run/openmp/par_example.cpp b/examples/run/openmp/par_example.cpp index faf1d3e292..e3def13d7d 100644 --- a/examples/run/openmp/par_example.cpp +++ b/examples/run/openmp/par_example.cpp @@ -7,7 +7,7 @@ // Project include(s). #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/cluster.hpp" #include "traccc/edm/measurement.hpp" @@ -53,7 +53,7 @@ int par_run(const std::string &detector_file, // Algorithms traccc::clusterization_algorithm ca(resource); - traccc::spacepoint_formation sf(resource); + traccc::spacepoint_formation_algorithm sf(resource); // Output stats uint64_t n_modules = 0; @@ -61,7 +61,8 @@ int par_run(const std::string &detector_file, uint64_t n_measurements = 0; uint64_t n_spacepoints = 0; -#pragma omp parallel for reduction (+:n_modules, n_cells, n_measurements, n_spacepoints) +#pragma omp parallel for reduction(+ : n_modules, n_cells, n_measurements, \ + n_spacepoints) // Loop over events for (unsigned int event = 0; event < events; ++event) { @@ -85,7 +86,8 @@ int par_run(const std::string &detector_file, ------------------------*/ auto spacepoints_per_event = - sf(measurements_per_event, modules_per_event); + sf(vecmem::get_data(measurements_per_event), + vecmem::get_data(modules_per_event)); /*---------------------------- Statistics diff --git a/examples/run/sycl/seq_example_sycl.sycl b/examples/run/sycl/seq_example_sycl.sycl index e9efae3d17..c10085a636 100644 --- a/examples/run/sycl/seq_example_sycl.sycl +++ b/examples/run/sycl/seq_example_sycl.sycl @@ -16,7 +16,7 @@ // algorithms #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/seeding/seeding_algorithm.hpp" #include "traccc/seeding/track_params_estimation.hpp" #include "traccc/sycl/clusterization/clusterization_algorithm.hpp" @@ -109,7 +109,7 @@ int seq_run(const traccc::opts::detector& detector_opts, traccc::memory_resource mr{device_mr, &sycl_host_mr}; traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation sf(host_mr); + traccc::spacepoint_formation_algorithm sf(host_mr); traccc::seeding_algorithm sa(seeding_opts.seedfinder, {seeding_opts.seedfinder}, seeding_opts.seedfilter, host_mr); @@ -137,7 +137,8 @@ int seq_run(const traccc::opts::detector& detector_opts, // Instantiate host containers/collections traccc::io::cell_reader_output read_out_per_event(mr.host); traccc::clusterization_algorithm::output_type measurements_per_event; - traccc::spacepoint_formation::output_type spacepoints_per_event; + traccc::spacepoint_formation_algorithm::output_type + spacepoints_per_event; traccc::seeding_algorithm::output_type seeds; traccc::track_params_estimation::output_type params; @@ -208,7 +209,8 @@ int seq_run(const traccc::opts::detector& detector_opts, traccc::performance::timer t("Spacepoint formation (cpu)", elapsedTimes); spacepoints_per_event = - sf(measurements_per_event, modules_per_event); + sf(vecmem::get_data(measurements_per_event), + vecmem::get_data(modules_per_event)); } } diff --git a/tests/cpu/seq_single_module.cpp b/tests/cpu/seq_single_module.cpp index 95df6ce456..ac272b35c1 100644 --- a/tests/cpu/seq_single_module.cpp +++ b/tests/cpu/seq_single_module.cpp @@ -8,11 +8,9 @@ // Project include(s). #include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/cluster.hpp" #include "traccc/edm/measurement.hpp" -#include "traccc/edm/spacepoint.hpp" #include "traccc/geometry/pixel_data.hpp" // VecMem include(s). diff --git a/tests/cpu/test_clusterization_resolution.cpp b/tests/cpu/test_clusterization_resolution.cpp index 95e821337b..bf7b29ec23 100644 --- a/tests/cpu/test_clusterization_resolution.cpp +++ b/tests/cpu/test_clusterization_resolution.cpp @@ -7,7 +7,7 @@ // Project include(s). #include "traccc/clusterization/clusterization_algorithm.hpp" -#include "traccc/clusterization/spacepoint_formation.hpp" +#include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/io/read_cells.hpp" #include "traccc/io/read_digitization_config.hpp" #include "traccc/io/read_geometry.hpp" @@ -42,7 +42,7 @@ TEST_P(SurfaceBinningTests, Run) { // Algorithms traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation sf(host_mr); + traccc::spacepoint_formation_algorithm sf(host_mr); // Read the cells from the relevant event file traccc::io::cell_reader_output readOut(&host_mr); @@ -54,7 +54,8 @@ TEST_P(SurfaceBinningTests, Run) { // Get Reconstructed Spacepoints auto measurements_recon = ca(cells_truth, modules); - auto spacepoints_recon = sf(measurements_recon, modules); + auto spacepoints_recon = + sf(vecmem::get_data(measurements_recon), vecmem::get_data(modules)); // Read the hits from the relevant event file traccc::io::spacepoint_reader_output sp_readOut(&host_mr); From 4c43e1a5c9c2558412aa7592fef7e0b5783e95ae Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Tue, 16 Apr 2024 10:39:42 +0200 Subject: [PATCH 4/4] Re-worked the (host) clusterization algorithm. Moved all of the clusterization (adjacent) algorithms into the traccc::host namespace, and renamed traccc::component_connection_algorithm to traccc::host::sparse_ccl_algorithm. --- core/CMakeLists.txt | 8 +-- .../clusterization_algorithm.hpp | 24 +++---- .../component_connection_algorithm.hpp | 66 ------------------- .../measurement_creation_algorithm.hpp | 4 +- .../spacepoint_formation_algorithm.hpp | 4 +- .../clusterization/sparse_ccl_algorithm.hpp | 58 ++++++++++++++++ .../clusterization_algorithm.cpp | 15 ++--- .../measurement_creation_algorithm.cpp | 4 +- .../spacepoint_formation_algorithm.cpp | 4 +- ...algorithm.cpp => sparse_ccl_algorithm.cpp} | 12 ++-- examples/run/cpu/ccl_example.cpp | 6 +- examples/run/cpu/full_chain_algorithm.cpp | 5 +- examples/run/cpu/full_chain_algorithm.hpp | 4 +- examples/run/cpu/seq_example.cpp | 7 +- examples/run/cuda/seq_example_cuda.cpp | 12 ++-- examples/run/openmp/io_dec_par_example.cpp | 7 +- examples/run/openmp/par_example.cpp | 7 +- examples/run/sycl/seq_example_sycl.sycl | 12 ++-- io/src/mapper.cpp | 6 +- tests/cpu/seq_single_module.cpp | 6 +- tests/cpu/test_cca.cpp | 6 +- tests/cpu/test_clusterization_resolution.cpp | 7 +- 22 files changed, 141 insertions(+), 143 deletions(-) delete mode 100644 core/include/traccc/clusterization/component_connection_algorithm.hpp create mode 100644 core/include/traccc/clusterization/sparse_ccl_algorithm.hpp rename core/src/clusterization/{component_connection_algorithm.cpp => sparse_ccl_algorithm.cpp} (79%) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index afd6f4ffea..7dfc6bae1b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -42,18 +42,18 @@ traccc_add_library( traccc_core core TYPE SHARED # Clusterization algorithmic code. "include/traccc/clusterization/details/sparse_ccl.hpp" "include/traccc/clusterization/impl/sparse_ccl.ipp" - "include/traccc/clusterization/component_connection_algorithm.hpp" - "src/clusterization/component_connection_algorithm.cpp" + "include/traccc/clusterization/sparse_ccl_algorithm.hpp" + "src/clusterization/sparse_ccl_algorithm.cpp" "include/traccc/clusterization/details/measurement_creation.hpp" "include/traccc/clusterization/impl/measurement_creation.ipp" "include/traccc/clusterization/measurement_creation_algorithm.hpp" "src/clusterization/measurement_creation_algorithm.cpp" - "include/traccc/clusterization/clusterization_algorithm.hpp" - "src/clusterization/clusterization_algorithm.cpp" "include/traccc/clusterization/details/spacepoint_formation.hpp" "include/traccc/clusterization/impl/spacepoint_formation.ipp" "include/traccc/clusterization/spacepoint_formation_algorithm.hpp" "src/clusterization/spacepoint_formation_algorithm.cpp" + "include/traccc/clusterization/clusterization_algorithm.hpp" + "src/clusterization/clusterization_algorithm.cpp" # Finding algorithmic code "include/traccc/finding/candidate_link.hpp" "include/traccc/finding/finding_algorithm.hpp" diff --git a/core/include/traccc/clusterization/clusterization_algorithm.hpp b/core/include/traccc/clusterization/clusterization_algorithm.hpp index cd338acdfb..a1a0199244 100644 --- a/core/include/traccc/clusterization/clusterization_algorithm.hpp +++ b/core/include/traccc/clusterization/clusterization_algorithm.hpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -8,8 +8,8 @@ #pragma once // Library include(s). -#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation_algorithm.hpp" +#include "traccc/clusterization/sparse_ccl_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/measurement.hpp" #include "traccc/utils/algorithm.hpp" @@ -20,7 +20,7 @@ // System include(s). #include -namespace traccc { +namespace traccc::host { /// Clusterization algorithm, creating measurements from cells /// @@ -29,8 +29,8 @@ namespace traccc { /// class clusterization_algorithm : public algorithm { + const cell_collection_types::const_view&, + const cell_module_collection_types::const_view&)> { public: /// Clusterization algorithm constructor @@ -41,20 +41,20 @@ class clusterization_algorithm /// Construct measurements for each detector module /// - /// @param cells The cells for every detector module in the event - /// @param modules A collection of detector modules + /// @param cells_view The cells for every detector module in the event + /// @param modules_view A collection of detector modules /// @return The measurements reconstructed for every detector module /// - output_type operator()( - const cell_collection_types::host& cells, - const cell_module_collection_types::host& modules) const override; + output_type operator()(const cell_collection_types::const_view& cells_view, + const cell_module_collection_types::const_view& + modules_view) const override; private: /// @name Sub-algorithms used by this algorithm /// @{ /// Per-module cluster creation algorithm - component_connection_algorithm m_cc; + sparse_ccl_algorithm m_cc; /// Per-module measurement creation algorithm measurement_creation_algorithm m_mc; @@ -66,4 +66,4 @@ class clusterization_algorithm }; // class clusterization_algorithm -} // namespace traccc +} // namespace traccc::host diff --git a/core/include/traccc/clusterization/component_connection_algorithm.hpp b/core/include/traccc/clusterization/component_connection_algorithm.hpp deleted file mode 100644 index 0cf0ac8f07..0000000000 --- a/core/include/traccc/clusterization/component_connection_algorithm.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/** TRACCC library, part of the ACTS project (R&D line) - * - * (c) 2021-2024 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// Library include(s). -#include "traccc/edm/cell.hpp" -#include "traccc/edm/cluster.hpp" -#include "traccc/utils/algorithm.hpp" - -// VecMem include(s). -#include - -// System include(s). -#include - -namespace traccc { - -/// Connected component labelling -/// -/// Note that the separation between the public and private interface is -/// only there in the class because the compilers can't automatically figure -/// out the "vector type" of the templated implementation, without adding a -/// lot of "internal knowledge" about the vector types into this piece of -/// code. So instead the public operators are specifically implemented for -/// the host- and device versions of the EDM, making use of a single -/// implementation internally. -/// -class component_connection_algorithm - : public algorithm { - - public: - /// Constructor for component_connection - /// - /// @param mr is the memory resource - /// - component_connection_algorithm(vecmem::memory_resource& mr); - - /// @name Operator(s) to use in host code - /// @{ - - /// Callable operator for the connected component, based on one single - /// module - /// - /// @param cells_view Collection of input cells sorted by module - /// - /// c++20 piping interface: - /// @return a cluster collection - /// - output_type operator()( - const cell_collection_types::const_view& cells_view) const override; - - /// @} - - private: - /// The memory resource used by the algorithm - std::reference_wrapper m_mr; - -}; // class component_connection_algorithm - -} // namespace traccc diff --git a/core/include/traccc/clusterization/measurement_creation_algorithm.hpp b/core/include/traccc/clusterization/measurement_creation_algorithm.hpp index 632626864a..960e0c8cf9 100644 --- a/core/include/traccc/clusterization/measurement_creation_algorithm.hpp +++ b/core/include/traccc/clusterization/measurement_creation_algorithm.hpp @@ -19,7 +19,7 @@ // System include(s). #include -namespace traccc { +namespace traccc::host { /// Measurement creation out of clusters /// @@ -61,4 +61,4 @@ class measurement_creation_algorithm }; // class measurement_creation_algorithm -} // namespace traccc +} // namespace traccc::host diff --git a/core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp b/core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp index 912e214911..7dfce0d077 100644 --- a/core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp +++ b/core/include/traccc/clusterization/spacepoint_formation_algorithm.hpp @@ -18,7 +18,7 @@ // System include(s). #include -namespace traccc { +namespace traccc::host { /// Algorithm forming space points out of measurements /// @@ -55,4 +55,4 @@ class spacepoint_formation_algorithm }; // class spacepoint_formation_algorithm -} // namespace traccc +} // namespace traccc::host diff --git a/core/include/traccc/clusterization/sparse_ccl_algorithm.hpp b/core/include/traccc/clusterization/sparse_ccl_algorithm.hpp new file mode 100644 index 0000000000..bde252c22c --- /dev/null +++ b/core/include/traccc/clusterization/sparse_ccl_algorithm.hpp @@ -0,0 +1,58 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2021-2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// Library include(s). +#include "traccc/edm/cell.hpp" +#include "traccc/edm/cluster.hpp" +#include "traccc/utils/algorithm.hpp" + +// VecMem include(s). +#include + +// System include(s). +#include + +namespace traccc::host { + +/// Pixel cell clusterization based on a SparseCCL algorithm +/// +/// The implementation is based on the paper: +/// https://doi.org/10.1109/DASIP48288.2019.9049184 +/// +class sparse_ccl_algorithm : public algorithm { + + public: + /// Constructor for component_connection + /// + /// @param mr is the memory resource + /// + sparse_ccl_algorithm(vecmem::memory_resource& mr); + + /// @name Operator(s) to use in host code + /// @{ + + /// Callable operator for the connected component labelling + /// + /// @param cells_view Collection of input cells sorted by module + /// + /// @return a cluster container + /// + output_type operator()( + const cell_collection_types::const_view& cells_view) const override; + + /// @} + + private: + /// The memory resource used by the algorithm + std::reference_wrapper m_mr; + +}; // class sparse_ccl_algorithm + +} // namespace traccc::host diff --git a/core/src/clusterization/clusterization_algorithm.cpp b/core/src/clusterization/clusterization_algorithm.cpp index fd05d59bfc..6404914f8a 100644 --- a/core/src/clusterization/clusterization_algorithm.cpp +++ b/core/src/clusterization/clusterization_algorithm.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 */ @@ -8,19 +8,18 @@ // Library include(s). #include "traccc/clusterization/clusterization_algorithm.hpp" -namespace traccc { +namespace traccc::host { clusterization_algorithm::clusterization_algorithm(vecmem::memory_resource& mr) : m_cc(mr), m_mc(mr), m_mr(mr) {} clusterization_algorithm::output_type clusterization_algorithm::operator()( - const cell_collection_types::host& cells, - const cell_module_collection_types::host& modules) const { + const cell_collection_types::const_view& cells_view, + const cell_module_collection_types::const_view& modules_view) const { - const component_connection_algorithm::output_type clusters = - m_cc(vecmem::get_data(cells)); + const sparse_ccl_algorithm::output_type clusters = m_cc(cells_view); const auto clusters_data = get_data(clusters); - return m_mc(clusters_data, vecmem::get_data(modules)); + return m_mc(clusters_data, modules_view); } -} // namespace traccc +} // namespace traccc::host diff --git a/core/src/clusterization/measurement_creation_algorithm.cpp b/core/src/clusterization/measurement_creation_algorithm.cpp index 169f2a6225..ffe1208366 100644 --- a/core/src/clusterization/measurement_creation_algorithm.cpp +++ b/core/src/clusterization/measurement_creation_algorithm.cpp @@ -11,7 +11,7 @@ #include "traccc/clusterization/details/measurement_creation.hpp" #include "traccc/definitions/primitives.hpp" -namespace traccc { +namespace traccc::host { measurement_creation_algorithm::measurement_creation_algorithm( vecmem::memory_resource &mr) @@ -61,4 +61,4 @@ measurement_creation_algorithm::operator()( return result; } -} // namespace traccc +} // namespace traccc::host diff --git a/core/src/clusterization/spacepoint_formation_algorithm.cpp b/core/src/clusterization/spacepoint_formation_algorithm.cpp index c3da820f9e..12a6a8a8a2 100644 --- a/core/src/clusterization/spacepoint_formation_algorithm.cpp +++ b/core/src/clusterization/spacepoint_formation_algorithm.cpp @@ -10,7 +10,7 @@ #include "traccc/clusterization/details/spacepoint_formation.hpp" -namespace traccc { +namespace traccc::host { spacepoint_formation_algorithm::spacepoint_formation_algorithm( vecmem::memory_resource& mr) @@ -41,4 +41,4 @@ spacepoint_formation_algorithm::operator()( return result; } -} // namespace traccc +} // namespace traccc::host diff --git a/core/src/clusterization/component_connection_algorithm.cpp b/core/src/clusterization/sparse_ccl_algorithm.cpp similarity index 79% rename from core/src/clusterization/component_connection_algorithm.cpp rename to core/src/clusterization/sparse_ccl_algorithm.cpp index 1159aeb16f..b9c38de36a 100644 --- a/core/src/clusterization/component_connection_algorithm.cpp +++ b/core/src/clusterization/sparse_ccl_algorithm.cpp @@ -6,7 +6,7 @@ */ // Library include(s). -#include "traccc/clusterization/component_connection_algorithm.hpp" +#include "traccc/clusterization/sparse_ccl_algorithm.hpp" #include "traccc/clusterization/details/sparse_ccl.hpp" @@ -14,14 +14,12 @@ #include #include -namespace traccc { +namespace traccc::host { -component_connection_algorithm::component_connection_algorithm( - vecmem::memory_resource& mr) +sparse_ccl_algorithm::sparse_ccl_algorithm(vecmem::memory_resource& mr) : m_mr(mr) {} -component_connection_algorithm::output_type -component_connection_algorithm::operator()( +sparse_ccl_algorithm::output_type sparse_ccl_algorithm::operator()( const cell_collection_types::const_view& cells_view) const { // Run SparseCCL to fill CCL indices. @@ -44,4 +42,4 @@ component_connection_algorithm::operator()( return clusters; } -} // namespace traccc +} // namespace traccc::host diff --git a/examples/run/cpu/ccl_example.cpp b/examples/run/cpu/ccl_example.cpp index f24e6dab54..db6dbac9c7 100644 --- a/examples/run/cpu/ccl_example.cpp +++ b/examples/run/cpu/ccl_example.cpp @@ -7,7 +7,7 @@ */ // Project include(s). -#include "traccc/clusterization/component_connection_algorithm.hpp" +#include "traccc/clusterization/sparse_ccl_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/io/read_cells.hpp" @@ -83,7 +83,7 @@ void print_statistics(const traccc::cell_collection_types::host& data) { } } -void run_on_event(traccc::component_connection_algorithm& cc, +void run_on_event(traccc::host::sparse_ccl_algorithm& cc, traccc::cell_collection_types::host& data) { traccc::cluster_container_types::host clusters = cc(vecmem::get_data(data)); } @@ -101,7 +101,7 @@ int main(int argc, char* argv[]) { vecmem::host_memory_resource mem; - traccc::component_connection_algorithm cc(mem); + traccc::host::sparse_ccl_algorithm cc(mem); auto time_read_start = std::chrono::high_resolution_clock::now(); diff --git a/examples/run/cpu/full_chain_algorithm.cpp b/examples/run/cpu/full_chain_algorithm.cpp index 2306f3aaef..6e7c923a75 100644 --- a/examples/run/cpu/full_chain_algorithm.cpp +++ b/examples/run/cpu/full_chain_algorithm.cpp @@ -27,9 +27,10 @@ full_chain_algorithm::output_type full_chain_algorithm::operator()( const cell_collection_types::host& cells, const cell_module_collection_types::host& modules) const { - const spacepoint_formation_algorithm::output_type spacepoints = + const host::spacepoint_formation_algorithm::output_type spacepoints = m_spacepoint_formation( - vecmem::get_data(m_clusterization(cells, modules)), + vecmem::get_data(m_clusterization(vecmem::get_data(cells), + vecmem::get_data(modules))), vecmem::get_data(modules)); return m_track_parameter_estimation(spacepoints, m_seeding(spacepoints), {0.f, 0.f, m_finder_config.bFieldInZ}); diff --git a/examples/run/cpu/full_chain_algorithm.hpp b/examples/run/cpu/full_chain_algorithm.hpp index 57dede402b..8a7cf353f1 100644 --- a/examples/run/cpu/full_chain_algorithm.hpp +++ b/examples/run/cpu/full_chain_algorithm.hpp @@ -57,9 +57,9 @@ class full_chain_algorithm /// @{ /// Clusterization algorithm - clusterization_algorithm m_clusterization; + host::clusterization_algorithm m_clusterization; /// Spacepoint formation algorithm - spacepoint_formation_algorithm m_spacepoint_formation; + host::spacepoint_formation_algorithm m_spacepoint_formation; /// Seeding algorithm seeding_algorithm m_seeding; /// Track parameter estimation algorithm diff --git a/examples/run/cpu/seq_example.cpp b/examples/run/cpu/seq_example.cpp index 1256816f12..32dc03177b 100644 --- a/examples/run/cpu/seq_example.cpp +++ b/examples/run/cpu/seq_example.cpp @@ -139,8 +139,8 @@ int seq_run(const traccc::opts::input_data& input_opts, propagation_opts.setup(fitting_cfg.propagation); // Algorithms - traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation_algorithm sf(host_mr); + traccc::host::clusterization_algorithm ca(host_mr); + traccc::host::spacepoint_formation_algorithm sf(host_mr); traccc::seeding_algorithm sa(seeding_opts.seedfinder, {seeding_opts.seedfinder}, seeding_opts.seedfilter, host_mr); @@ -179,7 +179,8 @@ int seq_run(const traccc::opts::input_data& input_opts, Clusterization -------------------*/ - auto measurements_per_event = ca(cells_per_event, modules_per_event); + auto measurements_per_event = ca(vecmem::get_data(cells_per_event), + vecmem::get_data(modules_per_event)); /*------------------------ Spacepoint formation diff --git a/examples/run/cuda/seq_example_cuda.cpp b/examples/run/cuda/seq_example_cuda.cpp index b204ad21e0..ef40500790 100644 --- a/examples/run/cuda/seq_example_cuda.cpp +++ b/examples/run/cuda/seq_example_cuda.cpp @@ -79,8 +79,8 @@ int seq_run(const traccc::opts::detector& detector_opts, vecmem::cuda::device_memory_resource device_mr; traccc::memory_resource mr{device_mr, &cuda_host_mr}; - traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation_algorithm sf(host_mr); + traccc::host::clusterization_algorithm ca(host_mr); + traccc::host::spacepoint_formation_algorithm sf(host_mr); traccc::seeding_algorithm sa(seeding_opts.seedfinder, {seeding_opts.seedfinder}, seeding_opts.seedfilter, host_mr); @@ -109,8 +109,9 @@ int seq_run(const traccc::opts::detector& detector_opts, // Instantiate host containers/collections traccc::io::cell_reader_output read_out_per_event(mr.host); - traccc::clusterization_algorithm::output_type measurements_per_event; - traccc::spacepoint_formation_algorithm::output_type + traccc::host::clusterization_algorithm::output_type + measurements_per_event; + traccc::host::spacepoint_formation_algorithm::output_type spacepoints_per_event; traccc::seeding_algorithm::output_type seeds; traccc::track_params_estimation::output_type params; @@ -170,7 +171,8 @@ int seq_run(const traccc::opts::detector& detector_opts, traccc::performance::timer t("Clusterization (cpu)", elapsedTimes); measurements_per_event = - ca(cells_per_event, modules_per_event); + ca(vecmem::get_data(cells_per_event), + vecmem::get_data(modules_per_event)); } // stop measuring clusterization cpu timer /*--------------------------------- diff --git a/examples/run/openmp/io_dec_par_example.cpp b/examples/run/openmp/io_dec_par_example.cpp index 50df6147f3..ec9d2a8b91 100644 --- a/examples/run/openmp/io_dec_par_example.cpp +++ b/examples/run/openmp/io_dec_par_example.cpp @@ -34,8 +34,8 @@ traccc::demonstrator_result run(traccc::demonstrator_input input_data, vecmem::host_memory_resource resource) { // Algorithms - traccc::clusterization_algorithm ca(resource); - traccc::spacepoint_formation_algorithm sf(resource); + traccc::host::clusterization_algorithm ca(resource); + traccc::host::spacepoint_formation_algorithm sf(resource); // Output stats uint64_t n_modules = 0; @@ -61,7 +61,8 @@ traccc::demonstrator_result run(traccc::demonstrator_input input_data, Clusterization -------------------*/ - auto measurements_per_event = ca(cells_per_event, modules_per_event); + auto measurements_per_event = ca(vecmem::get_data(cells_per_event), + vecmem::get_data(modules_per_event)); /*------------------------ Spacepoint formation diff --git a/examples/run/openmp/par_example.cpp b/examples/run/openmp/par_example.cpp index e3def13d7d..a50a0d7f68 100644 --- a/examples/run/openmp/par_example.cpp +++ b/examples/run/openmp/par_example.cpp @@ -52,8 +52,8 @@ int par_run(const std::string &detector_file, vecmem::host_memory_resource resource; // Algorithms - traccc::clusterization_algorithm ca(resource); - traccc::spacepoint_formation_algorithm sf(resource); + traccc::host::clusterization_algorithm ca(resource); + traccc::host::spacepoint_formation_algorithm sf(resource); // Output stats uint64_t n_modules = 0; @@ -79,7 +79,8 @@ int par_run(const std::string &detector_file, Clusterization -------------------*/ - auto measurements_per_event = ca(cells_per_event, modules_per_event); + auto measurements_per_event = ca(vecmem::get_data(cells_per_event), + vecmem::get_data(modules_per_event)); /*------------------------ Spacepoint formation diff --git a/examples/run/sycl/seq_example_sycl.sycl b/examples/run/sycl/seq_example_sycl.sycl index c10085a636..d3652db49c 100644 --- a/examples/run/sycl/seq_example_sycl.sycl +++ b/examples/run/sycl/seq_example_sycl.sycl @@ -108,8 +108,8 @@ int seq_run(const traccc::opts::detector& detector_opts, vecmem::sycl::device_memory_resource device_mr{&q}; traccc::memory_resource mr{device_mr, &sycl_host_mr}; - traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation_algorithm sf(host_mr); + traccc::host::clusterization_algorithm ca(host_mr); + traccc::host::spacepoint_formation_algorithm sf(host_mr); traccc::seeding_algorithm sa(seeding_opts.seedfinder, {seeding_opts.seedfinder}, seeding_opts.seedfilter, host_mr); @@ -136,8 +136,9 @@ int seq_run(const traccc::opts::detector& detector_opts, // Instantiate host containers/collections traccc::io::cell_reader_output read_out_per_event(mr.host); - traccc::clusterization_algorithm::output_type measurements_per_event; - traccc::spacepoint_formation_algorithm::output_type + traccc::host::clusterization_algorithm::output_type + measurements_per_event; + traccc::host::spacepoint_formation_algorithm::output_type spacepoints_per_event; traccc::seeding_algorithm::output_type seeds; traccc::track_params_estimation::output_type params; @@ -198,7 +199,8 @@ int seq_run(const traccc::opts::detector& detector_opts, traccc::performance::timer t("Clusterization (cpu)", elapsedTimes); measurements_per_event = - ca(cells_per_event, modules_per_event); + ca(vecmem::get_data(cells_per_event), + vecmem::get_data(modules_per_event)); } /*--------------------------------- diff --git a/io/src/mapper.cpp b/io/src/mapper.cpp index 6f341399c9..6fbf8aded9 100644 --- a/io/src/mapper.cpp +++ b/io/src/mapper.cpp @@ -19,8 +19,8 @@ #include "traccc/io/utils.hpp" // Project include(s). -#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation_algorithm.hpp" +#include "traccc/clusterization/sparse_ccl_algorithm.hpp" namespace traccc { @@ -195,8 +195,8 @@ generate_measurement_cell_map(std::size_t event, measurement_cell_map result; // CCA algorithms - component_connection_algorithm cc(resource); - measurement_creation_algorithm mc(resource); + host::sparse_ccl_algorithm cc(resource); + host::measurement_creation_algorithm mc(resource); // Read the surface transforms auto [surface_transforms, _] = io::read_geometry(detector_file); diff --git a/tests/cpu/seq_single_module.cpp b/tests/cpu/seq_single_module.cpp index ac272b35c1..9ee208f24e 100644 --- a/tests/cpu/seq_single_module.cpp +++ b/tests/cpu/seq_single_module.cpp @@ -6,8 +6,8 @@ */ // Project include(s). -#include "traccc/clusterization/component_connection_algorithm.hpp" #include "traccc/clusterization/measurement_creation_algorithm.hpp" +#include "traccc/clusterization/sparse_ccl_algorithm.hpp" #include "traccc/edm/cell.hpp" #include "traccc/edm/cluster.hpp" #include "traccc/edm/measurement.hpp" @@ -24,8 +24,8 @@ TEST(algorithms, seq_single_module) { // Memory resource used in the test. vecmem::host_memory_resource resource; - traccc::component_connection_algorithm cc(resource); - traccc::measurement_creation_algorithm mc(resource); + traccc::host::sparse_ccl_algorithm cc(resource); + traccc::host::measurement_creation_algorithm mc(resource); /// Following [DOI: 10.1109/DASIP48288.2019.9049184] traccc::cell_collection_types::host cells = {{{1, 0, 1., 0., 0}, diff --git a/tests/cpu/test_cca.cpp b/tests/cpu/test_cca.cpp index 430d52f8af..12bc4b1bb3 100644 --- a/tests/cpu/test_cca.cpp +++ b/tests/cpu/test_cca.cpp @@ -1,6 +1,6 @@ /** TRACCC library, part of the ACTS project (R&D line) * - * (c) 2021-2022 CERN for the benefit of the ACTS project + * (c) 2021-2024 CERN for the benefit of the ACTS project * * Mozilla Public License Version 2.0 */ @@ -25,14 +25,14 @@ namespace { vecmem::host_memory_resource resource; -traccc::clusterization_algorithm ca(resource); +traccc::host::clusterization_algorithm ca(resource); cca_function_t f = [](const traccc::cell_collection_types::host& cells, const traccc::cell_module_collection_types::host& modules) { std::map> result; - auto measurements = ca(cells, modules); + auto measurements = ca(vecmem::get_data(cells), vecmem::get_data(modules)); for (std::size_t i = 0; i < measurements.size(); i++) { result[modules.at(measurements.at(i).module_link).surface_link.value()] .push_back(measurements.at(i)); diff --git a/tests/cpu/test_clusterization_resolution.cpp b/tests/cpu/test_clusterization_resolution.cpp index bf7b29ec23..5313ee079d 100644 --- a/tests/cpu/test_clusterization_resolution.cpp +++ b/tests/cpu/test_clusterization_resolution.cpp @@ -41,8 +41,8 @@ TEST_P(SurfaceBinningTests, Run) { vecmem::host_memory_resource host_mr; // Algorithms - traccc::clusterization_algorithm ca(host_mr); - traccc::spacepoint_formation_algorithm sf(host_mr); + traccc::host::clusterization_algorithm ca(host_mr); + traccc::host::spacepoint_formation_algorithm sf(host_mr); // Read the cells from the relevant event file traccc::io::cell_reader_output readOut(&host_mr); @@ -53,7 +53,8 @@ TEST_P(SurfaceBinningTests, Run) { const traccc::cell_module_collection_types::host& modules = readOut.modules; // Get Reconstructed Spacepoints - auto measurements_recon = ca(cells_truth, modules); + auto measurements_recon = + ca(vecmem::get_data(cells_truth), vecmem::get_data(modules)); auto spacepoints_recon = sf(vecmem::get_data(measurements_recon), vecmem::get_data(modules));