Skip to content

Commit

Permalink
Add misc-use-anonymous-namespace check (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Dec 27, 2024
1 parent 01d2b47 commit b3e8e1e
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 85 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ misc-*,
-misc-redundant-expression,
-misc-static-assert,
-misc-unused-parameters,
-misc-use-anonymous-namespace,
-misc-use-internal-linkage,
modernize-*,
-modernize-pass-by-value,
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/deepcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ std::size_t constexpr large_dim2_2D = large_dim1_2D;

std::size_t constexpr large_dim1_1D = large_dim1_2D * large_dim1_2D;

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(DEEPCOPY_CPP)


static void memcpy_1d(benchmark::State& state)
void memcpy_1d(benchmark::State& state)
{
std::vector<double> src_data(state.range(0), 0.0);
std::vector<double> dst_data(state.range(0), -1.0);
Expand All @@ -62,7 +59,7 @@ static void memcpy_1d(benchmark::State& state)
state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(state.range(0) * sizeof(double)));
}

static void deepcopy_1d(benchmark::State& state)
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);
Expand All @@ -75,7 +72,7 @@ static void deepcopy_1d(benchmark::State& state)
state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(state.range(0) * sizeof(double)));
}

static void memcpy_2d(benchmark::State& state)
void memcpy_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);
Expand All @@ -92,7 +89,7 @@ static void memcpy_2d(benchmark::State& state)
* int64_t(state.range(0) * state.range(1) * sizeof(double)));
}

static void deepcopy_2d(benchmark::State& state)
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);
Expand All @@ -107,7 +104,7 @@ static void deepcopy_2d(benchmark::State& state)
* int64_t(state.range(0) * state.range(1) * sizeof(double)));
}

static void deepcopy_subchunk_2d(benchmark::State& state)
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);
Expand All @@ -126,7 +123,9 @@ static void deepcopy_subchunk_2d(benchmark::State& state)
* int64_t(state.range(0) * state.range(1) * sizeof(double)));
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(DEEPCOPY_CPP)

// NOLINTBEGIN(misc-use-anonymous-namespace)
// 1D
BENCHMARK(memcpy_1d)->Arg(small_dim1_1D);
BENCHMARK(deepcopy_1d)->Arg(small_dim1_1D);
Expand All @@ -139,6 +138,7 @@ BENCHMARK(deepcopy_subchunk_2d)->Args({small_dim1_2D, small_dim2_2D});
BENCHMARK(memcpy_2d)->Args({large_dim1_2D, large_dim2_2D});
BENCHMARK(deepcopy_2d)->Args({large_dim1_2D, large_dim2_2D});
BENCHMARK(deepcopy_subchunk_2d)->Args({large_dim1_2D, large_dim2_2D});
// NOLINTEND(misc-use-anonymous-namespace)

