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 .clang-tidy file, apply clang-tidy and fix reported warnings #195

Merged
merged 1 commit into from
Mar 31, 2021
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
55 changes: 55 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
# -bugprone-forward-declaration-namespace # too many false positives in LLAMA
# -bugprone-exception-escape # bgruber is fine with exceptions escaping main we cannot add main as an exception
# -cppcoreguidelines-pro-type-member-init # maybe enable in the future
# -cppcoreguidelines-pro-type-reinterpret-cast # we need some reinterpret casts in LLAMA
# -hicpp-member-init # maybe enable in the future
# -readability-misleading-indentation # many false positives because of constexpr if
Checks: >
*,
-bugprone-exception-escape,
-bugprone-forward-declaration-namespace,
-cert-msc32-c,
-cert-msc51-cpp,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-pro-type-reinterpret-cast,
-fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations,
-fuchsia-overloaded-operator,
-fuchsia-trailing-return,
-google-build-using-namespace,
-google-readability-braces-around-statements,
-google-readability-todo,
-google-runtime-references,
-hicpp-avoid-c-arrays,
-hicpp-braces-around-statements,
-hicpp-member-init,
-hicpp-named-parameter,
-hicpp-uppercase-literal-suffix,
-llvmlibc-callee-namespace,
-llvmlibc-implementation-in-namespace,
-llvmlibc-restrict-system-libc-headers,
-misc-non-private-member-variables-in-classes,
-modernize-avoid-c-arrays,
-modernize-use-nodiscard,
-openmp-use-default-none,
-portability-simd-intrinsics,
-readability-braces-around-statements,
-readability-magic-numbers,
-readability-misleading-indentation,
-readability-named-parameter,
-readability-uppercase-literal-suffix

WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: ''
CheckOptions:
...
25 changes: 16 additions & 9 deletions examples/alpaka/asyncblur/asyncblur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace tag
struct R{};
struct G{};
struct B{};
}
} // namespace tag

/// real datum domain of the image pixel used on the host for loading and saving
using Pixel = llama::DS<
Expand Down Expand Up @@ -130,7 +130,7 @@ struct BlurKernel
llama::One<PixelOnAcc> sum;
sum = 0;

using ItType = long int;
using ItType = std::int64_t;
const ItType iBStart = SHARED ? ItType(y) - ItType(bi[0] * ElemsPerBlock) : y;
const ItType iAStart = SHARED ? ItType(x) - ItType(bi[1] * ElemsPerBlock) : x;
const ItType i_b_end
Expand All @@ -153,7 +153,8 @@ struct BlurKernel
}
};

int main(int argc, char** argv)
auto main(int argc, char** argv) -> int
try
{
// ALPAKA
using Dim = alpaka::DimInt<2>;
Expand All @@ -171,7 +172,7 @@ int main(int argc, char** argv)
const DevHost devHost = alpaka::getDevByIdx<PltfHost>(0);
std::vector<Queue> queue;
for (std::size_t i = 0; i < CHUNK_COUNT; ++i)
queue.push_back(Queue(devAcc));
queue.emplace_back(devAcc);

// ASYNCCOPY
std::size_t img_x = DEFAULT_IMG_X;
Expand Down Expand Up @@ -229,8 +230,10 @@ int main(int argc, char** argv)
std::vector<alpaka::Buf<DevHost, std::byte, alpaka::DimInt<1>, std::size_t>> hostChunkBuffer;
std::vector<llama::View<decltype(devMapping), std::byte*>> hostChunkView;

std::vector<alpaka::Buf<DevAcc, std::byte, alpaka::DimInt<1>, std::size_t>> devOldBuffer, devNewBuffer;
std::vector<llama::View<decltype(devMapping), std::byte*>> devOldView, devNewView;
std::vector<alpaka::Buf<DevAcc, std::byte, alpaka::DimInt<1>, std::size_t>> devOldBuffer;
std::vector<alpaka::Buf<DevAcc, std::byte, alpaka::DimInt<1>, std::size_t>> devNewBuffer;
std::vector<llama::View<decltype(devMapping), std::byte*>> devOldView;
std::vector<llama::View<decltype(devMapping), std::byte*>> devNewView;

for (std::size_t i = 0; i < CHUNK_COUNT; ++i)
{
Expand Down Expand Up @@ -272,9 +275,9 @@ int main(int argc, char** argv)
const auto X = std::clamp<std::size_t>(x, KERNEL_SIZE, img_x + KERNEL_SIZE - 1);
const auto Y = std::clamp<std::size_t>(y, KERNEL_SIZE, img_y + KERNEL_SIZE - 1);
const auto* pixel = &image[((Y - KERNEL_SIZE) * img_x + X - KERNEL_SIZE) * 3];
hostView(y, x)(tag::R()) = FP(pixel[0]) / 255.;
hostView(y, x)(tag::G()) = FP(pixel[1]) / 255.;
hostView(y, x)(tag::B()) = FP(pixel[2]) / 255.;
hostView(y, x)(tag::R()) = FP(pixel[0]) / 255;
hostView(y, x)(tag::G()) = FP(pixel[1]) / 255;
hostView(y, x)(tag::B()) = FP(pixel[2]) / 255;
}
}
}
Expand Down Expand Up @@ -395,3 +398,7 @@ int main(int argc, char** argv)

