Skip to content

Commit 248ced1

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 9b5e684 commit 248ced1

File tree

8 files changed

+72
-51
lines changed

8 files changed

+72
-51
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ struct seedfilter_config {
199199
float deltaRMin = 5.f * unit<float>::mm;
200200
// how often do you want to increase the weight of a seed for finding a
201201
// compatible seed?
202-
size_t compatSeedLimit = 2;
202+
unsigned int compatSeedLimit = 2;
203+
204+
unsigned int compatSeedMin = 2;
205+
// Tool to apply experiment specific cuts on collected middle space points
203206

204207
// seed weight increase
205208
float good_spB_min_radius = 150.f * unit<float>::mm;
@@ -211,7 +214,6 @@ struct seedfilter_config {
211214
float good_spB_min_weight = 380.f;
212215

213216
// seed cut
214-
float seed_min_weight = 200.f;
215217
float spB_min_radius = 43.f * unit<float>::mm;
216218
};
217219

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
@@ -98,11 +98,15 @@ void seed_filtering::operator()(
9898
const traccc::details::spacepoint_grid_types::const_device
9999
sp_grid_accessor(sp_grid_data);
100100
const auto& this_seed = triplets_passing_single_seed_cuts[i].get();
101-
if (seed_selecting_helper::cut_per_middle_sp(
102-
m_filter_config,
103-
spacepoints.at(sp_grid_accessor.bin(
104-
this_seed.sp1.bin_idx)[this_seed.sp1.sp_idx]),
105-
this_seed.weight)) {
101+
102+
const scalar spB_radius =
103+
spacepoints
104+
.at(sp_grid_accessor.bin(
105+
this_seed.sp1.bin_idx)[this_seed.sp1.sp_idx])
106+
.radius();
107+
108+
if (this_seed.weight > 200.f ||
109+
spB_radius > m_filter_config.spB_min_radius) {
106110
triplets_passing_final_cuts.push_back(
107111
triplets_passing_single_seed_cuts[i]);
108112
}

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: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ inline void select_seeds(
6767
const triplet_counter_spM_collection_types::const_view& spM_tc_view,
6868
const triplet_counter_collection_types::const_view& tc_view,
6969
const device_triplet_collection_types::const_view& triplet_view,
70+
const vecmem::data::vector_view<const unsigned int> num_confirmations_view,
7071
device_triplet* data, edm::seed_collection::view seed_view) {
7172

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

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

9093
// Current work item = middle spacepoint
@@ -99,6 +102,14 @@ inline void select_seeds(
99102

100103
const unsigned int end_triplets_spM =
101104
spM_counter.posTriplets + spM_counter.m_nTriplets;
105+
106+
unsigned int max_num_confirmations = 0;
107+
108+
for (unsigned int i = spM_counter.posTriplets; i < end_triplets_spM; ++i) {
109+
max_num_confirmations =
110+
std::max(max_num_confirmations, num_confirmations.at(i));
111+
}
112+
102113
// iterate over the triplets in the bin
103114
for (unsigned int i = spM_counter.posTriplets; i < end_triplets_spM; ++i) {
104115
device_triplet aTriplet = triplets[i];
@@ -111,10 +122,19 @@ inline void select_seeds(
111122
const edm::spacepoint_collection::const_device::const_proxy_type spT =
112123
spacepoints.at(spT_idx);
113124

125+
if (num_confirmations.at(i) + 1 < max_num_confirmations) {
126+
continue;
127+
}
128+
114129
// update weight of triplet
115130
seed_selecting_helper::seed_weight(filter_config, spM, spB, spT,
116131
aTriplet.weight);
117132

133+
aTriplet.weight +=
134+
static_cast<scalar>(std::min(num_confirmations.at(i),
135+
filter_config.compatSeedLimit)) *
136+
filter_config.compatSeedWeight;
137+
118138
// check if it is a good triplet
119139
if (!seed_selecting_helper::single_seed_cut(filter_config, spM, spB,
120140
spT, aTriplet.weight)) {
@@ -165,15 +185,15 @@ inline void select_seeds(
165185
break;
166186
}
167187

168-
// check if it is a good triplet
169-
if (seed_selecting_helper::cut_per_middle_sp(
170-
filter_config, spacepoints.at(aTriplet.spB), aTriplet.weight) ||
171-
n_seeds_per_spM == 0) {
188+
if (spacepoints.at(aTriplet.spB).radius() <=
189+
filter_config.spB_min_radius &&
190+
n_seeds_per_spM > 0) {
191+
continue;
192+
}
172193

173-
n_seeds_per_spM++;
194+
n_seeds_per_spM++;
174195

175-
seeds_device.push_back({aTriplet.spB, aTriplet.spM, aTriplet.spT});
176-
}
196+
seeds_device.push_back({aTriplet.spB, aTriplet.spM, aTriplet.spT});
177197
}
178198
}
179199

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

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

4748
} // namespace traccc::device

device/cuda/src/seeding/seed_finding.cu

Lines changed: 17 additions & 10 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
@@ -145,7 +147,7 @@ __global__ void select_seeds(
145147

146148
device::select_seeds(details::global_index1(), finder_config, filter_config,
147149
spacepoints, sp_view, spM_tc, midBot_tc, triplet_view,
148-
dataPos, seed_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
@@ -362,7 +369,7 @@ edm::seed_collection::buffer seed_finding::operator()(
362369
stream>>>(
363370
m_seedfinder_config, m_seedfilter_config, spacepoints_view, g2_view,
364371
triplet_counter_spM_buffer, triplet_counter_midBot_buffer,
365-
triplet_buffer, seed_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)