Skip to content

Commit

Permalink
Update to clang-tidy-14
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jun 1, 2022
1 parent 02a87ed commit 2fd65ac
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 68 deletions.
5 changes: 5 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
# -readability-static-accessed-through-instance # flags threadIdx/blockIdx in CUDA code
# -cert-err58-cpp # errors in Catch2
# -fuchsia-statically-constructed-objects # too much noise with Catch2
# -bugprone-easily-swappable-parameters # too noisy
Checks: >
*,
-bugprone-exception-escape,
-bugprone-forward-declaration-namespace,
-bugprone-easily-swappable-parameters,
-cert-err58-cpp,
-cert-msc32-c,
-cert-msc51-cpp,
Expand Down Expand Up @@ -46,7 +48,10 @@ Checks: >
-readability-uppercase-literal-suffix,
-readability-function-cognitive-complexity,
-readability-static-accessed-through-instance,
-readability-identifier-length,
-altera-struct-pack-align,
-altera-unroll-loops,
-altera-id-dependent-backward-branch,
-misc-no-recursion,
-llvm-header-guard,
-cppcoreguidelines-macro-usage,
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
clang-tidy:
runs-on: ubuntu-latest
env:
CXX: clang++-12
CXX: clang++-14
steps:
- uses: actions/checkout@v2
- name: install boost
Expand All @@ -40,12 +40,12 @@ jobs:
tar -xf $BOOST_ARCHIVE
rm $BOOST_ARCHIVE
mv boost_${BOOST_VERSION//./_} "${BOOST_ROOT}"
- name: install clang-12
- name: install clang-14
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main'
sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main'
sudo apt update
sudo apt install clang-12 libomp-12-dev clang-tidy-12
sudo apt install clang-14 libomp-14-dev clang-tidy-14
- name: vcpkg install dependencies
run: |
vcpkg install catch2 fmt vc tinyobjloader
Expand All @@ -62,7 +62,7 @@ jobs:
cd build
cmake .. -DBUILD_TESTING=ON -DLLAMA_BUILD_EXAMPLES=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=$CONFIG -DALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE=ON -DALPAKA_ACC_CPU_DISABLE_ATOMIC_REF=ON -DALPAKA_CXX_STANDARD=17 -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake
sed -i 's/\(-forward-unknown-to-host-compiler\|--generate-code=arch=[^ ]\+\|--expt-extended-lambda\|--expt-relaxed-constexpr\|--use_fast_math\)//g' compile_commands.json # remove NVCC specific flags which clang cannot handle
run-clang-tidy-12 -header-filter='^((?!/thirdparty/).)*$' -extra-arg=--no-cuda-version-check -extra-arg=-nocudalib '^(?!.*'$PWD').*$'
run-clang-tidy-14 -header-filter='^((?!/thirdparty/).)*$' -extra-arg=--no-cuda-version-check -extra-arg=-nocudalib -extra-arg=-Wno-unused-command-line-argument '^(?!.*'$PWD').*$'
coverage:
runs-on: ubuntu-latest
Expand Down
16 changes: 8 additions & 8 deletions examples/cuda/nbody/nbody.cu
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ __global__ void updateSM(View particles)
return llama::View{sharedMapping, sharedMems};
}();

const auto ti = threadIdx.x + blockIdx.x * blockDim.x;
const auto tbi = blockIdx.x;
const int ti = static_cast<int>(threadIdx.x + blockIdx.x * blockDim.x);
const int tbi = static_cast<int>(blockIdx.x);

