Skip to content

Commit 0adad8c

Browse files
committed
Rework seed confirmation counting mechanism
Currently, we could seed confirmations and add them to the weight of the seed. We add a large weight, 200, which causes several problems with the seeding code. Most prominently, our weights before the confirmation are in the range [-10, 0] which means that adding 200 brings you in the range [190, 200] and the minimum weight is 200. Thus, you are very coarsely cutting seeds on a very high minimum weight. Expressing the confirmations using an integer counting system makes us more robust against the aforementioned.
1 parent 5cfd02a commit 0adad8c

File tree

8 files changed

+64
-55
lines changed

8 files changed

+64
-55
lines changed

core/include/traccc/seeding/detail/seeding_config.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ struct seedfilter_config {
202202
unsigned int maxSeedsPerSpM = 20;
203203
// how often do you want to increase the weight of a seed for finding a
204204
// compatible seed?
205-
size_t compatSeedLimit = 2;
205+
unsigned int compatSeedLimit = 2;
206+
207+
unsigned int compatSeedMin = 2;
206208
// Tool to apply experiment specific cuts on collected middle space points
207209

208210
size_t max_triplets_per_spM = 5;
@@ -217,7 +219,6 @@ struct seedfilter_config {
217219
float good_spB_min_weight = 380.f;
218220

219221
// seed cut
220-
float seed_min_weight = 200.f;
221222
float spB_min_radius = 43.f * unit<float>::mm;
222223
};
223224

core/include/traccc/seeding/seed_selecting_helper.hpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,6 @@ struct seed_selecting_helper {
6161
return !(spB.radius() > filter_config.good_spB_min_radius &&
6262
triplet_weight < filter_config.good_spB_min_weight);
6363
}
64-
65-
/// Cut triplets with criteria
66-
///
67-
/// @param filter_config seed filtering configuration parameters
68-
/// @param spacepoints spacepoint collection
69-
/// @param sp_grid Spacepoint grid
70-
/// @param seed current seed to possibly cut
71-
///
72-
/// @return boolean value
73-
template <typename spacepoint_type>
74-
static TRACCC_HOST_DEVICE bool cut_per_middle_sp(
75-
const seedfilter_config& filter_config, const spacepoint_type& spB,
76-
const scalar weight) {
77-
78-
return (weight > filter_config.seed_min_weight ||
79-
spB.radius() > filter_config.spB_min_radius);
80-
}
8164
};
8265

8366
} // namespace traccc

