Skip to content

Commit 48ad5a3

Browse files
authored
Merge pull request #415 from guilhermeAlmeida1/fixCrashOnNoSeeds
Fix: Handle empty inputs gracefully
2 parents 452b53c + ba1ee05 commit 48ad5a3

File tree

9 files changed

+65
-10
lines changed

9 files changed

+65
-10
lines changed

device/cuda/src/clusterization/clusterization_algorithm.cu

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ clusterization_algorithm::output_type clusterization_algorithm::operator()(
9191
const cell_collection_types::view::size_type num_cells =
9292
m_copy.get_size(cells);
9393

94+
if (num_cells == 0) {
95+
return {output_type::first_type{0, m_mr.main},
96+
output_type::second_type{0, m_mr.main}};
97+
}
98+
9499
// Create result object for the CCL kernel with size overestimation
95100
alt_measurement_collection_types::buffer measurements_buffer(num_cells,
96101
m_mr.main);

device/cuda/src/seeding/seed_finding.cu

+16-4
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,21 @@ seed_finding::output_type seed_finding::operator()(
164164
vecmem::data::vector_buffer sp_grid_prefix_sum_buff =
165165
make_prefix_sum_buff(grid_sizes, m_copy, m_mr, m_stream);
166166

167+
const auto num_spacepoints = m_copy.get_size(sp_grid_prefix_sum_buff);
168+
if (num_spacepoints == 0) {
169+
return {0, m_mr.main};
170+
}
171+
167172
// Set up the doublet counter buffer.
168173
device::doublet_counter_collection_types::buffer doublet_counter_buffer = {
169-
m_copy.get_size(sp_grid_prefix_sum_buff), m_mr.main,
170-
vecmem::data::buffer_type::resizable};
174+
num_spacepoints, m_mr.main, vecmem::data::buffer_type::resizable};
171175
m_copy.setup(doublet_counter_buffer);
172176

173177
// Calculate the number of threads and thread blocks to run the doublet
174178
// counting kernel for.
175179
const unsigned int nDoubletCountThreads = WARP_SIZE * 2;
176180
const unsigned int nDoubletCountBlocks =
177-
(m_copy.get_size(sp_grid_prefix_sum_buff) + nDoubletCountThreads - 1) /
178-
nDoubletCountThreads;
181+
(num_spacepoints + nDoubletCountThreads - 1) / nDoubletCountThreads;
179182

180183
// Counter for the total number of doublets and triplets
181184
vecmem::unique_alloc_ptr<device::seeding_global_counter>
@@ -205,6 +208,11 @@ seed_finding::output_type seed_finding::operator()(
205208
cudaMemcpyDeviceToHost, stream));
206209
m_stream.synchronize();
207210

211+
if (globalCounter_host->m_nMidBot == 0 ||
212+
globalCounter_host->m_nMidTop == 0) {
213+
return {0, m_mr.main};
214+
}
215+
208216
// Set up the doublet counter buffers.
209217
device::device_doublet_collection_types::buffer doublet_buffer_mb = {
210218
globalCounter_host->m_nMidBot, m_mr.main};
@@ -275,6 +283,10 @@ seed_finding::output_type seed_finding::operator()(
275283
cudaMemcpyDeviceToHost, stream));
276284
m_stream.synchronize();
277285

286+
if (globalCounter_host->m_nTriplets == 0) {
287+
return {0, m_mr.main};
288+
}
289+
278290
// Set up the triplet buffer.
279291
device::device_triplet_collection_types::buffer triplet_buffer = {
280292
globalCounter_host->m_nTriplets, m_mr.main};

