Skip to content

Commit bdfa3f5

Browse files
authored
Thread ID Cleanup, main branch (2025.01.09.) (acts-project#810)
* Harmonized the different thread_id classes with each other. Made all of them into "private headers", and added automated tests that they would fulfill the appropriate concept. * Synchronized how thread IDs would be used in the device functions. While also cleaning up the includes of the files a bit. * Call device functions consistently from CUDA. * Call device functions consistently from SYCL. * Implement (some of) Stephen's suggestions.
1 parent adab46d commit bdfa3f5

File tree

72 files changed

+518
-407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+518
-407
lines changed

device/alpaka/include/traccc/alpaka/utils/thread_id.hpp

Lines changed: 0 additions & 53 deletions
This file was deleted.

device/alpaka/src/clusterization/clusterization_algorithm.cpp

Lines changed: 3 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) 2024 CERN for the benefit of the ACTS project
3+
* (c) 2024-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -9,10 +9,10 @@
99
#include "traccc/alpaka/clusterization/clusterization_algorithm.hpp"
1010

1111
#include "../utils/barrier.hpp"
12+
#include "../utils/thread_id.hpp"
1213
#include "../utils/utils.hpp"
1314

1415
// Project include(s)
15-
#include "traccc/alpaka/utils/thread_id.hpp"
1616
#include "traccc/clusterization/clustering_config.hpp"
1717
#include "traccc/clusterization/device/ccl_kernel.hpp"
1818