llama::One<Particle> pi = particles(ti);
for(int blockOffset = 0; blockOffset < PROBLEM_SIZE; blockOffset += SHARED_ELEMENTS_PER_BLOCK)
Expand Down Expand Up @@ -237,17 +237,17 @@ try
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> distribution(FP(0), FP(1));
std::normal_distribution<FP> distribution(FP{0}, FP{1});
for(int i = 0; i < PROBLEM_SIZE; ++i)
{
llama::One<Particle> p;
p(tag::Pos(), tag::X()) = distribution(engine);
p(tag::Pos(), tag::Y()) = distribution(engine);
p(tag::Pos(), tag::Z()) = distribution(engine);
p(tag::Vel(), tag::X()) = distribution(engine) / FP(10);
p(tag::Vel(), tag::Y()) = distribution(engine) / FP(10);
p(tag::Vel(), tag::Z()) = distribution(engine) / FP(10);
p(tag::Mass()) = distribution(engine) / FP(100);
p(tag::Vel(), tag::X()) = distribution(engine) / FP{10};
p(tag::Vel(), tag::Y()) = distribution(engine) / FP{10};
p(tag::Vel(), tag::Z()) = distribution(engine) / FP{10};
p(tag::Mass()) = distribution(engine) / FP{100};
hostView(i) = p;
}
if constexpr(TRACE)
Expand Down Expand Up @@ -407,7 +407,7 @@ namespace manual
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> distribution(FP(0), FP(1));
std::normal_distribution<FP> distribution(FP{0}, FP{1});
for(int i = 0; i < PROBLEM_SIZE; ++i)
{
hostPositions[i].x = distribution(engine);
Expand Down
10 changes: 5 additions & 5 deletions examples/cuda/pitch/pitch.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ __global__ void init(View view, ArrayExtents extents)
if(y >= extents[0] || x >= extents[1])
return;

view(y, x).r = x * 255 / static_cast<float>(blockDim.x * gridDim.x);
view(y, x).g = y * 255 / static_cast<float>(blockDim.y * gridDim.y);
view(y, x).b = (threadIdx.x + threadIdx.y) * 255 / static_cast<float>(blockDim.x + blockDim.y);
view(y, x).r = static_cast<float>(x) * 255 / static_cast<float>(blockDim.x * gridDim.x);
view(y, x).g = static_cast<float>(y) * 255 / static_cast<float>(blockDim.y * gridDim.y);
view(y, x).b = static_cast<float>(threadIdx.x + threadIdx.y) * 255 / static_cast<float>(blockDim.x + blockDim.y);
}

namespace llamaex
Expand Down Expand Up @@ -143,8 +143,8 @@ try
llama::divCeil(static_cast<unsigned>(extents[0]), blockDim.y),
1};

std::vector<RGB> host1(llama::product(extents));
std::vector<RGB> host2(llama::product(extents));
auto host1 = std::vector<RGB>(llama::product(extents));
auto host2 = std::vector<RGB>(llama::product(extents));
{
std::byte* mem = nullptr;
std::size_t rowPitch = 0;
Expand Down
80 changes: 40 additions & 40 deletions examples/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ namespace usellama
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t i = 0; i < PROBLEM_SIZE; ++i)
{
auto p = particles(i);
p(tag::Pos{}, tag::X{}) = dist(engine);
p(tag::Pos{}, tag::Y{}) = dist(engine);
p(tag::Pos{}, tag::Z{}) = dist(engine);
p(tag::Vel{}, tag::X{}) = dist(engine) / FP(10);
p(tag::Vel{}, tag::Y{}) = dist(engine) / FP(10);
p(tag::Vel{}, tag::Z{}) = dist(engine) / FP(10);
p(tag::Mass{}) = dist(engine) / FP(100);
p(tag::Vel{}, tag::X{}) = dist(engine) / FP{10};
p(tag::Vel{}, tag::Y{}) = dist(engine) / FP{10};
p(tag::Vel{}, tag::Z{}) = dist(engine) / FP{10};
p(tag::Mass{}) = dist(engine) / FP{100};
}
if constexpr(TRACE)
particles.mapping().fieldHits(particles.storageBlobs) = {};
Expand Down Expand Up @@ -324,16 +324,16 @@ namespace manualAoS
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(auto& p : particles)
{
p.pos.x = dist(engine);
p.pos.y = dist(engine);
p.pos.z = dist(engine);
p.vel.x = dist(engine) / FP(10);
p.vel.y = dist(engine) / FP(10);
p.vel.z = dist(engine) / FP(10);
p.mass = dist(engine) / FP(100);
p.vel.x = dist(engine) / FP{10};
p.vel.y = dist(engine) / FP{10};
p.vel.z = dist(engine) / FP{10};
p.mass = dist(engine) / FP{100};
}
watch.printAndReset("init");

