Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable -Wconversion #746

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/cpu/toy_detector_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BENCHMARK_F(ToyDetectorBenchmark, CPU)(benchmark::State& state) {

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

auto& spacepoints_per_event = spacepoints[i_evt];
auto& measurements_per_event = measurements[i_evt];
Expand Down
15 changes: 7 additions & 8 deletions benchmarks/cuda/toy_detector_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {

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

int i_evt = i;

// First 10 events are for cold run
if (i < 0) {
i_evt = 0;
}
auto i_evt = static_cast<unsigned int>(std::max(i, 0));

// Measure the time after the cold run
if (i == 0) {
state.ResumeTiming();
Expand All @@ -112,13 +109,15 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {

// Copy the spacepoint and module data to the device.
traccc::spacepoint_collection_types::buffer spacepoints_cuda_buffer(
spacepoints_per_event.size(), mr.main);
static_cast<unsigned int>(spacepoints_per_event.size()),
mr.main);
async_copy(vecmem::get_data(spacepoints_per_event),
spacepoints_cuda_buffer);

traccc::measurement_collection_types::buffer
measurements_cuda_buffer(measurements_per_event.size(),
mr.main);
measurements_cuda_buffer(
static_cast<unsigned int>(measurements_per_event.size()),
mr.main);
async_copy(vecmem::get_data(measurements_per_event),
measurements_cuda_buffer);

Expand Down
2 changes: 1 addition & 1 deletion cmake/traccc-compiler-options-cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if( ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" ) OR
traccc_add_flag( CMAKE_CXX_FLAGS "-pedantic" )
traccc_add_flag( CMAKE_CXX_FLAGS "-Wold-style-cast" )
if(PROJECT_IS_TOP_LEVEL)
traccc_add_flag( CMAKE_CXX_FLAGS "-Wfloat-conversion" )
traccc_add_flag( CMAKE_CXX_FLAGS "-Wconversion" )
endif()

# Fail on warnings, if asked for that behaviour.
Expand Down
4 changes: 4 additions & 0 deletions cmake/traccc-compiler-options-cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" )
traccc_add_flag( CMAKE_CUDA_FLAGS "-Xcompiler /Zc:__cplusplus" )
endif()

if( "${CMAKE_CUDA_COMPILER_ID}" MATCHES "NVIDIA" )
traccc_add_flag( CMAKE_CUDA_FLAGS "-Wconversion" )
endif()

# Set the CUDA architecture to build code for.
set( CMAKE_CUDA_ARCHITECTURES "52" CACHE STRING
"CUDA architectures to build device code for" )
Expand Down
1 change: 1 addition & 0 deletions cmake/traccc-compiler-options-sycl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ foreach( mode RELEASE RELWITHDEBINFO MINSIZEREL DEBUG )
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wno-unknown-cuda-version" )
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wshadow" )
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wunused-local-typedefs" )
traccc_add_flag( CMAKE_SYCL_FLAGS_${mode} "-Wconversion" )
endforeach()

if( NOT WIN32 )
Expand Down
6 changes: 3 additions & 3 deletions core/include/traccc/clusterization/clustering_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ struct clustering_config {
/**
* @brief The maximum number of cells per partition.
*/
TRACCC_HOST_DEVICE constexpr std::size_t max_partition_size() const {
TRACCC_HOST_DEVICE constexpr unsigned int max_partition_size() const {
return threads_per_partition * max_cells_per_thread;
}

/**
* @brief The target number of cells per partition.
*/
TRACCC_HOST_DEVICE constexpr std::size_t target_partition_size() const {
TRACCC_HOST_DEVICE constexpr unsigned int target_partition_size() const {
return threads_per_partition * target_cells_per_thread;
}

/**
* @brief The total size of the scratch space, in number of cells.
*/
TRACCC_HOST_DEVICE constexpr std::size_t backup_size() const {
TRACCC_HOST_DEVICE constexpr unsigned int backup_size() const {
return max_partition_size() * backup_size_multiplier;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ TRACCC_HOST_DEVICE inline vector2 position_from_cell(
const auto module_dd = det_descr.at(cell.module_index());
// Calculate / construct the local cell position.
return {module_dd.reference_x() +
(scalar{0.5} + cell.channel0()) * module_dd.pitch_x(),
(scalar{0.5f} + static_cast<scalar>(cell.channel0())) *
module_dd.pitch_x(),
module_dd.reference_y() +
(scalar{0.5} + cell.channel1()) * module_dd.pitch_y()};
(scalar{0.5f} + static_cast<scalar>(cell.channel1())) *
module_dd.pitch_y()};
}

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

point2 offset{0., 0.};
point2 offset{0.f, 0.f};
bool first_processed = false;

// Loop over the cell indices of the cluster.
Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/clusterization/impl/sparse_ccl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TRACCC_HOST_DEVICE inline unsigned int make_union(
vecmem::device_vector<unsigned int>& labels, unsigned int e1,
unsigned int e2) {

int e;
unsigned int e;
if (e1 < e2) {
e = e1;
assert(e2 < labels.size());
Expand Down
4 changes: 2 additions & 2 deletions core/include/traccc/edm/internal_spacepoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ struct internal_spacepoint {
scalar phi() const { return m_phi; }

TRACCC_HOST_DEVICE
scalar varianceR() const { return 0.; }
scalar varianceR() const { return 0.f; }

TRACCC_HOST_DEVICE
scalar varianceZ() const { return 0.; }
scalar varianceZ() const { return 0.f; }
};

template <typename spacepoint_t>
Expand Down
4 changes: 2 additions & 2 deletions core/include/traccc/edm/measurement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace traccc {
struct measurement {

/// Local 2D coordinates for a measurement on a detector module
point2 local{0., 0.};
point2 local{0.f, 0.f};
/// Variance on the 2D coordinates of the measurement
variance2 variance{0., 0.};
variance2 variance{0.f, 0.f};

/// Geometry ID
detray::geometry::barcode surface_link;
Expand Down
10 changes: 6 additions & 4 deletions core/include/traccc/edm/seed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ struct seed {
const spacepoint_collection_types::const_view& spacepoints_view) const {
const spacepoint_collection_types::const_device spacepoints(
spacepoints_view);
return {spacepoints.at(spB_link).meas, spacepoints.at(spM_link).meas,
spacepoints.at(spT_link).meas};
return {spacepoints.at(static_cast<unsigned int>(spB_link)).meas,
spacepoints.at(static_cast<unsigned int>(spM_link)).meas,
spacepoints.at(static_cast<unsigned int>(spT_link)).meas};
}

TRACCC_HOST_DEVICE
std::array<spacepoint, 3> get_spacepoints(
const spacepoint_collection_types::const_view& spacepoints_view) const {
const spacepoint_collection_types::const_device spacepoints(
spacepoints_view);
return {spacepoints.at(spB_link), spacepoints.at(spM_link),
spacepoints.at(spT_link)};
return {spacepoints.at(static_cast<unsigned int>(spB_link)),
spacepoints.at(static_cast<unsigned int>(spM_link)),
spacepoints.at(static_cast<unsigned int>(spT_link))};
}
};

Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/edm/spacepoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace traccc {
struct spacepoint {

/// The global position of the spacepoint in 3D space
point3 global{0., 0., 0.};
point3 global{0.f, 0.f, 0.f};
/// The local measurement of the spacepoint on the detector surface
measurement meas;

Expand Down
2 changes: 1 addition & 1 deletion core/include/traccc/finding/candidate_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace traccc {
struct candidate_link {

// Type of index
using link_index_type = thrust::pair<int, unsigned int>;
using link_index_type = thrust::pair<unsigned int, unsigned int>;

// Index of link from the previous step
link_index_type previous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,6 @@ using silicon_detector_description = vecmem::edm::container<
vecmem::edm::type::vector<geometry_id>, vecmem::edm::type::vector<scalar>,
vecmem::edm::type::vector<scalar>, vecmem::edm::type::vector<scalar>,
vecmem::edm::type::vector<scalar>, vecmem::edm::type::vector<scalar>,
vecmem::edm::type::vector<char> >;
vecmem::edm::type::vector<unsigned char> >;

} // namespace traccc
6 changes: 4 additions & 2 deletions core/include/traccc/sanity/contiguous_on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ is_contiguous_on(P&& projection, const CONTAINER& in) {
// Compress adjacent elements
for (std::size_t i = 0; i < n; ++i) {
if (i == 0) {
iout[iout_size++] = projection(in.at(i));
iout[iout_size++] =
projection(in.at(static_cast<CONTAINER::size_type>(i)));
} else {
projection_t v = projection(in.at(i));
projection_t v =
projection(in.at(static_cast<CONTAINER::size_type>(i)));

if (v != iout[iout_size - 1]) {
iout[iout_size++] = v;
Expand Down
10 changes: 5 additions & 5 deletions core/include/traccc/seeding/detail/seeding_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ struct seedfinder_config {
// compatible

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

// for how many seeds can one SpacePoint be the middle SpacePoint?
int maxSeedsPerSpM = 10;
unsigned int maxSeedsPerSpM = 10;

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

// average radiation lengths of material on the length of a seed. used for
// scattering.
Expand Down
3 changes: 2 additions & 1 deletion core/include/traccc/seeding/seed_selecting_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ struct seed_selecting_helper {
const spacepoint_collection_t& sp_collection, const seed& seed,
const scalar& triplet_weight) {

const auto& spB = sp_collection.at(seed.spB_link);
const auto& spB =
sp_collection.at(static_cast<unsigned int>(seed.spB_link));

return (triplet_weight > filter_config.seed_min_weight ||
spB.radius() > filter_config.spB_min_radius);
Expand Down
13 changes: 8 additions & 5 deletions core/include/traccc/seeding/spacepoint_binning_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ inline std::pair<detray::axis2::circular<>, detray::axis2::regular<>> get_axes(
// seed making step. So each individual bin should cover
// 1/config.phiBinDeflectionCoverage of the maximum expected azimutal
// deflection
scalar deltaPhi = (outerAngle - innerAngle + deltaAngleWithMaxD0) /
grid_config.phiBinDeflectionCoverage;
scalar deltaPhi =
(outerAngle - innerAngle + deltaAngleWithMaxD0) /
static_cast<scalar>(grid_config.phiBinDeflectionCoverage);

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

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

scalar zBinSize = grid_config.cotThetaMax * grid_config.deltaRMax;
detray::dindex zBins = std::max(
1, static_cast<int>(
std::floor((grid_config.zMax - grid_config.zMin) / zBinSize)));
static_cast<detray::dindex>(1),
static_cast<detray::dindex>(
std::floor((grid_config.zMax - grid_config.zMin) / zBinSize)));

detray::axis2::regular m_z_axis{zBins, grid_config.zMin, grid_config.zMax,
mr};
Expand Down
11 changes: 7 additions & 4 deletions core/include/traccc/seeding/track_params_estimation_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ seed_to_bound_vector(const spacepoint_collection_t& sp_collection,

bound_vector params;

const auto& spB = sp_collection.at(seed.spB_link);
const auto& spM = sp_collection.at(seed.spM_link);
const auto& spT = sp_collection.at(seed.spT_link);
const auto& spB =
sp_collection.at(static_cast<unsigned int>(seed.spB_link));
const auto& spM =
sp_collection.at(static_cast<unsigned int>(seed.spM_link));
const auto& spT =
sp_collection.at(static_cast<unsigned int>(seed.spT_link));

darray<vector3, 3> sp_global_positions;
sp_global_positions[0] = spB.global;
Expand Down Expand Up @@ -110,7 +113,7 @@ seed_to_bound_vector(const spacepoint_collection_t& sp_collection,
scalar qOverPt = 1.f / (R * getter::norm(bfield));
// The estimated q/p in [GeV/c]^-1
getter::element(params, e_bound_qoverp, 0) =
qOverPt / getter::perp(vector2{1., invTanTheta});
qOverPt / getter::perp(vector2{1.f, invTanTheta});

// Make sure the time is a finite value
assert(std::isfinite(getter::element(params, e_bound_time, 0)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ void greedy_ambiguity_resolution_algorithm::resolve(state_t& state) const {
auto track_comperator = [&state](std::size_t a, std::size_t b) {
/// Helper to calculate the relative amount of shared measurements.
auto relative_shared_measurements = [&state](std::size_t i) {
return 1.0 * state.shared_measurements_per_track[i] /
state.measurements_per_track[i].size();
return static_cast<double>(state.shared_measurements_per_track[i]) /
static_cast<double>(state.measurements_per_track[i].size());
};

if (relative_shared_measurements(a) !=
Expand Down
2 changes: 1 addition & 1 deletion core/src/clusterization/measurement_creation_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ measurement_creation_algorithm::operator()(
measurement_collection_types::device measurements{vecmem::get_data(result)};

// Process the clusters one-by-one.
for (std::size_t i = 0; i < clusters.size(); ++i) {
for (decltype(clusters)::size_type i = 0; i < clusters.size(); ++i) {

// Get the cluster.
const auto cluster = clusters[i];
Expand Down
2 changes: 1 addition & 1 deletion core/src/clusterization/sparse_ccl_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sparse_ccl_algorithm::output_type sparse_ccl_algorithm::operator()(
clusters.resize(num_clusters);

// Add cells to their clusters.
for (std::size_t cell_idx = 0; cell_idx < cluster_indices.size();
for (unsigned int cell_idx = 0; cell_idx < cluster_indices.size();
++cell_idx) {
clusters.cell_indices()[cluster_indices[cell_idx]].push_back(cell_idx);
}
Expand Down
Loading
Loading