device/cuda/src/seeding/spacepoint_binning.cu

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ sp_grid_buffer spacepoint_binning::operator()(
6060
cudaStream_t stream = details::get_stream(m_stream);
6161

6262
// Get the spacepoint sizes from the view
63-
auto sp_size = m_copy.get_size(spacepoints_view);
63+
const auto sp_size = m_copy.get_size(spacepoints_view);
64+
65+
if (sp_size == 0) {
66+
return {m_axes.first, m_axes.second, {}, m_mr.main, m_mr.host};
67+
}
6468

6569
// Set up the container that will be filled with the required capacities for
6670
// the spacepoint grid.

device/cuda/src/utils/make_prefix_sum_buff.cu

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ vecmem::data::vector_buffer<device::prefix_sum_element_t> make_prefix_sum_buff(
3838
sizes_sum_view = make_sum_result.view;
3939
const unsigned int totalSize = make_sum_result.totalSize;
4040

41+
if (totalSize == 0) {
42+
return {0, mr.main};
43+
}
44+
4145
// Create buffer and view objects for prefix sum vector
4246
vecmem::data::vector_buffer<device::prefix_sum_element_t> prefix_sum_buff(
4347
totalSize, mr.main);
@@ -65,6 +69,10 @@ vecmem::data::vector_buffer<device::prefix_sum_element_t> make_prefix_sum_buff(
6569
sizes_sum_view = make_sum_result.view;
6670
const unsigned int totalSize = make_sum_result.totalSize;
6771

72+
if (totalSize == 0) {
73+
return {0, mr.main};
74+
}
75+
6876
// Create buffer and view objects for prefix sum vector
6977
vecmem::data::vector_buffer<device::prefix_sum_element_t> prefix_sum_buff(
7078
totalSize, mr.main);

device/sycl/src/clusterization/clusterization_algorithm.sycl

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ clusterization_algorithm::output_type clusterization_algorithm::operator()(
6565
const cell_collection_types::view::size_type num_cells =
6666
m_copy.get_size(cells);
6767

68+
if (num_cells == 0) {
69+
return {output_type::first_type{0, m_mr.main},
70+
output_type::second_type{0, m_mr.main}};
71+
}
72+
6873
// Create result object for the CCL kernel with size overestimation
6974
alt_measurement_collection_types::buffer measurements_buffer(num_cells,
7075
m_mr.main);

device/sycl/src/seeding/seed_finding.sycl

+16-3
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,14 @@ seed_finding::output_type seed_finding::operator()(
8282
vecmem::data::vector_view<device::prefix_sum_element_t>
8383
sp_grid_prefix_sum_view = sp_grid_prefix_sum_buff;
8484

85+
const auto num_spacepoints = m_copy.get_size(sp_grid_prefix_sum_view);
86+
if (num_spacepoints == 0) {
87+
return {0, m_mr.main};
88+
}
89+
8590
// Set up the doublet counter buffer.
8691
device::doublet_counter_collection_types::buffer doublet_counter_buffer = {
87-
m_copy.get_size(sp_grid_prefix_sum_view), m_mr.main,
88-
vecmem::data::buffer_type::resizable};
92+
num_spacepoints, m_mr.main, vecmem::data::buffer_type::resizable};
8993
m_copy.setup(doublet_counter_buffer)->wait();
9094

9195
// Counter for the total number of doublets and triplets
@@ -102,7 +106,7 @@ seed_finding::output_type seed_finding::operator()(
102106
// Calculate the range to run the doublet counting for.
103107
static constexpr unsigned int doubletCountLocalSize = 32 * 2;
104108
auto doubletCountRange = traccc::sycl::calculate1DimNdRange(
105-
m_copy.get_size(sp_grid_prefix_sum_view), doubletCountLocalSize);
109+
num_spacepoints, doubletCountLocalSize);
106110

107111
// Count the number of doublets that we need to produce.
108112
device::doublet_counter_collection_types::view doublet_counter_view =
@@ -135,6 +139,11 @@ seed_finding::output_type seed_finding::operator()(
135139
sizeof(device::seeding_global_counter))
136140
.wait_and_throw();
137141

142+
if (globalCounter_host->m_nMidBot == 0 ||
143+
globalCounter_host->m_nMidTop == 0) {
144+
return {0, m_mr.main};
145+
}
146+
138147
// Set up the doublet buffers.
139148
device::device_doublet_collection_types::buffer doublet_buffer_mb = {
140149
globalCounter_host->m_nMidBot, m_mr.main};
@@ -232,6 +241,10 @@ seed_finding::output_type seed_finding::operator()(
232241
sizeof(device::seeding_global_counter))
233242
.wait_and_throw();
234243

244+
if (globalCounter_host->m_nTriplets == 0) {
245+
return {0, m_mr.main};
246+
}
247+
235248
// Set up the triplet buffer and its view
236249
device::device_triplet_collection_types::buffer triplet_buffer = {
237250
globalCounter_host->m_nTriplets, m_mr.main};

device/sycl/src/seeding/spacepoint_binning.sycl

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ sp_grid_buffer spacepoint_binning::operator()(
4444
const spacepoint_collection_types::const_view& spacepoints_view) const {
4545

4646
// Get the spacepoint sizes from the view
47-
auto sp_size = m_copy.get_size(spacepoints_view);
47+
const auto sp_size = m_copy.get_size(spacepoints_view);
48+
49+
if (sp_size == 0) {
50+
return {m_axes.first, m_axes.second, {}, m_mr.main, m_mr.host};
51+
}
4852

4953
// Set up the container that will be filled with the required capacities for
5054
// the spacepoint grid.

device/sycl/src/utils/make_prefix_sum_buff.sycl

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ vecmem::data::vector_buffer<device::prefix_sum_element_t> make_prefix_sum_buff(
2626
sizes_sum_view = make_sum_result.view;
2727
const unsigned int totalSize = make_sum_result.totalSize;
2828

29+
if (totalSize == 0) {
30+
return {0, mr.main};
31+
}
32+
2933
// Create buffer and view objects for prefix sum vector
3034
vecmem::data::vector_buffer<device::prefix_sum_element_t> prefix_sum_buff(
3135
totalSize, mr.main);

extern/vecmem/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ message( STATUS "Building VecMem as part of the TRACCC project" )
1818

1919
# Declare where to get VecMem from.
2020
set( TRACCC_VECMEM_SOURCE
21-
"URL;https://github.com/acts-project/vecmem/archive/refs/tags/v0.25.0.tar.gz;URL_MD5;7fc14592c693c9853d27ca21ec528555"
21+
"URL;https://github.com/acts-project/vecmem/archive/refs/tags/v0.26.0.tar.gz;URL_MD5;3162c26ced6bb7ce25a5873002e8a2b4"
2222
CACHE STRING "Source for VecMem, when built as part of this project" )
2323
mark_as_advanced( TRACCC_VECMEM_SOURCE )
2424
FetchContent_Declare( VecMem ${TRACCC_VECMEM_SOURCE} )

0 commit comments

Comments
 (0)