int main(int argc, char** argv)
{
Expand Down
15 changes: 9 additions & 6 deletions benchmarks/splines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

#include <Kokkos_Core.hpp>

static const ddc::SplineSolver Backend = ddc::SplineSolver::LAPACK;

namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(SPLINES_CPP) {

ddc::SplineSolver const Backend = ddc::SplineSolver::LAPACK;

struct X
{
static constexpr bool PERIODIC = true;
Expand Down Expand Up @@ -59,8 +59,6 @@ struct DDimY : ddc::UniformPointSampling<Y>
{
};

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(SPLINES_CPP)

// Function to monitor GPU memory asynchronously
void monitorMemoryAsync(std::mutex& mutex, bool& monitorFlag, std::size_t& maxUsedMem)
{
Expand All @@ -84,7 +82,7 @@ void monitorMemoryAsync(std::mutex& mutex, bool& monitorFlag, std::size_t& maxUs
}

template <typename ExecSpace, bool IsNonUniform, std::size_t s_degree_x>
static void characteristics_advection_unitary(benchmark::State& state)
void characteristics_advection_unitary(benchmark::State& state)
{
std::size_t const nx = state.range(3);
std::size_t const ny = state.range(4);
Expand Down Expand Up @@ -228,7 +226,7 @@ static void characteristics_advection_unitary(benchmark::State& state)
////////////////////////////////////////////////////
}

static void characteristics_advection(benchmark::State& state)
void characteristics_advection(benchmark::State& state)
{
long const host = 0;
long const dev = 1;
Expand Down Expand Up @@ -265,6 +263,8 @@ static void characteristics_advection(benchmark::State& state)
benchs.at(std::array {state.range(0), state.range(1), state.range(2)})(state);
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(SPLINES_CPP)

// Reference parameters: the benchmarks sweep on two parameters and fix all the others according to those reference parameters.
bool on_gpu_ref = true;
bool non_uniform_ref = false;
Expand All @@ -284,6 +284,7 @@ std::size_t ny_ref = 1000;

// Sweep on spline order
std::string name = "degree_x";
// NOLINTBEGIN(misc-use-anonymous-namespace)
BENCHMARK(characteristics_advection)
->RangeMultiplier(2)
->Ranges(
Expand All @@ -296,6 +297,8 @@ BENCHMARK(characteristics_advection)
{preconditioner_max_block_size_ref, preconditioner_max_block_size_ref}})
->MinTime(3)
->UseRealTime();
// NOLINTEND(misc-use-anonymous-namespace)

/*
// Sweep on ny
std::string name = "ny";
Expand Down
8 changes: 4 additions & 4 deletions examples/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ struct DDimY
{
};

static unsigned nt = 10;
static unsigned length = 5;
static unsigned height = 5;

void blinker_init(
ddc::DiscreteDomain<DDimX, DDimY> const& domain,
ddc::ChunkSpan<
Expand Down Expand Up @@ -71,6 +67,10 @@ int main()
Kokkos::ScopeGuard const kokkos_scope;
ddc::ScopeGuard const ddc_scope;

unsigned const nt = 10;
unsigned const length = 5;
unsigned const height = 5;

ddc::DiscreteDomain<DDimX, DDimY> const domain_xy(
ddc::DiscreteElement<DDimX, DDimY>(0, 0),
ddc::DiscreteVector<DDimX, DDimY>(length, height));
Expand Down
10 changes: 7 additions & 3 deletions tests/fft/fft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#endif
#endif

namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(FFT_CPP) {

template <typename X>
struct DDim : ddc::UniformPointSampling<X>
{
Expand All @@ -45,7 +47,7 @@ struct DFDim : ddc::PeriodicSampling<Kx>
};

template <typename X>
static void test_fourier_mesh(std::size_t Nx)
void test_fourier_mesh(std::size_t Nx)
{
double const a = -10;
double const b = 10;
Expand Down Expand Up @@ -75,7 +77,7 @@ static void test_fourier_mesh(std::size_t Nx)
// TODO:
// - FFT multidim but according to a subset of dimensions
template <typename ExecSpace, typename MemorySpace, typename Tin, typename Tout, typename... X>
static void test_fft()
void test_fft()
{
ExecSpace const exec_space;
bool const full_fft
Expand Down Expand Up @@ -167,7 +169,7 @@ static void test_fft()
}

template <typename ExecSpace, typename MemorySpace, typename Tin, typename Tout, typename X>
static void test_fft_norm(ddc::FFT_Normalization const norm)
void test_fft_norm(ddc::FFT_Normalization const norm)
{
ExecSpace const exec_space;
bool const full_fft
Expand Down Expand Up @@ -237,6 +239,8 @@ struct RDimX;
struct RDimY;
struct RDimZ;

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(FFT_CPP)

TEST(FourierMesh, Even)
{
test_fourier_mesh<RDimX>(16);
Expand Down
34 changes: 25 additions & 9 deletions tests/parallel_transform_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <Kokkos_Core.hpp>

namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP) {

using DElem0D = ddc::DiscreteElement<>;
using DVect0D = ddc::DiscreteVector<>;
using DDom0D = ddc::DiscreteDomain<>;
Expand All @@ -32,14 +34,16 @@ using DElemXY = ddc::DiscreteElement<DDimX, DDimY>;
using DVectXY = ddc::DiscreteVector<DDimX, DDimY>;
using DDomXY = ddc::DiscreteDomain<DDimX, DDimY>;

static DElemX constexpr lbound_x(0);
static DVectX constexpr nelems_x(10);
DElemX constexpr lbound_x(0);
DVectX constexpr nelems_x(10);

DElemY constexpr lbound_y(0);
DVectY constexpr nelems_y(12);

static DElemY constexpr lbound_y(0);
static DVectY constexpr nelems_y(12);
DElemXY constexpr lbound_x_y(lbound_x, lbound_y);
DVectXY constexpr nelems_x_y(nelems_x, nelems_y);

static DElemXY constexpr lbound_x_y(lbound_x, lbound_y);
static DVectXY constexpr nelems_x_y(nelems_x, nelems_y);
} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP)

TEST(ParallelTransformReduceHost, ZeroDimension)
{
Expand Down Expand Up @@ -92,7 +96,9 @@ TEST(ParallelTransformReduceHost, TwoDimensions)
dom.size() * (dom.size() - 1) / 2);
}

static void TestParallelTransformReduceDeviceZeroDimension()
namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP) {

void TestParallelTransformReduceDeviceZeroDimension()
{
DDom0D const dom;
ddc::Chunk<int, DDom0D, ddc::DeviceAllocator<int>> storage(dom);
Expand All @@ -107,12 +113,16 @@ static void TestParallelTransformReduceDeviceZeroDimension()
dom.size() * (dom.size() - 1) / 2);
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP)

TEST(ParallelTransformReduceDevice, ZeroDimension)
{
TestParallelTransformReduceDeviceZeroDimension();
}

static void TestParallelTransformReduceDeviceOneDimension()
namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP) {

void TestParallelTransformReduceDeviceOneDimension()
{
DDomX const dom(lbound_x, nelems_x);
ddc::Chunk<int, DDomX, ddc::DeviceAllocator<int>> storage(dom);
Expand All @@ -127,12 +137,16 @@ static void TestParallelTransformReduceDeviceOneDimension()
dom.size() * (dom.size() - 1) / 2);
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP)

TEST(ParallelTransformReduceDevice, OneDimension)
{
TestParallelTransformReduceDeviceOneDimension();
}

static void TestParallelTransformReduceDeviceTwoDimensions()
namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP) {

void TestParallelTransformReduceDeviceTwoDimensions()
{
DDomXY const dom(lbound_x_y, nelems_x_y);
ddc::Chunk<int, DDomXY, ddc::DeviceAllocator<int>> storage(dom);
Expand All @@ -149,6 +163,8 @@ static void TestParallelTransformReduceDeviceTwoDimensions()
dom.size() * (dom.size() - 1) / 2);
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(PARALLEL_TRANSFORM_REDUCE_CPP)

TEST(ParallelTransformReduceDevice, TwoDimensions)
{
TestParallelTransformReduceDeviceTwoDimensions();
Expand Down
38 changes: 16 additions & 22 deletions tests/splines/batched_2d_spline_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#endif
#include "spline_error_bounds.hpp"

namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(BATCHED_2D_SPLINE_BUILDER_CPP) {

#if defined(BC_PERIODIC)
struct DimX
{
Expand All @@ -42,11 +44,6 @@ struct DimZ
{
static constexpr bool PERIODIC = true;
};

struct DimT
{
static constexpr bool PERIODIC = true;
};
#else

struct DimX
Expand All @@ -63,24 +60,19 @@ struct DimZ
{
static constexpr bool PERIODIC = false;
};

struct DimT
{
static constexpr bool PERIODIC = false;
};
#endif

static constexpr std::size_t s_degree = DEGREE;
constexpr std::size_t s_degree = DEGREE;

#if defined(BC_PERIODIC)
static constexpr ddc::BoundCond s_bcl = ddc::BoundCond::PERIODIC;
static constexpr ddc::BoundCond s_bcr = ddc::BoundCond::PERIODIC;
constexpr ddc::BoundCond s_bcl = ddc::BoundCond::PERIODIC;
constexpr ddc::BoundCond s_bcr = ddc::BoundCond::PERIODIC;
#elif defined(BC_GREVILLE)
static constexpr ddc::BoundCond s_bcl = ddc::BoundCond::GREVILLE;
static constexpr ddc::BoundCond s_bcr = ddc::BoundCond::GREVILLE;
constexpr ddc::BoundCond s_bcl = ddc::BoundCond::GREVILLE;
constexpr ddc::BoundCond s_bcr = ddc::BoundCond::GREVILLE;
#elif defined(BC_HERMITE)
static constexpr ddc::BoundCond s_bcl = ddc::BoundCond::HERMITE;
static constexpr ddc::BoundCond s_bcr = ddc::BoundCond::HERMITE;
constexpr ddc::BoundCond s_bcl = ddc::BoundCond::HERMITE;
constexpr ddc::BoundCond s_bcr = ddc::BoundCond::HERMITE;
#endif

template <typename BSpX>
Expand Down Expand Up @@ -144,28 +136,28 @@ using BatchDims = ddc::type_seq_remove_t<ddc::detail::TypeSeq<X...>, ddc::detail

// Templated function giving first coordinate of the mesh in given dimension.
template <typename X>
static constexpr Coord<X> x0()
constexpr Coord<X> x0()
{
return Coord<X>(0.);
}

// Templated function giving last coordinate of the mesh in given dimension.
template <typename X>
static constexpr Coord<X> xN()
constexpr Coord<X> xN()
{
return Coord<X>(1.);
}

// Templated function giving step of the mesh in given dimension.
template <typename X>
static constexpr double dx(std::size_t ncells)
constexpr double dx(std::size_t ncells)
{
return (xN<X>() - x0<X>()) / ncells;
}

// Templated function giving break points of mesh in given dimension for non-uniform case.
template <typename X>
static std::vector<Coord<X>> breaks(std::size_t ncells)
std::vector<Coord<X>> breaks(std::size_t ncells)
{
std::vector<Coord<X>> out(ncells + 1);
for (std::size_t i(0); i < ncells + 1; ++i) {
Expand Down Expand Up @@ -217,7 +209,7 @@ struct DimsInitializer<IDimI1, IDimI2, ddc::detail::TypeSeq<IDimX...>>
// Checks that when evaluating the spline at interpolation points one
// recovers values that were used to build the spline
template <typename ExecSpace, typename MemorySpace, typename I1, typename I2, typename... X>
static void Batched2dSplineTest()
void Batched2dSplineTest()
{
// Instantiate execution spaces and initialize spaces
Kokkos::DefaultHostExecutionSpace const host_exec_space;
Expand Down Expand Up @@ -667,6 +659,8 @@ static void Batched2dSplineTest()
1e-11 * max_norm_diff12));
}

} // namespace DDC_HIP_5_7_ANONYMOUS_NAMESPACE_WORKAROUND(BATCHED_2D_SPLINE_BUILDER_CPP)

#if defined(BC_PERIODIC) && defined(BSPLINES_TYPE_UNIFORM)
#define SUFFIX(name) name##Periodic##Uniform
#elif defined(BC_PERIODIC) && defined(BSPLINES_TYPE_NON_UNIFORM)
Expand Down
Loading

0 comments on commit b3e8e1e

Please sign in to comment.