Expand Down Expand Up @@ -431,16 +431,16 @@ namespace manualSoA
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t i = 0; i < PROBLEM_SIZE; ++i)
{
posx[i] = dist(engine);
posy[i] = dist(engine);
posz[i] = dist(engine);
velx[i] = dist(engine) / FP(10);
vely[i] = dist(engine) / FP(10);
velz[i] = dist(engine) / FP(10);
mass[i] = dist(engine) / FP(100);
velx[i] = dist(engine) / FP{10};
vely[i] = dist(engine) / FP{10};
velz[i] = dist(engine) / FP{10};
mass[i] = dist(engine) / FP{100};
}
watch.printAndReset("init");

Expand Down Expand Up @@ -608,7 +608,7 @@ namespace manualAoSoA
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t bi = 0; bi < blocks; ++bi)
{
auto& block = particles[bi];
Expand All @@ -617,10 +617,10 @@ namespace manualAoSoA
block.pos.x[i] = dist(engine);
block.pos.y[i] = dist(engine);
block.pos.z[i] = dist(engine);
block.vel.x[i] = dist(engine) / FP(10);
block.vel.y[i] = dist(engine) / FP(10);
block.vel.z[i] = dist(engine) / FP(10);
block.mass[i] = dist(engine) / FP(100);
block.vel.x[i] = dist(engine) / FP{10};
block.vel.y[i] = dist(engine) / FP{10};
block.vel.z[i] = dist(engine) / FP{10};
block.mass[i] = dist(engine) / FP{100};
}
}
watch.printAndReset("init");
Expand Down Expand Up @@ -823,7 +823,7 @@ namespace manualAoSoA_manualAVX
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t bi = 0; bi < BLOCKS; ++bi)
{
auto& block = particles[bi];
Expand All @@ -832,10 +832,10 @@ namespace manualAoSoA_manualAVX
block.pos.x[i] = dist(engine);
block.pos.y[i] = dist(engine);
block.pos.z[i] = dist(engine);
block.vel.x[i] = dist(engine) / FP(10);
block.vel.y[i] = dist(engine) / FP(10);
block.vel.z[i] = dist(engine) / FP(10);
block.mass[i] = dist(engine) / FP(100);
block.vel.x[i] = dist(engine) / FP{10};
block.vel.y[i] = dist(engine) / FP{10};
block.vel.z[i] = dist(engine) / FP{10};
block.mass[i] = dist(engine) / FP{100};
}
}
watch.printAndReset("init");
Expand Down Expand Up @@ -1090,7 +1090,7 @@ namespace manualAoSoA_Vc
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t bi = 0; bi < BLOCKS; ++bi)
{
auto& block = particles[bi];
Expand All @@ -1099,10 +1099,10 @@ namespace manualAoSoA_Vc
block.pos.x[i] = dist(engine);
block.pos.y[i] = dist(engine);
block.pos.z[i] = dist(engine);
block.vel.x[i] = dist(engine) / FP(10);
block.vel.y[i] = dist(engine) / FP(10);
block.vel.z[i] = dist(engine) / FP(10);
block.mass[i] = dist(engine) / FP(100);
block.vel.x[i] = dist(engine) / FP{10};
block.vel.y[i] = dist(engine) / FP{10};
block.vel.z[i] = dist(engine) / FP{10};
block.mass[i] = dist(engine) / FP{100};
}
}
watch.printAndReset("init");
Expand Down Expand Up @@ -1207,16 +1207,16 @@ namespace manualAoS_Vc
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(auto& p : particles)
{
p.pos.x = dist(engine);
p.pos.y = dist(engine);
p.pos.z = dist(engine);
p.vel.x = dist(engine) / FP(10);
p.vel.y = dist(engine) / FP(10);
p.vel.z = dist(engine) / FP(10);
p.mass = dist(engine) / FP(100);
p.vel.x = dist(engine) / FP{10};
p.vel.y = dist(engine) / FP{10};
p.vel.z = dist(engine) / FP{10};
p.mass = dist(engine) / FP{100};
}
watch.printAndReset("init");