return 0;
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
9 changes: 7 additions & 2 deletions examples/alpaka/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace tag
struct Y{};
struct Z{};
struct Mass{};
}
} // namespace tag

using Particle = llama::DS<
llama::DE<tag::Pos, llama::DS<
Expand Down Expand Up @@ -168,7 +168,8 @@ using Distribution = common::ThreadsElemsDistribution<Acc, BLOCK_SIZE, hardwareT
constexpr std::size_t elemCount = Distribution::elemCount;
constexpr std::size_t threadCount = Distribution::threadCount;

int main()
auto main() -> int
try
{
const DevAcc devAcc(alpaka::getDevByIdx<PltfAcc>(0u));
const DevHost devHost(alpaka::getDevByIdx<PltfHost>(0u));
Expand Down Expand Up @@ -262,3 +263,7 @@ int main()

return 0;
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
9 changes: 7 additions & 2 deletions examples/alpaka/vectoradd/vectoradd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace tag
struct X{};
struct Y{};
struct Z{};
}
} // namespace tag

using Vector = llama::DS<
llama::DE<tag::X, FP>,
Expand Down Expand Up @@ -59,7 +59,8 @@ struct AddKernel
}
};

int main(int argc, char** argv)
auto main() -> int
try
{
// ALPAKA
using Dim = alpaka::DimInt<1>;
Expand Down Expand Up @@ -160,3 +161,7 @@ int main(int argc, char** argv)

return 0;
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
15 changes: 10 additions & 5 deletions examples/bufferguard/bufferguard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace tag
struct X{};
struct Y{};
struct Z{};
}
} // namespace tag

using Vector = llama::DS<
llama::DE<tag::X, int>,
Expand All @@ -31,7 +31,7 @@ struct GuardMapping2D

constexpr GuardMapping2D() = default;

constexpr GuardMapping2D(ArrayDomain size, DatumDomain = {})
constexpr explicit GuardMapping2D(ArrayDomain size, DatumDomain = {})
: arrayDomainSize(size)
, left({size[0] - 2})
, right({size[0] - 2})
Expand Down Expand Up @@ -147,9 +147,9 @@ struct GuardMapping2D
}

template <typename Mapping>
constexpr auto blobIndices(const Mapping& mapping, std::size_t offset) const
constexpr auto blobIndices(const Mapping&, std::size_t offset) const
{
std::array<std::size_t, Mapping::blobCount> a;
std::array<std::size_t, Mapping::blobCount> a{};
std::generate(begin(a), end(a), [i = offset]() mutable { return i++; });
return a;
}
Expand Down Expand Up @@ -257,9 +257,14 @@ void run(const std::string& mappingName)
printView(view1, rows, cols);
}

int main()
auto main() -> int
try
{
run<llama::mapping::PreconfiguredAoS<>::type>("AoS");
run<llama::mapping::PreconfiguredSoA<>::type>("SoA");
run<llama::mapping::PreconfiguredSoA<std::true_type>::type>("SoA_MB");
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
13 changes: 10 additions & 3 deletions examples/cuda/nbody/nbody.cu
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ catch (const std::exception& e)
}

int main()
try
{
std::cout << PROBLEM_SIZE / 1000 << "k particles (" << PROBLEM_SIZE * llama::sizeOf<Particle> / 1024 << "kiB)\n"
<< "Caching " << SHARED_ELEMENTS_PER_BLOCK << " particles ("
Expand Down Expand Up @@ -331,15 +332,21 @@ int main()
});

std::cout << "Plot with: ./nbody.sh\n";
std::ofstream{"nbody.sh"} << fmt::format(R"(#!/usr/bin/gnuplot -p
std::ofstream{"nbody.sh"} << fmt::format(
R"(#!/usr/bin/gnuplot -p
set title "nbody CUDA {0}k particles"
set style data histograms
set style fill solid
set xtics rotate by 45 right
set key out top center maxrows 3
set yrange [0:*]
plot 'nbody.tsv' using 2:xtic(1) ti col, "" using 4 ti col
)", PROBLEM_SIZE / 1000);
)",
PROBLEM_SIZE / 1000);

return 0;
}
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
7 changes: 6 additions & 1 deletion examples/heatequation/heatequation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ void update_Vc_peel(const View& uCurr, View& uNext, uint32_t extent, double dx,
// u_t(x, t) = u_xx(x, t), x in [0, 1], t in [0, T]
// u(0, t) = u(1, t) = 0
// u(x, 0) = sin(pi * x)
double exactSolution(double const x, double const t)
auto exactSolution(double const x, double const t) -> double
{
constexpr double pi = 3.14159265358979323846;
return std::exp(-pi * pi * t) * std::sin(pi * x);
}

auto main() -> int
try
{
// Parameters (a user is supposed to change extent, timeSteps)
const auto extent = 10000;
Expand Down Expand Up @@ -151,3 +152,7 @@ auto main() -> int

return 0;
}
catch (const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
Loading