Skip to content

Commit 919a082

Browse files
authored
Merge pull request #1023 from krasznaa/DeviceClusterReco-main-20250617
Device Cluster Reconstruction, main branch (2025.06.17.)
1 parent 93a8f60 commit 919a082

File tree

22 files changed

+489
-145
lines changed

22 files changed

+489
-145
lines changed

device/alpaka/src/clusterization/clusterization_algorithm.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct CCLKernel {
3535
vecmem::data::vector_view<unsigned char> adjc_backup_view,
3636
vecmem::data::vector_view<device::details::index_t> adjv_backup_view,
3737
uint32_t* backup_mutex_ptr,
38+
vecmem::data::vector_view<unsigned int> disjoint_set_view,
39+
vecmem::data::vector_view<unsigned int> cluster_size_view,
3840
measurement_collection_types::view measurements_view,
3941
vecmem::data::vector_view<unsigned int> cell_links) const {
4042

@@ -57,11 +59,11 @@ struct CCLKernel {
5759

5860
alpaka::barrier<TAcc> barry_r(&acc);
5961

60-
device::ccl_kernel(cfg, thread_id, cells_view, det_descr_view,
61-
partition_start, partition_end, outi, f_view,
62-
gf_view, f_backup_view, gf_backup_view,
63-
adjc_backup_view, adjv_backup_view, backup_mutex,
64-
barry_r, measurements_view, cell_links);
62+
device::ccl_kernel(
63+
cfg, thread_id, cells_view, det_descr_view, partition_start,
64+
partition_end, outi, f_view, gf_view, f_backup_view, gf_backup_view,
65+
adjc_backup_view, adjv_backup_view, backup_mutex, disjoint_set_view,
66+
cluster_size_view, barry_r, measurements_view, cell_links);
6567
}
6668
};
6769

@@ -136,12 +138,13 @@ clusterization_algorithm::output_type clusterization_algorithm::operator()(
136138
"with support for multi-thread blocks.");
137139
auto workDiv = makeWorkDiv<Acc>(num_blocks, m_config.threads_per_partition);
138140

141+
vecmem::data::vector_view<unsigned int> dummy_view{0u, nullptr};
139142
::alpaka::exec<Acc>(
140143
queue, workDiv, CCLKernel{}, m_config, cells, det_descr,
141144
vecmem::get_data(m_f_backup), vecmem::get_data(m_gf_backup),
142145
vecmem::get_data(m_adjc_backup), vecmem::get_data(m_adjv_backup),
143-
m_backup_mutex.get(), vecmem::get_data(measurements),
144-
vecmem::get_data(cell_links));
146+
m_backup_mutex.get(), dummy_view, dummy_view,
147+
vecmem::get_data(measurements), vecmem::get_data(cell_links));
145148
::alpaka::wait(queue);
146149

147150
return measurements;

device/common/include/traccc/clusterization/device/aggregate_cluster.hpp

Lines changed: 10 additions & 2 deletions
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-2024 CERN for the benefit of the ACTS project
3+
* (c) 2022-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -30,6 +30,12 @@ namespace traccc::device {
3030
/// @param[in] end partition end point this cell belongs to
3131
/// @param[in] cid current cell id
3232
/// @param[out] out cluster to fill
33+
/// @param[out] disjoint_set Array of unsigned integers of
34+
/// length $|cells|$ to which an integer is written
35+
/// identifying the measurement index to which each cell
36+
/// belongs.
37+
/// @param[out] cluster_size Optional integer which is filled with the size of
38+
/// the measurement that is created.
3339
///
3440
TRACCC_HOST_DEVICE
3541
inline void aggregate_cluster(
@@ -38,7 +44,9 @@ inline void aggregate_cluster(
3844
const silicon_detector_description::const_device& det_descr,
3945
const vecmem::device_vector<details::index_t>& f, unsigned int start,
4046
unsigned int end, unsigned short cid, measurement& out,
41-
vecmem::data::vector_view<unsigned int> cell_links, unsigned int link);
47+
vecmem::data::vector_view<unsigned int> cell_links, unsigned int link,
48+
vecmem::device_vector<unsigned int>& disjoint_set,
49+
std::optional<std::reference_wrapper<unsigned int>> cluster_size);
4250

4351
} // namespace traccc::device
4452

