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

Add misc-const-correctness clang tidy check #625

Merged
merged 1 commit into from
Sep 6, 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 .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
#
# SPDX-License-Identifier: MIT
---
Checks: '-*,bugprone-reserved-identifier,hicpp-avoid-c-arrays,modernize-use-nullptr,readability-avoid-const-params-in-decls'
Checks: '-*,bugprone-reserved-identifier,hicpp-avoid-c-arrays,misc-const-correctness,modernize-use-nullptr,readability-avoid-const-params-in-decls'
WarningsAsErrors: '*'
14 changes: 7 additions & 7 deletions benchmarks/deepcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static void deepcopy_1d(benchmark::State& state)
std::vector<double> src_data(state.range(0), 0.0);
std::vector<double> dst_data(state.range(0), -1.0);
DDomX const dom(DElemX(0), DVectX(state.range(0)));
ChunkSpanX<double> src(src_data.data(), dom);
ChunkSpanX<double> dst(dst_data.data(), dom);
ChunkSpanX<double> const src(src_data.data(), dom);
ChunkSpanX<double> const dst(dst_data.data(), dom);
for (auto _ : state) {
ddc::parallel_deepcopy(dst, src);
}
Expand Down Expand Up @@ -97,8 +97,8 @@ static void deepcopy_2d(benchmark::State& state)
std::vector<double> src_data(state.range(0) * state.range(1), 0.0);
std::vector<double> dst_data(state.range(0) * state.range(1), -1.0);
DDomXY const dom(DElemXY(0, 0), DVectXY(state.range(0) - 1, state.range(1) - 1));
ChunkSpanXY<double> src(src_data.data(), dom);
ChunkSpanXY<double> dst(dst_data.data(), dom);
ChunkSpanXY<double> const src(src_data.data(), dom);
ChunkSpanXY<double> const dst(dst_data.data(), dom);
for (auto _ : state) {
ddc::parallel_deepcopy(dst, src);
}
Expand All @@ -112,10 +112,10 @@ static void deepcopy_subchunk_2d(benchmark::State& state)
std::vector<double> src_data(state.range(0) * state.range(1), 0.0);
std::vector<double> dst_data(state.range(0) * state.range(1), -1.0);
DDomXY const dom(DElemXY(0, 0), DVectXY(state.range(0) - 1, state.range(1) - 1));
ChunkSpanXY<double> src(src_data.data(), dom);
ChunkSpanXY<double> dst(dst_data.data(), dom);
ChunkSpanXY<double> const src(src_data.data(), dom);
ChunkSpanXY<double> const dst(dst_data.data(), dom);
for (auto _ : state) {
for (DElemX i : ddc::select<DDimX>(dom)) {
for (DElemX const i : ddc::select<DDimX>(dom)) {
auto&& dst_i = dst[i];
auto&& src_i = src[i];
ddc::parallel_deepcopy(dst_i, src_i);
Expand Down
44 changes: 24 additions & 20 deletions benchmarks/splines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,43 @@ namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(SPLINES_CPP)
// Function to monitor GPU memory asynchronously
void monitorMemoryAsync(std::mutex& mutex, bool& monitorFlag, size_t& maxUsedMem)
{
size_t freeMem = 0;
size_t totalMem = 0;
while (monitorFlag) {
std::this_thread::sleep_for(std::chrono::microseconds(10)); // Adjust the interval as needed

// Acquire a lock to ensure thread safety when accessing CUDA functions
std::lock_guard<std::mutex> lock(mutex);
std::lock_guard<std::mutex> const lock(mutex);

#if defined(__CUDACC__)
std::size_t freeMem = 0;
std::size_t totalMem = 0;
cudaMemGetInfo(&freeMem, &totalMem);
std::size_t const usedMem = totalMem - freeMem;
#else
std::size_t const usedMem = 0;
#endif
maxUsedMem = std::max(maxUsedMem, totalMem - freeMem);

maxUsedMem = std::max(maxUsedMem, usedMem);
}
}

template <typename ExecSpace, typename NonUniform, std::size_t s_degree_x>
static void characteristics_advection_unitary(benchmark::State& state)
{
std::size_t nx = state.range(3);
std::size_t ny = state.range(4);
std::size_t const nx = state.range(3);
std::size_t const ny = state.range(4);
int cols_per_chunk = state.range(5);
int preconditioner_max_block_size = state.range(6);

size_t freeMem = 0;
size_t totalMem = 0;

#if defined(__CUDACC__)
std::size_t freeMem = 0;
std::size_t totalMem = 0;
cudaMemGetInfo(&freeMem, &totalMem);
// cudaMemGetInfo gives GPU total memory occupation, we consider that other users of the GPU have constant occupancy and substract it.
std::size_t const initUsedMem = totalMem - freeMem;
#else
std::size_t const initUsedMem = 0;
#endif
size_t initUsedMem
= totalMem
- freeMem; // cudaMemGetInfo gives GPU total memory occupation, we consider that other users of the GPU have constant occupancy and substract it.
size_t maxUsedMem = initUsedMem;

bool monitorFlag = true;
Expand Down Expand Up @@ -113,7 +119,7 @@ static void characteristics_advection_unitary(benchmark::State& state)
ddc::BoundCond::PERIODIC,
ddc::BoundCond::PERIODIC>::
template get_sampling<DDimX<NonUniform, s_degree_x>>());
ddc::DiscreteDomain<DDimY> y_domain = ddc::init_discrete_space<DDimY>(DDimY::init<DDimY>(
ddc::DiscreteDomain<DDimY> const y_domain = ddc::init_discrete_space<DDimY>(DDimY::init<DDimY>(
ddc::Coordinate<Y>(-1.),
ddc::Coordinate<Y>(1.),
ddc::DiscreteVector<DDimY>(ny)));
Expand All @@ -127,7 +133,7 @@ static void characteristics_advection_unitary(benchmark::State& state)
ddc::KokkosAllocator<double, typename ExecSpace::memory_space>());
ddc::ChunkSpan const density = density_alloc.span_view();
// Initialize the density on the main domain
ddc::DiscreteDomain<DDimX<NonUniform, s_degree_x>, DDimY> x_mesh
ddc::DiscreteDomain<DDimX<NonUniform, s_degree_x>, DDimY> const x_mesh
= ddc::DiscreteDomain<DDimX<NonUniform, s_degree_x>, DDimY>(x_domain, y_domain);
ddc::parallel_for_each(
ExecSpace(),
Expand All @@ -147,9 +153,8 @@ static void characteristics_advection_unitary(benchmark::State& state)
ddc::BoundCond::PERIODIC,
Backend,
DDimX<NonUniform, s_degree_x>,
DDimY>
spline_builder(x_mesh, cols_per_chunk, preconditioner_max_block_size);
ddc::PeriodicExtrapolationRule<X> periodic_extrapolation;
DDimY> const spline_builder(x_mesh, cols_per_chunk, preconditioner_max_block_size);
ddc::PeriodicExtrapolationRule<X> const periodic_extrapolation;
ddc::SplineEvaluator<
ExecSpace,
typename ExecSpace::memory_space,
Expand All @@ -158,16 +163,15 @@ static void characteristics_advection_unitary(benchmark::State& state)
ddc::PeriodicExtrapolationRule<X>,
ddc::PeriodicExtrapolationRule<X>,
DDimX<NonUniform, s_degree_x>,
DDimY>
spline_evaluator(periodic_extrapolation, periodic_extrapolation);
DDimY> const spline_evaluator(periodic_extrapolation, periodic_extrapolation);
ddc::Chunk coef_alloc(
spline_builder.batched_spline_domain(),
ddc::KokkosAllocator<double, typename ExecSpace::memory_space>());
ddc::ChunkSpan coef = coef_alloc.span_view();
ddc::ChunkSpan const coef = coef_alloc.span_view();
ddc::Chunk feet_coords_alloc(
spline_builder.batched_interpolation_domain(),
ddc::KokkosAllocator<ddc::Coordinate<X>, typename ExecSpace::memory_space>());
ddc::ChunkSpan feet_coords = feet_coords_alloc.span_view();
ddc::ChunkSpan const feet_coords = feet_coords_alloc.span_view();

for (auto _ : state) {
Kokkos::Profiling::pushRegion("FeetCharacteristics");
Expand Down
15 changes: 7 additions & 8 deletions examples/characteristics_advection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void display(double time, ChunkType density)
std::cout << "At t = " << time << ",\n";
std::cout << " * mean density = " << mean_density << "\n";
// take a slice in the middle of the box
ddc::ChunkSpan density_slice = density
ddc::ChunkSpan const density_slice = density
[ddc::get_domain<DDimY>(density).front()
+ ddc::get_domain<DDimY>(density).size() / 2];
std::cout << " * density[y:"
Expand Down Expand Up @@ -189,7 +189,7 @@ int main(int argc, char** argv)
ddc::ChunkSpan const initial_density
= last_density_alloc.span_view();
// Initialize the density on the main domain
ddc::DiscreteDomain<DDimX, DDimY> x_mesh
ddc::DiscreteDomain<DDimX, DDimY> const x_mesh
= ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain);
ddc::parallel_for_each(
x_mesh,
Expand Down Expand Up @@ -228,9 +228,8 @@ int main(int argc, char** argv)
BoundCond,
ddc::SplineSolver::LAPACK,
DDimX,
DDimY>
spline_builder(x_mesh);
ExtrapolationRule extrapolation_rule;
DDimY> const spline_builder(x_mesh);
ExtrapolationRule const extrapolation_rule;
ddc::SplineEvaluator<
Kokkos::DefaultExecutionSpace,
Kokkos::DefaultExecutionSpace::memory_space,
Expand All @@ -239,7 +238,7 @@ int main(int argc, char** argv)
ExtrapolationRule,
ExtrapolationRule,
DDimX,
DDimY>
DDimY> const
spline_evaluator(extrapolation_rule, extrapolation_rule);
//! [instantiate solver]

Expand All @@ -248,13 +247,13 @@ int main(int argc, char** argv)
ddc::Chunk coef_alloc(
spline_builder.batched_spline_domain(),
ddc::DeviceAllocator<double>());
ddc::ChunkSpan coef = coef_alloc.span_view();
ddc::ChunkSpan const coef = coef_alloc.span_view();

// Instantiate chunk to receive feet coords
ddc::Chunk feet_coords_alloc(
spline_builder.batched_interpolation_domain(),
ddc::DeviceAllocator<ddc::Coordinate<X>>());
ddc::ChunkSpan feet_coords = feet_coords_alloc.span_view();
ddc::ChunkSpan const feet_coords = feet_coords_alloc.span_view();
//! [instantiate intermediate chunks]


Expand Down
4 changes: 2 additions & 2 deletions examples/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ int main()
ddc::Chunk cells_in_host_alloc
= ddc::create_mirror(cells_in_dev_alloc.span_cview());

ddc::ChunkSpan cells_in = cells_in_dev_alloc.span_view();
ddc::ChunkSpan cells_out = cells_out_dev_alloc.span_view();
ddc::ChunkSpan const cells_in = cells_in_dev_alloc.span_view();
ddc::ChunkSpan const cells_out = cells_out_dev_alloc.span_view();

// Initialize the whole domain
blinker_init(domain_xy, cells_in);
Expand Down
2 changes: 1 addition & 1 deletion examples/heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void display(double time, ChunkType temp)
std::cout << "At t = " << time << ",\n";
std::cout << " * mean temperature = " << mean_temp << "\n";
// take a slice in the middle of the box
ddc::ChunkSpan temp_slice
ddc::ChunkSpan const temp_slice
= temp[ddc::get_domain<DDimY>(temp).front()
+ ddc::get_domain<DDimY>(temp).size() / 2];
std::cout << " * temperature[y:"
Expand Down
6 changes: 3 additions & 3 deletions examples/heat_equation_spectral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int main(int argc, char** argv)
ddc::Coordinate<X>(x_start),
ddc::Coordinate<X>(x_end),
ddc::DiscreteVector<DDimX>(nb_x_points)));
ddc::DiscreteDomain<DDimX> x_domain
ddc::DiscreteDomain<DDimX> const x_domain
= x_domain_with_periodic_point.remove_last(
ddc::DiscreteVector<DDimX>(1));

Expand All @@ -120,7 +120,7 @@ int main(int argc, char** argv)
ddc::Coordinate<Y>(y_start),
ddc::Coordinate<Y>(y_end),
ddc::DiscreteVector<DDimY>(nb_y_points)));
ddc::DiscreteDomain<DDimY> y_domain
ddc::DiscreteDomain<DDimY> const y_domain
= y_domain_with_periodic_point.remove_last(
ddc::DiscreteVector<DDimY>(1));

Expand Down Expand Up @@ -201,7 +201,7 @@ int main(int argc, char** argv)

// Stencil computation on the main domain
ddc::kwArgs_fft const kwargs {ddc::FFT_Normalization::BACKWARD};
Kokkos::DefaultExecutionSpace execution_space;
Kokkos::DefaultExecutionSpace const execution_space;
ddc::fft(execution_space, Ff, last_temp, kwargs);
ddc::parallel_for_each(
execution_space,
Expand Down
14 changes: 7 additions & 7 deletions examples/non_uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void display(double time, ChunkType temp)
std::cout << std::fixed << std::setprecision(3);
std::cout << "At t = " << time << ",\n";
std::cout << " * mean temperature = " << mean_temp << "\n";
ddc::ChunkSpan temp_slice
ddc::ChunkSpan const temp_slice
= temp[ddc::get_domain<DDimY>(temp).front()
+ ddc::get_domain<DDimY>(temp).size() / 2];
std::cout << " * temperature[y:"
Expand Down Expand Up @@ -152,14 +152,14 @@ int main(int argc, char** argv)
= generate_random_vector(nb_x_points, x_start, x_end);
//! [iterator_main-domain]

std::size_t size_x = x_domain_vect.size();
std::size_t const size_x = x_domain_vect.size();

//! [ghost_points_x]
std::vector<double> x_pre_ghost_vect {
std::vector<double> const x_pre_ghost_vect {
x_domain_vect.front()
- (x_domain_vect.back() - x_domain_vect[size_x - 2])};

std::vector<double> x_post_ghost_vect {
std::vector<double> const x_post_ghost_vect {
x_domain_vect.back()
+ (x_domain_vect[1] - x_domain_vect.front())};
//! [ghost_points_x]
Expand All @@ -182,13 +182,13 @@ int main(int argc, char** argv)
std::vector<double> y_domain_vect
= generate_random_vector(nb_y_points, y_start, y_end);

std::size_t size_y = y_domain_vect.size();
std::size_t const size_y = y_domain_vect.size();

//! [ghost_points_y]
std::vector<double> y_pre_ghost_vect {
std::vector<double> const y_pre_ghost_vect {
y_domain_vect.front()
- (y_domain_vect.back() - y_domain_vect[size_y - 2])};
std::vector<double> y_post_ghost_vect {
std::vector<double> const y_post_ghost_vect {
y_domain_vect.back()
+ (y_domain_vect[1] - y_domain_vect.front())};
//! [ghost_points_y]
Expand Down
2 changes: 1 addition & 1 deletion examples/uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void display(double time, ChunkType temp)
std::cout << std::fixed << std::setprecision(3);
std::cout << "At t = " << time << ",\n";
std::cout << " * mean temperature = " << mean_temp << "\n";
ddc::ChunkSpan temp_slice
ddc::ChunkSpan const temp_slice
= temp[ddc::get_domain<DDimY>(temp).front()
+ ddc::get_domain<DDimY>(temp).size() / 2];
std::cout << " * temperature[y:"
Expand Down
17 changes: 9 additions & 8 deletions include/ddc/chunk_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
ptr,
std::experimental::layout_stride::mapping<extents_type>());
}
extents_type extents_r(::ddc::extents<DDims>(domain).value()...);
mapping_type mapping_r(extents_r);
extents_type const extents_r(::ddc::extents<DDims>(domain).value()...);
mapping_type const mapping_r(extents_r);

extents_type extents_s((front<DDims>(domain) + ddc::extents<DDims>(domain)).uid()...);
std::array<std::size_t, sizeof...(DDims)> strides_s {
extents_type const extents_s((front<DDims>(domain) + ddc::extents<DDims>(domain)).uid()...);
std::array<std::size_t, sizeof...(DDims)> const strides_s {
mapping_r.stride(type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
std::experimental::layout_stride::mapping<extents_type> mapping_s(extents_s, strides_s);
std::experimental::layout_stride::mapping<extents_type> const
mapping_s(extents_s, strides_s);
return internal_mdspan_type(ptr - mapping_s(front<DDims>(domain).uid()...), mapping_s);
}

Expand Down Expand Up @@ -297,12 +298,12 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
KOKKOS_FUNCTION constexpr allocation_mdspan_type allocation_mdspan() const
{
DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
extents_type extents_s(::ddc::extents<DDims>(m_domain).value()...);
extents_type const extents_s(::ddc::extents<DDims>(m_domain).value()...);
if constexpr (std::is_same_v<LayoutStridedPolicy, std::experimental::layout_stride>) {
mapping_type map(extents_s, m_internal_mdspan.mapping().strides());
mapping_type const map(extents_s, m_internal_mdspan.mapping().strides());
return allocation_mdspan_type(data_handle(), map);
} else {
mapping_type map(extents_s);
mapping_type const map(extents_s);
return allocation_mdspan_type(data_handle(), map);
}
DDC_IF_NVCC_THEN_POP
Expand Down
9 changes: 5 additions & 4 deletions include/ddc/chunk_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ class ChunkSpan<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy, Memo
&& ...));
namespace stdex = std::experimental;
if (!domain.empty()) {
extents_type extents_s((front<DDims>(domain) + extents<DDims>(domain)).uid()...);
std::array<std::size_t, sizeof...(DDims)> strides_s {allocation_mdspan.mapping().stride(
type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
stdex::layout_stride::mapping<extents_type> mapping_s(extents_s, strides_s);
extents_type const extents_s((front<DDims>(domain) + extents<DDims>(domain)).uid()...);
std::array<std::size_t, sizeof...(DDims)> const strides_s {
allocation_mdspan.mapping().stride(
type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
stdex::layout_stride::mapping<extents_type> const mapping_s(extents_s, strides_s);
this->m_internal_mdspan = internal_mdspan_type(
allocation_mdspan.data_handle() - mapping_s(front<DDims>(domain).uid()...),
mapping_s);
Expand Down
16 changes: 7 additions & 9 deletions include/ddc/detail/kokkos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ KOKKOS_FUNCTION mdspan_to_kokkos_layout_t<typename MP::layout_type> build_kokkos
std::experimental::mdspan<
std::size_t,
std::experimental::extents<std::size_t, sizeof...(Is), 2>,
std::experimental::layout_right>
interleaved_extents_strides(storage.data());
std::experimental::layout_right> const interleaved_extents_strides(storage.data());
((interleaved_extents_strides(Is, 0) = ep.extent(Is),
interleaved_extents_strides(Is, 1) = mapping.stride(Is)),
...);
Expand Down Expand Up @@ -175,14 +174,13 @@ struct use_annotated_operator
template <class ExecSpace>
constexpr bool need_annotated_operator() noexcept
{
bool need_annotation = false;
#ifdef KOKKOS_ENABLE_CUDA
need_annotation = need_annotation || std::is_same_v<ExecSpace, Kokkos::Cuda>;
#if defined(KOKKOS_ENABLE_CUDA)
return std::is_same_v<ExecSpace, Kokkos::Cuda>;
#elif defined(KOKKOS_ENABLE_HIP)
return std::is_same_v<ExecSpace, Kokkos::HIP>;
#else
return false;
#endif
#ifdef KOKKOS_ENABLE_HIP
need_annotation = need_annotation || std::is_same_v<ExecSpace, Kokkos::HIP>;
#endif
return need_annotation;
}

} // namespace ddc::detail
Loading