Skip to content

Commit 716ce87

Browse files
committed
Enable -Wconversion
This commit replaces the existing `Wfloat-conversion` flag with the more strict `-Wconversion` and fixes related errors. These were mostly harmless integer conversions, but certainly also some nasty improper floating point-to-integer conversions which may constitute bugs.
1 parent a143239 commit 716ce87

File tree

122 files changed

+505
-357
lines changed

Some content is hidden

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

122 files changed

+505
-357
lines changed

benchmarks/cpu/toy_detector_cpu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BENCHMARK_F(ToyDetectorBenchmark, CPU)(benchmark::State& state) {
7070

7171
// Iterate over events
7272
#pragma omp parallel for
73-
for (int i_evt = 0; i_evt < n_events; i_evt++) {
73+
for (unsigned int i_evt = 0; i_evt < n_events; i_evt++) {
7474

7575
auto& spacepoints_per_event = spacepoints[i_evt];
7676
auto& measurements_per_event = measurements[i_evt];

benchmarks/cuda/toy_detector_cuda.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,9 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
9696

9797
for (int i = -10; i < n_events; i++) {
9898

99-
int i_evt = i;
100-
10199
// First 10 events are for cold run
102-
if (i < 0) {
103-
i_evt = 0;
104-
}
100+
auto i_evt = static_cast<unsigned int>(std::max(i, 0));
101+
105102
// Measure the time after the cold run
106103
if (i == 0) {
107104
state.ResumeTiming();
@@ -112,13 +109,15 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
112109

113110
// Copy the spacepoint and module data to the device.
114111
traccc::spacepoint_collection_types::buffer spacepoints_cuda_buffer(
115-
spacepoints_per_event.size(), mr.main);
112+
static_cast<unsigned int>(spacepoints_per_event.size()),
113+
mr.main);
116114
async_copy(vecmem::get_data(spacepoints_per_event),
117115
spacepoints_cuda_buffer);
118116

119117
traccc::measurement_collection_types::buffer
120-
measurements_cuda_buffer(measurements_per_event.size(),
121-
mr.main);
118+
measurements_cuda_buffer(
119+
static_cast<unsigned int>(measurements_per_event.size()),
120+
mr.main);
122121
async_copy(vecmem::get_data(measurements_per_event),
123122
measurements_cuda_buffer);
124123

cmake/traccc-compiler-options-cpp.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if( ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" ) OR
2525
traccc_add_flag( CMAKE_CXX_FLAGS "-pedantic" )
2626
traccc_add_flag( CMAKE_CXX_FLAGS "-Wold-style-cast" )
2727
if(PROJECT_IS_TOP_LEVEL)
28-
traccc_add_flag( CMAKE_CXX_FLAGS "-Wfloat-conversion" )
28+
traccc_add_flag( CMAKE_CXX_FLAGS "-Wconversion" )
2929
endif()
3030

3131
# Fail on warnings, if asked for that behaviour.

cmake/traccc-compiler-options-cuda.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" )
1919
traccc_add_flag( CMAKE_CUDA_FLAGS "-Xcompiler /Zc:__cplusplus" )
2020
endif()
2121

22+
if( "${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA" )
23+
traccc_add_flag( CMAKE_CUDA_FLAGS "-Wconversion" )
24+
endif()
25+
2226
# Set the CUDA architecture to build code for.
2327
set( CMAKE_CUDA_ARCHITECTURES "52" CACHE STRING
2428
"CUDA architectures to build device code for" )

cmake/traccc-compiler-options-sycl.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ foreach( mode RELEASE RELWITHDEBINFO MINSIZEREL DEBUG )
2020
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wno-unknown-cuda-version" )
2121
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wshadow" )
2222
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wunused-local-typedefs" )
23+
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wconversion" )
2324
endforeach()
2425

2526
if( NOT WIN32 )

core/include/traccc/clusterization/clustering_config.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ struct clustering_config {
5757
/**
5858
* @brief The maximum number of cells per partition.
5959
*/
60-
TRACCC_HOST_DEVICE constexpr std::size_t max_partition_size() const {
60+
TRACCC_HOST_DEVICE constexpr unsigned int max_partition_size() const {
6161
return threads_per_partition * max_cells_per_thread;
6262
}
6363

6464
/**
6565
* @brief The target number of cells per partition.
6666
*/
67-
TRACCC_HOST_DEVICE constexpr std::size_t target_partition_size() const {
67+
TRACCC_HOST_DEVICE constexpr unsigned int target_partition_size() const {
6868
return threads_per_partition * target_cells_per_thread;
6969
}
7070

7171
/**
7272
* @brief The total size of the scratch space, in number of cells.
7373
*/
74-
TRACCC_HOST_DEVICE constexpr std::size_t backup_size() const {
74+
TRACCC_HOST_DEVICE constexpr unsigned int backup_size() const {
7575
return max_partition_size() * backup_size_multiplier;
7676
}
7777
};

core/include/traccc/clusterization/impl/measurement_creation.ipp

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ TRACCC_HOST_DEVICE inline vector2 position_from_cell(
2626
const auto module_dd = det_descr.at(cell.module_index());
2727
// Calculate / construct the local cell position.
2828
return {module_dd.reference_x() +
29-
(scalar{0.5} + cell.channel0()) * module_dd.pitch_x(),
29+
(scalar{0.5f} + static_cast<scalar>(cell.channel0())) *
30+
module_dd.pitch_x(),
3031
module_dd.reference_y() +
31-
(scalar{0.5} + cell.channel1()) * module_dd.pitch_y()};
32+
(scalar{0.5f} + static_cast<scalar>(cell.channel1())) *
33+
module_dd.pitch_y()};
3234
}
3335

3436
template <typename T>
@@ -38,7 +40,7 @@ TRACCC_HOST_DEVICE inline void calc_cluster_properties(
3840
const silicon_detector_description::const_device& det_descr, point2& mean,
3941
point2& var, scalar& totalWeight) {
4042

41-
point2 offset{0., 0.};
43+
point2 offset{0.f, 0.f};
4244
bool first_processed = false;
4345

4446
// Loop over the cell indices of the cluster.

core/include/traccc/clusterization/impl/sparse_ccl.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ TRACCC_HOST_DEVICE inline unsigned int make_union(
2828
vecmem::device_vector<unsigned int>& labels, unsigned int e1,
2929
unsigned int e2) {
3030

31-
int e;
31+
unsigned int e;
3232
if (e1 < e2) {
3333
e = e1;
3434
assert(e2 < labels.size());

core/include/traccc/edm/internal_spacepoint.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ struct internal_spacepoint {
7878
scalar phi() const { return m_phi; }
7979

8080
TRACCC_HOST_DEVICE
81-
scalar varianceR() const { return 0.; }
81+
scalar varianceR() const { return 0.f; }
8282

8383
TRACCC_HOST_DEVICE
84-
scalar varianceZ() const { return 0.; }
84+
scalar varianceZ() const { return 0.f; }
8585
};
8686

8787
template <typename spacepoint_t>

core/include/traccc/edm/measurement.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ namespace traccc {
3333
struct measurement {
3434

3535
/// Local 2D coordinates for a measurement on a detector module
36-
point2 local{0., 0.};
36+
point2 local{0.f, 0.f};
3737
/// Variance on the 2D coordinates of the measurement
38-
variance2 variance{0., 0.};
38+
variance2 variance{0.f, 0.f};
3939

4040
/// Geometry ID
4141
detray::geometry::barcode surface_link;

core/include/traccc/edm/seed.hpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ struct seed {
3030
const spacepoint_collection_types::const_view& spacepoints_view) const {
3131
const spacepoint_collection_types::const_device spacepoints(
3232
spacepoints_view);
33-
return {spacepoints.at(spB_link).meas, spacepoints.at(spM_link).meas,
34-
spacepoints.at(spT_link).meas};
33+
return {spacepoints.at(static_cast<unsigned int>(spB_link)).meas,
34+
spacepoints.at(static_cast<unsigned int>(spM_link)).meas,
35+
spacepoints.at(static_cast<unsigned int>(spT_link)).meas};
3536
}
3637

3738
TRACCC_HOST_DEVICE
3839
std::array<spacepoint, 3> get_spacepoints(
3940
const spacepoint_collection_types::const_view& spacepoints_view) const {
4041
const spacepoint_collection_types::const_device spacepoints(
4142
spacepoints_view);
42-
return {spacepoints.at(spB_link), spacepoints.at(spM_link),
43-
spacepoints.at(spT_link)};
43+
return {spacepoints.at(static_cast<unsigned int>(spB_link)),
44+
spacepoints.at(static_cast<unsigned int>(spM_link)),
45+
spacepoints.at(static_cast<unsigned int>(spT_link))};
4446
}
4547
};
4648

core/include/traccc/edm/spacepoint.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace traccc {
2828
struct spacepoint {
2929

3030
/// The global position of the spacepoint in 3D space
31-
point3 global{0., 0., 0.};
31+
point3 global{0.f, 0.f, 0.f};
3232
/// The local measurement of the spacepoint on the detector surface
3333
measurement meas;
3434

core/include/traccc/finding/candidate_link.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace traccc {
2020
struct candidate_link {
2121

2222
// Type of index
23-
using link_index_type = thrust::pair<int, unsigned int>;
23+
using link_index_type = thrust::pair<unsigned int, unsigned int>;
2424

2525
// Index of link from the previous step
2626
link_index_type previous;

core/include/traccc/finding/finding_algorithm.ipp

+17-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
2828
const measurement_collection_types::host& measurements,
2929
const bound_track_parameters_collection_types::host& seeds) const {
3030

31+
assert(m_cfg.min_track_candidates_per_track > 1);
32+
3133
/*****************************************************************
3234
* Measurement Operations
3335
*****************************************************************/
@@ -42,15 +44,16 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
4244

4345
auto end = std::unique_copy(measurements.begin(), measurements.end(),
4446
uniques.begin(), measurement_equal_comp());
45-
const unsigned int n_modules = end - uniques.begin();
47+
const auto n_modules = static_cast<unsigned int>(end - uniques.begin());
4648

4749
// Get upper bounds of unique elements
4850
std::vector<unsigned int> upper_bounds;
4951
upper_bounds.reserve(n_modules);
5052
for (unsigned int i = 0; i < n_modules; i++) {
5153
auto up = std::upper_bound(measurements.begin(), measurements.end(),
5254
uniques[i], measurement_sort_comp());
53-
upper_bounds.push_back(std::distance(measurements.begin(), up));
55+
upper_bounds.push_back(
56+
static_cast<unsigned int>(std::distance(measurements.begin(), up)));
5457
}
5558
const auto n_meas = measurements.size();
5659

@@ -88,8 +91,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
8891

8992
std::vector<bound_track_parameters> out_params;
9093

91-
for (int step = 0;
92-
step < static_cast<int>(m_cfg.max_track_candidates_per_track);
94+
for (unsigned int step = 0; step < m_cfg.max_track_candidates_per_track;
9395
step++) {
9496

9597
// Iterate over input parameters
@@ -104,8 +106,8 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
104106
out_params.reserve(n_in_params);
105107

106108
// Previous step ID
107-
const int previous_step =
108-
(step == 0) ? std::numeric_limits<int>::max() : step - 1;
109+
const unsigned int previous_step =
110+
(step == 0) ? std::numeric_limits<unsigned int>::max() : step - 1;
109111

110112
std::fill(n_trks_per_seed.begin(), n_trks_per_seed.end(), 0);
111113

@@ -158,13 +160,14 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
158160

159161
if (lo2 == barcodes.begin()) {
160162
range.first = 0u;
161-
range.second = upper_bounds[bcd_id];
163+
range.second = upper_bounds[static_cast<std::size_t>(bcd_id)];
162164
} else if (lo2 == barcodes.end()) {
163165
range.first = 0u;
164166
range.second = 0u;
165167
} else {
166-
range.first = upper_bounds[bcd_id - 1];
167-
range.second = upper_bounds[bcd_id];
168+
range.first =
169+
upper_bounds[static_cast<std::size_t>(bcd_id - 1)];
170+
range.second = upper_bounds[static_cast<std::size_t>(bcd_id)];
168171
}
169172

170173
unsigned int n_branches = 0;
@@ -223,7 +226,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
223226
* Propagate to the next surface
224227
*********************************/
225228

226-
const unsigned int n_links = links[step].size();
229+
const std::size_t n_links = links[step].size();
227230
for (unsigned int link_id = 0; link_id < n_links; link_id++) {
228231

229232
const unsigned int seed_idx = links[step][link_id].seed_idx;
@@ -276,7 +279,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
276279
// Unless the track found a surface, it is considered a
277280
// tip
278281
else if (!s4.success &&
279-
step >= static_cast<int>(
282+
step >= static_cast<unsigned int>(
280283
m_cfg.min_track_candidates_per_track) -
281284
1) {
282285
tips.push_back({step, link_id});
@@ -285,7 +288,8 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
285288
// If no more CKF step is expected, current candidate is
286289
// kept as a tip
287290
if (s4.success &&
288-
step == static_cast<int>(m_cfg.max_track_candidates_per_track) -
291+
step == static_cast<unsigned int>(
292+
m_cfg.max_track_candidates_per_track) -
289293
1) {
290294
tips.push_back({step, link_id});
291295
}
@@ -319,7 +323,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
319323
break;
320324
}
321325

322-
const unsigned int link_pos =
326+
const unsigned long link_pos =
323327
param_to_link[L.previous.first][L.previous.second];
324328
L = links[L.previous.first][link_pos];
325329
}

core/include/traccc/geometry/silicon_detector_description.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,6 @@ using silicon_detector_description = vecmem::edm::container<
222222
vecmem::edm::type::vector<geometry_id>, vecmem::edm::type::vector<scalar>,
223223
vecmem::edm::type::vector<scalar>, vecmem::edm::type::vector<scalar>,
224224
vecmem::edm::type::vector<scalar>, vecmem::edm::type::vector<scalar>,
225-
vecmem::edm::type::vector<char> >;
225+
vecmem::edm::type::vector<unsigned char> >;
226226

227227
} // namespace traccc

core/include/traccc/sanity/contiguous_on.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ is_contiguous_on(P&& projection, const CONTAINER& in) {
5454
// Compress adjacent elements
5555
for (std::size_t i = 0; i < n; ++i) {
5656
if (i == 0) {
57-
iout[iout_size++] = projection(in.at(i));
57+
iout[iout_size++] =
58+
projection(in.at(static_cast<CONTAINER::size_type>(i)));
5859
} else {
59-
projection_t v = projection(in.at(i));
60+
projection_t v =
61+
projection(in.at(static_cast<CONTAINER::size_type>(i)));
6062

6163
if (v != iout[iout_size - 1]) {
6264
iout[iout_size++] = v;

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ struct seedfinder_config {
5555
// compatible
5656

5757
// impact parameter in mm
58-
float impactMax = 10. * unit<float>::mm;
58+
float impactMax = 10.f * unit<float>::mm;
5959
// how many sigmas of scattering angle should be considered?
60-
float sigmaScattering = 3.0;
60+
float sigmaScattering = 3.0f;
6161
// Upper pt limit for scattering calculation
62-
float maxPtScattering = 10 * unit<float>::GeV;
62+
float maxPtScattering = 10.f * unit<float>::GeV;
6363

6464
// for how many seeds can one SpacePoint be the middle SpacePoint?
65-
int maxSeedsPerSpM = 10;
65+
unsigned int maxSeedsPerSpM = 10;
6666

6767
float bFieldInZ = 1.99724f * unit<float>::T;
6868
// location of beam in x,y plane.
6969
// used as offset for Space Points
70-
vector2 beamPos{-.0 * unit<float>::mm, -.0 * unit<float>::mm};
70+
vector2 beamPos{-.0f * unit<float>::mm, -.0f * unit<float>::mm};
7171

7272
// average radiation lengths of material on the length of a seed. used for
7373
// scattering.

core/include/traccc/seeding/seed_selecting_helper.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ struct seed_selecting_helper {
7272
const spacepoint_collection_t& sp_collection, const seed& seed,
7373
const scalar& triplet_weight) {
7474

75-
const auto& spB = sp_collection.at(seed.spB_link);
75+
const auto& spB =
76+
sp_collection.at(static_cast<unsigned int>(seed.spB_link));
7677

7778
return (triplet_weight > filter_config.seed_min_weight ||
7879
spB.radius() > filter_config.spB_min_radius);

core/include/traccc/seeding/spacepoint_binning_helper.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ inline std::pair<detray::axis2::circular<>, detray::axis2::regular<>> get_axes(
6868
// seed making step. So each individual bin should cover
6969
// 1/config.phiBinDeflectionCoverage of the maximum expected azimutal
7070
// deflection
71-
scalar deltaPhi = (outerAngle - innerAngle + deltaAngleWithMaxD0) /
72-
grid_config.phiBinDeflectionCoverage;
71+
scalar deltaPhi =
72+
(outerAngle - innerAngle + deltaAngleWithMaxD0) /
73+
static_cast<scalar>(grid_config.phiBinDeflectionCoverage);
7374

7475
// sanity check: if the delta phi is equal to or less than zero, we'll
7576
// be creating an infinite or a negative number of bins, which would be
@@ -82,7 +83,8 @@ inline std::pair<detray::axis2::circular<>, detray::axis2::regular<>> get_axes(
8283

8384
// divide 2pi by angle delta to get number of phi-bins
8485
// size is always 2pi even for regions of interest
85-
phiBins = std::llround(2 * M_PI / deltaPhi + 0.5);
86+
phiBins = static_cast<detray::dindex>(
87+
std::llround(2 * M_PI / deltaPhi + 0.5));
8688
// need to scale the number of phi bins accordingly to the number of
8789
// consecutive phi bins in the seed making step.
8890
// Each individual bin should be approximately a fraction (depending on
@@ -99,8 +101,9 @@ inline std::pair<detray::axis2::circular<>, detray::axis2::regular<>> get_axes(
99101

100102
scalar zBinSize = grid_config.cotThetaMax * grid_config.deltaRMax;
101103
detray::dindex zBins = std::max(
102-
1, static_cast<int>(
103-
std::floor((grid_config.zMax - grid_config.zMin) / zBinSize)));
104+
static_cast<detray::dindex>(1),
105+
static_cast<detray::dindex>(
106+
std::floor((grid_config.zMax - grid_config.zMin) / zBinSize)));
104107

105108
detray::axis2::regular m_z_axis{zBins, grid_config.zMin, grid_config.zMax,
106109
mr};

0 commit comments

Comments
 (0)