device/common/include/traccc/clusterization/device/ccl_kernel.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ namespace traccc::device {
4949
/// matrix fragment storage
5050
/// @param backup_mutex mutex lock to mediate control over the backup global
5151
/// memory data structures.
52+
/// @param[out] disjoint_set_view Array of unsigned integers of
53+
/// length $|cells|$ to which an integer is written identifying the
54+
/// measurement index to which each cell belongs.
55+
/// @param[out] cluster_size_view Array of unsigned integers of
56+
/// size $|cells|$; the first $N$ elements - where $N$ is the number of
57+
/// output measurements - will have their value set to the size of the
58+
/// corresponding measurement.
5259
/// @param barrier A generic object for block-wide synchronisation
5360
/// @param[out] measurements_view collection of measurements
5461
/// @param[out] cell_links collection of links to measurements each cell is
@@ -66,7 +73,10 @@ TRACCC_DEVICE inline void ccl_kernel(
6673
vecmem::data::vector_view<details::index_t> gf_backup_view,
6774
vecmem::data::vector_view<unsigned char> adjc_backup_view,
6875
vecmem::data::vector_view<details::index_t> adjv_backup_view,
69-
vecmem::device_atomic_ref<uint32_t> backup_mutex, const barrier_t& barrier,
76+
vecmem::device_atomic_ref<uint32_t> backup_mutex,
77+
vecmem::data::vector_view<unsigned int> disjoint_set_view,
78+
vecmem::data::vector_view<unsigned int> cluster_size_view,
79+
const barrier_t& barrier,
7080
measurement_collection_types::view measurements_view,
7181
vecmem::data::vector_view<unsigned int> cell_links);
7282

device/common/include/traccc/clusterization/device/impl/aggregate_cluster.ipp

Lines changed: 15 additions & 3 deletions
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-2024 CERN for the benefit of the ACTS project
3+
* (c) 2022-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -19,8 +19,9 @@ inline void aggregate_cluster(
1919
const silicon_detector_description::const_device& det_descr,
2020
const vecmem::device_vector<details::index_t>& f, const unsigned int start,
2121
const unsigned int end, const unsigned short cid, measurement& out,
22-
vecmem::data::vector_view<unsigned int> cell_links,
23-
const unsigned int link) {
22+
vecmem::data::vector_view<unsigned int> cell_links, const unsigned int link,
23+
vecmem::device_vector<unsigned int>& disjoint_set,
24+
std::optional<std::reference_wrapper<unsigned int>> cluster_size) {
2425
vecmem::device_vector<unsigned int> cell_links_device(cell_links);
2526

2627
/*
@@ -63,6 +64,7 @@ inline void aggregate_cluster(
6364
const unsigned int module_idx = cells.module_index().at(cid + start);
6465
const auto module_descr = det_descr.at(module_idx);
6566
const auto partition_size = static_cast<unsigned short>(end - start);
67+
unsigned int tmp_cluster_size = 0;
6668

6769
bool first_processed = false;
6870

@@ -125,6 +127,12 @@ inline void aggregate_cluster(
125127
}
126128

127129
cell_links_device.at(pos) = link;
130+
131+
tmp_cluster_size++;
132+
133+
if (disjoint_set.capacity()) {
134+
disjoint_set.at(pos) = link;
135+
}
128136
}
129137

130138
/*
@@ -134,6 +142,10 @@ inline void aggregate_cluster(
134142
if (cell.channel1() > maxChannel1 + 1) {
135143
break;
136144
}
145+
146+
if (cluster_size.has_value()) {
147+
(*cluster_size).get() = tmp_cluster_size;
148+
}
137149
}
138150

139151
var = var + point2{module_descr.pitch_x() * module_descr.pitch_x() /

device/common/include/traccc/clusterization/device/impl/ccl_kernel.ipp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ TRACCC_DEVICE inline void ccl_core(
145145
const edm::silicon_cell_collection::const_device& cells_device,
146146
const silicon_detector_description::const_device& det_descr,
147147
measurement_collection_types::device measurements_device,
148-
const barrier_t& barrier) {
148+
const barrier_t& barrier, vecmem::device_vector<unsigned int>& disjoint_set,
149+
vecmem::device_vector<unsigned int>& cluster_size) {
149150
const auto size =
150151
static_cast<details::index_t>(partition_end - partition_start);
151152

@@ -197,17 +198,23 @@ TRACCC_DEVICE inline void ccl_core(
197198
for (details::index_t tst = 0; tst < thread_cell_count; ++tst) {
198199
const auto cid = static_cast<details::index_t>(
199200
tst * thread_id.getBlockDimX() + thread_id.getLocalThreadIdX());
201+
200202
if (f.at(cid) == cid) {
201203
// Add a new measurement to the output buffer. Remembering its
202204
// position inside of the container.
203205
const measurement_collection_types::device::size_type meas_pos =
204206
measurements_device.push_back({});
205207
// Set up the measurement under the appropriate index.
206-
aggregate_cluster(cfg, cells_device, det_descr, f,
207-
static_cast<unsigned int>(partition_start),
208-
static_cast<unsigned int>(partition_end), cid,
209-
measurements_device.at(meas_pos), cell_links,
210-
meas_pos);
208+
aggregate_cluster(
209+
cfg, cells_device, det_descr, f,
210+
static_cast<unsigned int>(partition_start),
211+
static_cast<unsigned int>(partition_end), cid,
212+
measurements_device.at(meas_pos), cell_links, meas_pos,
213+
disjoint_set,
214+
(cluster_size.capacity()
215+
? std::optional<std::reference_wrapper<
216+
unsigned int>>{cluster_size.at(meas_pos)}
217+
: std::nullopt));
211218
}
212219
}
213220
}
@@ -225,7 +232,10 @@ TRACCC_DEVICE inline void ccl_kernel(
225232
vecmem::data::vector_view<details::index_t> gf_backup_view,
226233
vecmem::data::vector_view<unsigned char> adjc_backup_view,
227234
vecmem::data::vector_view<details::index_t> adjv_backup_view,
228-
vecmem::device_atomic_ref<uint32_t> backup_mutex, const barrier_t& barrier,
235+
vecmem::device_atomic_ref<uint32_t> backup_mutex,
236+
vecmem::data::vector_view<unsigned int> disjoint_set_view,
237+
vecmem::data::vector_view<unsigned int> cluster_size_view,
238+
const barrier_t& barrier,
229239
measurement_collection_types::view measurements_view,
230240
vecmem::data::vector_view<unsigned int> cell_links) {
231241

@@ -239,6 +249,8 @@ TRACCC_DEVICE inline void ccl_kernel(
239249
vecmem::device_vector<details::index_t> gf_backup(gf_backup_view);
240250
vecmem::device_vector<unsigned char> adjc_backup(adjc_backup_view);
241251
vecmem::device_vector<details::index_t> adjv_backup(adjv_backup_view);
252+
vecmem::device_vector<unsigned int> disjoint_set(disjoint_set_view);
253+
vecmem::device_vector<unsigned int> cluster_size(cluster_size_view);
242254

243255
mutex<uint32_t> mutex(backup_mutex);
244256
unique_lock lock(mutex, std::defer_lock);
@@ -353,7 +365,8 @@ TRACCC_DEVICE inline void ccl_kernel(
353365
ccl_core(cfg, thread_id, partition_start, partition_end,
354366
use_scratch ? f_backup : f_primary,
355367
use_scratch ? gf_backup : gf_primary, cell_links, adjv, adjc,
356-
cells_device, det_descr, measurements_device, barrier);
368+
cells_device, det_descr, measurements_device, barrier,
369+
disjoint_set, cluster_size);
357370

358371
barrier.blockBarrier();
359372
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2025 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
namespace traccc::device {
11+
12+
TRACCC_HOST_DEVICE inline void reify_cluster_data(
13+
global_index_t thread_id,
14+
vecmem::data::vector_view<const unsigned int> disjoint_set_view,
15+
traccc::edm::silicon_cluster_collection::view cluster_view) {
16+
17+
// Create the device objects.
18+
const vecmem::device_vector<const unsigned int> disjoint_set(
19+
disjoint_set_view);
20+
traccc::edm::silicon_cluster_collection::device clusters(cluster_view);
21+
22+
// Fill the output container.
23+
if (thread_id < disjoint_set.size()) {
24+
clusters.cell_indices()
25+
.at(disjoint_set.at(thread_id))
26+
.push_back(thread_id);
27+
}
28+
}
29+
30+
} // namespace traccc::device
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2025 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// Local include(s).
11+
#include "traccc/device/global_index.hpp"
12+
13+
// Project include(s).
14+
#include "traccc/definitions/qualifiers.hpp"
15+
#include "traccc/edm/silicon_cluster_collection.hpp"
16+
17+
// VecMem include(s).
18+
#include <vecmem/containers/data/vector_view.hpp>
19+
20+
namespace traccc::device {
21+
22+
/// Fill a cluster collection with the cell indices
23+
///
24+
/// @param thread_id The thread identifier
25+
/// @param disjoint_set_view The cluster/measurement index of each cell
26+
/// @param cluster_view The collection to fill
27+
///
28+
TRACCC_HOST_DEVICE inline void reify_cluster_data(
29+
global_index_t thread_id,
30+
vecmem::data::vector_view<const unsigned int> disjoint_set_view,
31+
traccc::edm::silicon_cluster_collection::view cluster_view);
32+
33+
} // namespace traccc::device
34+
35+
// Include the implementation.
36+
#include "traccc/clusterization/device/impl/reify_cluster_data.ipp"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
namespace traccc::device {
11+
/**
12+
* @defgroup Clustering algorithm cluster retention parameters
13+
*
14+
* Optional parameters to clustering algorithms which convert directly from
15+
* cells to measurements, determining whether to reconstruct the intermediate
16+
* cluster data or not.
17+
*
18+
* @{
19+
* @brief Explicitly discard cluster information.
20+
*/
21+
struct clustering_discard_disjoint_set {};
22+
/*
23+
* @brief Explicitly reconstruct and return cluster information.
24+
*/
25+
struct clustering_keep_disjoint_set {};
26+
/*
27+
* @}
28+
*/
29+
} // namespace traccc::device

device/cuda/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED
5151
"src/clusterization/measurement_sorting_algorithm.cu"
5252
"src/clusterization/kernels/ccl_kernel.cu"
5353
"src/clusterization/kernels/ccl_kernel.cuh"
54+
"src/clusterization/kernels/reify_cluster_data.cu"
5455
# Finding
5556
"include/traccc/cuda/finding/finding_algorithm.hpp"
5657
"src/finding/finding_algorithm.cu"

device/cuda/include/traccc/cuda/clusterization/clusterization_algorithm.hpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// Project include(s).
1414
#include "traccc/clusterization/clustering_config.hpp"
1515
#include "traccc/clusterization/device/ccl_kernel_definitions.hpp"
16+
#include "traccc/clusterization/device/tags.hpp"
1617
#include "traccc/edm/measurement.hpp"
1718
#include "traccc/edm/silicon_cell_collection.hpp"
19+
#include "traccc/edm/silicon_cluster_collection.hpp"
1820
#include "traccc/geometry/silicon_detector_description.hpp"
1921
#include "traccc/utils/algorithm.hpp"
2022
#include "traccc/utils/memory_resource.hpp"
@@ -26,6 +28,7 @@
2628

2729
// System include(s).
2830
#include <functional>
31+
#include <optional>
2932

3033
namespace traccc::cuda {
3134

@@ -41,6 +44,16 @@ class clusterization_algorithm
4144
: public algorithm<measurement_collection_types::buffer(
4245
const edm::silicon_cell_collection::const_view&,
4346
const silicon_detector_description::const_view&)>,
47+
public algorithm<measurement_collection_types::buffer(
48+
const edm::silicon_cell_collection::const_view&,
49+
const silicon_detector_description::const_view&,
50+
device::clustering_discard_disjoint_set&&)>,
51+
public algorithm<
52+
std::pair<measurement_collection_types::buffer,
53+
traccc::edm::silicon_cluster_collection::buffer>(
54+
const edm::silicon_cell_collection::const_view&,
55+
const silicon_detector_description::const_view&,
56+
device::clustering_keep_disjoint_set&&)>,
4457
public messaging {
4558

4659
public:
@@ -67,12 +80,31 @@ class clusterization_algorithm
6780
/// @param det_descr The detector description
6881
/// @return a measurement collection (buffer)
6982
///
70-
output_type operator()(
83+
/// @{
84+
measurement_collection_types::buffer operator()(
7185
const edm::silicon_cell_collection::const_view& cells,
7286
const silicon_detector_description::const_view& det_descr)
7387
const override;
7488

89+
measurement_collection_types::buffer operator()(
90+
const edm::silicon_cell_collection::const_view& cells,
91+
const silicon_detector_description::const_view& det_descr,
92+
device::clustering_discard_disjoint_set&&) const override;
93+
94+
std::pair<measurement_collection_types::buffer,
95+
traccc::edm::silicon_cluster_collection::buffer>
96+
operator()(const edm::silicon_cell_collection::const_view& cells,
97+
const silicon_detector_description::const_view& det_descr,
98+
device::clustering_keep_disjoint_set&&) const override;
99+
/// @}
100+
75101
private:
102+
std::pair<measurement_collection_types::buffer,
103+
std::optional<traccc::edm::silicon_cluster_collection::buffer>>
104+
execute_impl(const edm::silicon_cell_collection::const_view& cells,
105+
const silicon_detector_description::const_view& det_descr,
106+
bool keep_disjoint_set) const;
107+
76108
/// The memory resource(s) to use
77109
traccc::memory_resource m_mr;
78110
/// The copy object to use

0 commit comments

Comments
 (0)