Expand Down Expand Up @@ -1312,16 +1312,16 @@ namespace manualSoA_Vc
watch.printAndReset("alloc");

std::default_random_engine engine;
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t i = 0; i < PROBLEM_SIZE; ++i)
{
posx[i] = dist(engine);
posy[i] = dist(engine);
posz[i] = dist(engine);
velx[i] = dist(engine) / FP(10);
vely[i] = dist(engine) / FP(10);
velz[i] = dist(engine) / FP(10);
mass[i] = dist(engine) / FP(100);
velx[i] = dist(engine) / FP{10};
vely[i] = dist(engine) / FP{10};
velz[i] = dist(engine) / FP{10};
mass[i] = dist(engine) / FP{100};
}
watch.printAndReset("init");

Expand Down
10 changes: 5 additions & 5 deletions examples/nbody_benchmark/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ void run(std::ostream& plotFile)
}

std::default_random_engine engine; // NOLINT(readability-misleading-indentation)
std::normal_distribution<FP> dist(FP(0), FP(1));
std::normal_distribution<FP> dist(FP{0}, FP{1});
for(std::size_t i = 0; i < PROBLEM_SIZE; ++i)
{
auto p = particles(i);
p(tag::Pos{}, tag::X{}) = dist(engine);
p(tag::Pos{}, tag::Y{}) = dist(engine);
p(tag::Pos{}, tag::Z{}) = dist(engine);
p(tag::Vel{}, tag::X{}) = dist(engine) / FP(10);
p(tag::Vel{}, tag::Y{}) = dist(engine) / FP(10);
p(tag::Vel{}, tag::Z{}) = dist(engine) / FP(10);
p(tag::Mass{}) = dist(engine) / FP(100);
p(tag::Vel{}, tag::X{}) = dist(engine) / FP{10};
p(tag::Vel{}, tag::Y{}) = dist(engine) / FP{10};
p(tag::Vel{}, tag::Z{}) = dist(engine) / FP{10};
p(tag::Mass{}) = dist(engine) / FP{100};
}

double sumUpdate = 0;
Expand Down
7 changes: 4 additions & 3 deletions examples/raycast/raycast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/container/static_vector.hpp>
#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <cstddef>
#include <deque>
#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -326,12 +327,12 @@ namespace
// "Image " + filename.string() + " does not have 3 channels but " + std::to_string(comp));
w = x;
h = y;
pixels.resize(w * h);
std::memcpy(pixels.data(), data, w * h * 3);
pixels.resize(std::size_t{w} * h);
std::memcpy(pixels.data(), data, std::size_t{w} * h * 3);
stbi_image_free(data);
}

Image(unsigned int width, unsigned int height) : w(width), h(height), pixels(width * height)
Image(unsigned int width, unsigned int height) : w(width), h(height), pixels(std::size_t{width} * height)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/computedprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST_CASE("computedprop")
auto mapping = AoSWithComputedNormal<decltype(extents), Triangle>{extents};

STATIC_REQUIRE(mapping.blobCount == 1);
CHECK(mapping.blobSize(0) == 10 * 12 * sizeof(double));
CHECK(mapping.blobSize(0) == sizeof(double) * 10 * 12);

auto view = llama::allocViewUninitialized(mapping);

Expand Down
2 changes: 1 addition & 1 deletion tests/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ TEST_CASE("view.iteration-and-access")
SetZeroFunctor<decltype(view(x, y))> szf{view(x, y)};
llama::forEachLeafCoord<Particle>(szf, llama::RecordCoord<0, 0>{});
llama::forEachLeafCoord<Particle>(szf, tag::Vel{});
view({x, y}) = double(x + y) / double(extents[0] + extents[1]);
view({x, y}) = static_cast<double>(x + y) / static_cast<double>(extents[0] + extents[1]);
}

double sum = 0.0;
Expand Down

0 comments on commit 2fd65ac

Please sign in to comment.