@@ -36,7 +36,7 @@ struct CCLKernel {
3636
measurement_collection_types::view measurements_view,
3737
vecmem::data::vector_view<unsigned int> cell_links) const {
3838

39-
traccc::alpaka::thread_id1 thread_id(acc);
39+
details::thread_id1 thread_id(acc);
4040

4141
auto& partition_start =
4242
::alpaka::declareSharedVar<std::size_t, __COUNTER__>(acc);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* traccc library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2024-2025 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#pragma once
10+
11+
// Local include(s).
12+
#include "utils.hpp"
13+
14+
// Project include(s).
15+
#include "traccc/definitions/qualifiers.hpp"
16+
#include "traccc/device/concepts/thread_id.hpp"
17+
18+
// Alpaka include(s).
19+
#include <alpaka/alpaka.hpp>
20+
21+
namespace traccc::alpaka::details {
22+
23+
/// An Alpaka thread identifier type
24+
template <typename Acc>
25+
struct thread_id1 {
26+
TRACCC_HOST_DEVICE explicit thread_id1(const Acc& acc) : m_acc(acc) {}
27+
28+
unsigned int inline TRACCC_HOST_DEVICE getLocalThreadId() const {
29+
return static_cast<unsigned int>(
30+
::alpaka::getIdx<::alpaka::Block, ::alpaka::Threads>(m_acc)[0u]);
31+
}
32+
33+
unsigned int inline TRACCC_HOST_DEVICE getLocalThreadIdX() const {
34+
return getLocalThreadId();
35+
}
36+
37+
unsigned int inline TRACCC_HOST_DEVICE getGlobalThreadId() const {
38+
return getLocalThreadId() + getBlockIdX() * getBlockDimX();
39+
}
40+
41+
unsigned int inline TRACCC_HOST_DEVICE getGlobalThreadIdX() const {
42+
return getLocalThreadId() + getBlockIdX() * getBlockDimX();
43+
}
44+
45+
unsigned int inline TRACCC_HOST_DEVICE getBlockIdX() const {
46+
return static_cast<unsigned int>(
47+
::alpaka::getIdx<::alpaka::Grid, ::alpaka::Blocks>(m_acc)[0u]);
48+
}
49+
50+
unsigned int inline TRACCC_HOST_DEVICE getBlockDimX() const {
51+
return static_cast<unsigned int>(
52+
::alpaka::getWorkDiv<::alpaka::Block, ::alpaka::Threads>(
53+
m_acc)[0u]);
54+
}
55+
56+
unsigned int inline TRACCC_HOST_DEVICE getGridDimX() const {
57+
return static_cast<unsigned int>(
58+
::alpaka::getWorkDiv<::alpaka::Grid, ::alpaka::Blocks>(m_acc)[0u]);
59+
}
60+
61+
private:
62+
const Acc& m_acc;
63+
};
64+
65+
/// Verify that @c traccc::alpaka::details::thread_id1 fulfills the
66+
/// @c traccc::device::concepts::thread_id1 concept.
67+
static_assert(traccc::device::concepts::thread_id1<thread_id1<Acc>>);
68+
69+
} // namespace traccc::alpaka::details

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

Lines changed: 2 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
*/
@@ -254,8 +254,7 @@ TRACCC_DEVICE inline void ccl_kernel(
254254
*/
255255
if (thread_id.getLocalThreadIdX() == 0) {
256256
unsigned int start =
257-
static_cast<unsigned int>(thread_id.getBlockIdX()) *
258-
cfg.target_partition_size();
257+
thread_id.getBlockIdX() * cfg.target_partition_size();
259258
assert(start < num_cells);
260259
unsigned int end =
261260
std::min(num_cells, start + cfg.target_partition_size());

device/common/include/traccc/finding/device/find_tracks.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
#pragma once
99

10+
// Local include(s).
11+
#include "traccc/device/concepts/barrier.hpp"
12+
#include "traccc/device/concepts/thread_id.hpp"
13+
1014
// Project include(s).
1115
#include "traccc/definitions/primitives.hpp"
1216
#include "traccc/definitions/qualifiers.hpp"
13-
#include "traccc/device/concepts/barrier.hpp"
14-
#include "traccc/device/concepts/thread_id.hpp"
1517
#include "traccc/edm/measurement.hpp"
1618
#include "traccc/edm/track_parameters.hpp"
1719
#include "traccc/finding/candidate_link.hpp"
@@ -140,8 +142,8 @@ struct find_tracks_shared_payload {
140142
template <typename detector_t, concepts::thread_id1 thread_id_t,
141143
concepts::barrier barrier_t>
142144
TRACCC_DEVICE inline void find_tracks(
143-
thread_id_t& thread_id, barrier_t& barrier, const finding_config& cfg,
144-
const find_tracks_payload<detector_t>& payload,
145+
const thread_id_t& thread_id, const barrier_t& barrier,
146+
const finding_config& cfg, const find_tracks_payload<detector_t>& payload,
145147
const find_tracks_shared_payload& shared_payload);
146148

147149
} // namespace traccc::device

device/common/include/traccc/finding/device/impl/find_tracks.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace traccc::device {
1919
template <typename detector_t, concepts::thread_id1 thread_id_t,
2020
concepts::barrier barrier_t>
2121
TRACCC_DEVICE inline void find_tracks(
22-
thread_id_t& thread_id, barrier_t& barrier, const finding_config& cfg,
23-
const find_tracks_payload<detector_t>& payload,
22+
const thread_id_t& thread_id, const barrier_t& barrier,
23+
const finding_config& cfg, const find_tracks_payload<detector_t>& payload,
2424
const find_tracks_shared_payload& shared_payload) {
2525

2626
/*

device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#include "traccc/utils/particle.hpp"
1212

1313
// Detray include(s).
14-
#include "detray/utils/tuple.hpp"
14+
#include "detray/propagator/constrained_step.hpp"
15+
#include "detray/utils/tuple_helpers.hpp"
1516

1617
namespace traccc::device {
1718

device/common/include/traccc/finding/device/propagate_to_next_surface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "traccc/definitions/qualifiers.hpp"
1515
#include "traccc/edm/track_parameters.hpp"
1616
#include "traccc/finding/candidate_link.hpp"
17+
#include "traccc/finding/finding_config.hpp"
1718

1819
// VecMem include(s).
1920
#include <vecmem/containers/data/vector_view.hpp>

device/common/include/traccc/fitting/device/fill_sort_keys.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2024 CERN for the benefit of the ACTS project
3+
* (c) 2024-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
77

88
#pragma once
99

10-
// Project include(s).
10+
// Local include(s).
11+
#include "traccc/device/global_index.hpp"
1112
#include "traccc/edm/device/sort_key.hpp"
12-
#include "traccc/edm/track_candidate.hpp"
1313

14-
// System include(s).
15-
#include <cstddef>
14+
// Project include(s).
15+
#include "traccc/edm/track_candidate.hpp"
1616

1717
namespace traccc::device {
1818

@@ -24,7 +24,7 @@ namespace traccc::device {
2424
/// @param[out] ids_view The param ids
2525
///
2626
TRACCC_HOST_DEVICE inline void fill_sort_keys(
27-
std::size_t globalIndex,
27+
global_index_t globalIndex,
2828
const track_candidate_container_types::const_view& track_candidates_view,
2929
vecmem::data::vector_view<device::sort_key> keys_view,
3030
vecmem::data::vector_view<unsigned int> ids_view);

device/common/include/traccc/fitting/device/fit.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022 CERN for the benefit of the ACTS project
3+
* (c) 2022-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
77

88
#pragma once
99

10+
// Local include(s).
11+
#include "traccc/device/global_index.hpp"
12+
1013
// Project include(s).
1114
#include "traccc/definitions/qualifiers.hpp"
1215
#include "traccc/edm/track_candidate.hpp"
1316
#include "traccc/edm/track_state.hpp"
1417

15-
// System include(s).
16-
#include <cstddef>
17-
1818
namespace traccc::device {
1919

2020
/// Function used for fitting a track for a given track candidates
@@ -26,7 +26,7 @@ namespace traccc::device {
2626
///
2727
template <typename fitter_t>
2828
TRACCC_HOST_DEVICE inline void fit(
29-
std::size_t globalIndex,
29+
global_index_t globalIndex,
3030
typename fitter_t::detector_type::view_type det_data,
3131
const typename fitter_t::bfield_type field_data,
3232
const typename fitter_t::config_type cfg,

0 commit comments

Comments
 (0)