core/src/seeding/seed_filtering.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ void seed_filtering::operator()(
9494
const traccc::details::spacepoint_grid_types::const_device
9595
sp_grid_accessor(sp_grid_data);
9696
const auto& this_seed = triplets_passing_single_seed_cuts[i].get();
97-
if (seed_selecting_helper::cut_per_middle_sp(
98-
m_filter_config,
99-
spacepoints.at(sp_grid_accessor.bin(
100-
this_seed.sp1.bin_idx)[this_seed.sp1.sp_idx]),
101-
this_seed.weight)) {
97+
98+
const scalar spB_radius =
99+
spacepoints
100+
.at(sp_grid_accessor.bin(
101+
this_seed.sp1.bin_idx)[this_seed.sp1.sp_idx])
102+
.radius();
103+
104+
if (this_seed.weight > 200.f ||
105+
spB_radius > m_filter_config.spB_min_radius) {
102106
triplets_passing_final_cuts.push_back(
103107
triplets_passing_single_seed_cuts[i]);
104108
}

device/common/include/traccc/seeding/device/update_triplet_weights.hpp renamed to device/common/include/traccc/seeding/device/find_triplet_confirmations.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ namespace traccc::device {
3434
/// @param[inout] triplet_view Collection of triplets
3535
///
3636
TRACCC_HOST_DEVICE
37-
inline void update_triplet_weights(
37+
inline void find_triplet_confirmations(
3838
global_index_t globalIndex, const seedfilter_config& filter_config,
3939
const edm::spacepoint_collection::const_view& spacepoints,
4040
const triplet_counter_spM_collection_types::const_view& spM_tc_view,
4141
const triplet_counter_collection_types::const_view& tc_view, scalar* data,
42-
device_triplet_collection_types::view triplet_view);
42+
const device_triplet_collection_types::const_view triplet_view,
43+
vecmem::data::vector_view<unsigned int> num_confirmations_view);
4344

4445
} // namespace traccc::device
4546

4647
// Include the implementation.
47-
#include "traccc/seeding/device/impl/update_triplet_weights.ipp"
48+
#include "traccc/seeding/device/impl/find_triplet_confirmations.ipp"

device/common/include/traccc/seeding/device/impl/update_triplet_weights.ipp renamed to device/common/include/traccc/seeding/device/impl/find_triplet_confirmations.ipp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@
1616
namespace traccc::device {
1717

1818
TRACCC_HOST_DEVICE
19-
inline void update_triplet_weights(
19+
inline void find_triplet_confirmations(
2020
const global_index_t globalIndex, const seedfilter_config& filter_config,
2121
const edm::spacepoint_collection::const_view& spacepoints_view,
2222
const triplet_counter_spM_collection_types::const_view& spM_tc_view,
2323
const triplet_counter_collection_types::const_view& tc_view, scalar* data,
24-
device_triplet_collection_types::view triplet_view) {
24+
const device_triplet_collection_types::const_view triplet_view,
25+
vecmem::data::vector_view<unsigned int> num_confirmations_view) {
2526

2627
// Check if anything needs to be done.
27-
device_triplet_collection_types::device triplets(triplet_view);
28+
const device_triplet_collection_types::const_device triplets(triplet_view);
2829
if (globalIndex >= triplets.size()) {
2930
return;
3031
}
3132

33+
vecmem::device_vector<unsigned int> num_confirmations(
34+
num_confirmations_view);
35+
3236
// Set up the device containers
3337
const edm::spacepoint_collection::const_device spacepoints{
3438
spacepoints_view};
@@ -38,7 +42,7 @@ inline void update_triplet_weights(
3842
tc_view);
3943

4044
// Current work item
41-
device_triplet this_triplet = triplets.at(globalIndex);
45+
const device_triplet& this_triplet = triplets.at(globalIndex);
4246

4347
const edm::spacepoint_collection::const_device::const_proxy_type
4448
current_spT = spacepoints.at(this_triplet.spT);
@@ -52,7 +56,7 @@ inline void update_triplet_weights(
5256
this_triplet.curvature - filter_config.deltaInvHelixDiameter;
5357
const scalar upperLimitCurv =
5458
this_triplet.curvature + filter_config.deltaInvHelixDiameter;
55-
std::size_t num_compat_seedR = 0;
59+
unsigned int num_compat_seedR = 0;
5660

5761
const triplet_counter mb_count =
5862
triplet_counts.at(static_cast<unsigned int>(this_triplet.counter_link));
@@ -116,7 +120,6 @@ inline void update_triplet_weights(
116120

117121
if (newCompSeed) {
118122
data[num_compat_seedR] = otherTop_r;
119-
this_triplet.weight += filter_config.compatSeedWeight;
120123
num_compat_seedR++;
121124
}
122125

@@ -125,7 +128,7 @@ inline void update_triplet_weights(
125128
}
126129
}
127130

128-
triplets.at(globalIndex).weight = this_triplet.weight;
131+
num_confirmations.at(globalIndex) = num_compat_seedR;
129132
}
130133

131134
} // namespace traccc::device

device/common/include/traccc/seeding/device/impl/select_seeds.ipp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ inline void select_seeds(
6666
const triplet_counter_spM_collection_types::const_view& spM_tc_view,
6767
const triplet_counter_collection_types::const_view& tc_view,
6868
const device_triplet_collection_types::const_view& triplet_view,
69+
const vecmem::data::vector_view<const unsigned int> num_confirmations_view,
6970
device_triplet* data, edm::seed_collection::view seed_view) {
7071

7172
// Check if anything needs to be done.
@@ -84,6 +85,8 @@ inline void select_seeds(
8485
sp_view);
8586

8687
const device_triplet_collection_types::const_device triplets(triplet_view);
88+
const vecmem::device_vector<const unsigned int> num_confirmations(
89+
num_confirmations_view);
8790
edm::seed_collection::device seeds_device(seed_view);
8891

8992
// Current work item = middle spacepoint
@@ -114,6 +117,11 @@ inline void select_seeds(
114117
seed_selecting_helper::seed_weight(filter_config, spM, spB, spT,
115118
aTriplet.weight);
116119

120+
aTriplet.weight +=
121+
static_cast<scalar>(std::min(num_confirmations.at(i),
122+
filter_config.compatSeedLimit)) *
123+
filter_config.compatSeedWeight;
124+
117125
// check if it is a good triplet
118126
if (!seed_selecting_helper::single_seed_cut(filter_config, spM, spB,
119127
spT, aTriplet.weight)) {
@@ -164,15 +172,16 @@ inline void select_seeds(
164172
break;
165173
}
166174

167-
// check if it is a good triplet
168-
if (seed_selecting_helper::cut_per_middle_sp(
169-
filter_config, spacepoints.at(aTriplet.spB), aTriplet.weight) ||
170-
n_seeds_per_spM == 0) {
175+
if (num_confirmations.at(i) < filter_config.compatSeedMin &&
176+
spacepoints.at(aTriplet.spB).radius() <=
177+
filter_config.spB_min_radius &&
178+
n_seeds_per_spM > 0) {
179+
continue;
180+
}
171181

172-
n_seeds_per_spM++;
182+
n_seeds_per_spM++;
173183

174-
seeds_device.push_back({aTriplet.spB, aTriplet.spM, aTriplet.spT});
175-
}
184+
seeds_device.push_back({aTriplet.spB, aTriplet.spM, aTriplet.spT});
176185
}
177186
}
178187

device/common/include/traccc/seeding/device/select_seeds.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ inline void select_seeds(
4141
const triplet_counter_spM_collection_types::const_view& spM_tc_view,
4242
const triplet_counter_collection_types::const_view& tc_view,
4343
const device_triplet_collection_types::const_view& triplet_view,
44+
const vecmem::data::vector_view<const unsigned int> num_confirmations_view,
4445
triplet* data, edm::seed_collection::view seed_view);
4546

4647
} // namespace traccc::device

device/cuda/src/seeding/seed_finding.cu

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include "traccc/seeding/device/count_doublets.hpp"
2424
#include "traccc/seeding/device/count_triplets.hpp"
2525
#include "traccc/seeding/device/find_doublets.hpp"
26+
#include "traccc/seeding/device/find_triplet_confirmations.hpp"
2627
#include "traccc/seeding/device/find_triplets.hpp"
2728
#include "traccc/seeding/device/reduce_triplet_counts.hpp"
2829
#include "traccc/seeding/device/select_seeds.hpp"
29-
#include "traccc/seeding/device/update_triplet_weights.hpp"
3030

3131
// VecMem include(s).
3232
#include <vecmem/utils/cuda/copy.hpp>
@@ -108,22 +108,23 @@ __global__ void find_triplets(
108108
}
109109

110110
/// CUDA kernel for running @c traccc::device::update_triplet_weights
111-
__global__ void update_triplet_weights(
111+
__global__ void find_triplet_confirmations(
112112
seedfilter_config filter_config,
113113
edm::spacepoint_collection::const_view spacepoints,
114114
device::triplet_counter_spM_collection_types::const_view spM_tc,
115115
device::triplet_counter_collection_types::const_view midBot_tc,
116-
device::device_triplet_collection_types::view triplet_view) {
116+
device::device_triplet_collection_types::view triplet_view,
117+
vecmem::data::vector_view<unsigned int> num_confirmations_view) {
117118

118119
// Array for temporary storage of quality parameters for comparing triplets
119120
// within weight updating kernel
120121
extern __shared__ scalar data[];
121122
// Each thread uses compatSeedLimit elements of the array
122123
scalar* dataPos = &data[threadIdx.x * filter_config.compatSeedLimit];
123124

124-
device::update_triplet_weights(details::global_index1(), filter_config,
125-
spacepoints, spM_tc, midBot_tc, dataPos,
126-
triplet_view);
125+
device::find_triplet_confirmations(details::global_index1(), filter_config,
126+
spacepoints, spM_tc, midBot_tc, dataPos,
127+
triplet_view, num_confirmations_view);
127128
}
128129

129130
/// CUDA kernel for running @c traccc::device::select_seeds
@@ -134,6 +135,7 @@ __global__ void select_seeds(
134135
device::triplet_counter_spM_collection_types::const_view spM_tc,
135136
device::triplet_counter_collection_types::const_view midBot_tc,
136137
device::device_triplet_collection_types::view triplet_view,
138+
const vecmem::data::vector_view<const unsigned int> num_confirmations_view,
137139
edm::seed_collection::view seed_view) {
138140

139141
// Array for temporary storage of triplets for comparing within seed
@@ -144,8 +146,8 @@ __global__ void select_seeds(
144146
&data2[threadIdx.x * filter_config.max_triplets_per_spM];
145147

146148
device::select_seeds(details::global_index1(), filter_config, spacepoints,
147-
sp_view, spM_tc, midBot_tc, triplet_view, dataPos,
148-
seed_view);
149+
sp_view, spM_tc, midBot_tc, triplet_view,
150+
num_confirmations_view, dataPos, seed_view);
149151
}
150152

151153
} // namespace kernels
@@ -324,6 +326,11 @@ edm::seed_collection::buffer seed_finding::operator()(
324326
triplet_buffer);
325327
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
326328

329+
vecmem::data::vector_buffer<unsigned int> num_confirmations_buffer(
330+
globalCounter_host->m_nTriplets, m_mr.main);
331+
m_copy.setup(num_confirmations_buffer)->wait();
332+
m_copy.memset(num_confirmations_buffer, 0)->wait();
333+
327334
// Calculate the number of threads and thread blocks to run the weight
328335
// updating kernel for.
329336
const unsigned int nWeightUpdatingThreads = m_warp_size * 2;
@@ -332,13 +339,13 @@ edm::seed_collection::buffer seed_finding::operator()(
332339
nWeightUpdatingThreads;
333340

334341
// Update the weights of all spacepoint triplets.
335-
kernels::update_triplet_weights<<<
342+
kernels::find_triplet_confirmations<<<
336343
nWeightUpdatingBlocks, nWeightUpdatingThreads,
337344
sizeof(scalar) * m_seedfilter_config.compatSeedLimit *
338345
nWeightUpdatingThreads,
339346
stream>>>(m_seedfilter_config, spacepoints_view,
340347
triplet_counter_spM_buffer, triplet_counter_midBot_buffer,
341-
triplet_buffer);
348+
triplet_buffer, num_confirmations_buffer);
342349
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
343350

344351
// Create result object: collection of seeds
@@ -359,10 +366,10 @@ edm::seed_collection::buffer seed_finding::operator()(
359366
sizeof(device::device_triplet) *
360367
m_seedfilter_config.max_triplets_per_spM *
361368
nSeedSelectingThreads,
362-
stream>>>(m_seedfilter_config, spacepoints_view,
363-
g2_view, triplet_counter_spM_buffer,
364-
triplet_counter_midBot_buffer,
365-
triplet_buffer, seed_buffer);
369+
stream>>>(
370+
m_seedfilter_config, spacepoints_view, g2_view,
371+
triplet_counter_spM_buffer, triplet_counter_midBot_buffer,
372+
triplet_buffer, num_confirmations_buffer, seed_buffer);
366373
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
367374

368375
return seed_buffer;

0 commit comments

Comments
 (0)