Skip to content

Commit

Permalink
Add pre-commit hook for clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Sep 16, 2024
1 parent d9247ca commit 7d5d682
Show file tree
Hide file tree
Showing 15 changed files with 529 additions and 680 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 82
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ repos:
rev: v4.0.3
hooks:
- id: reuse

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
hooks:
- id: clang-format
types_or: [c, c++, cuda, metal]
18 changes: 7 additions & 11 deletions src/cpp/main_2d/engine_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@

namespace pffdtd {

[[nodiscard]] constexpr auto to_ixy(
std::integral auto x,
std::integral auto y,
std::integral auto /*Nx*/,
std::integral auto Ny
) -> std::integral auto {
[[nodiscard]] constexpr auto
to_ixy(std::integral auto x, std::integral auto y, std::integral auto /*Nx*/, std::integral auto Ny) -> std::integral
auto {
return x * Ny + y;
}

auto EngineNative::operator()(Simulation2D const& sim) const
-> stdex::mdarray<double, stdex::dextents<size_t, 2>> {
auto EngineNative::operator()(Simulation2D const& sim) const -> stdex::mdarray<double, stdex::dextents<size_t, 2>> {

auto const Nx = sim.Nx;
auto const Ny = sim.Ny;
Expand Down Expand Up @@ -51,9 +47,9 @@ auto EngineNative::operator()(Simulation2D const& sim) const
fmt::print(stdout, "{:04d}/{:04d}", n, Nt);
std::fflush(stdout);

// Air Update
#pragma omp parallel for
for (int64_t x = 1; x < Nx-1; ++x) {
// Air Update
#pragma omp parallel for
for (int64_t x = 1; x < Nx - 1; ++x) {
for (int64_t y = 1; y < Ny - 1; ++y) {
auto const idx = to_ixy(x, y, 0, Ny);
auto const left = u1.data_handle()[idx - 1];
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/main_2d/engine_native.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace pffdtd {

struct EngineNative {
[[nodiscard]] auto operator()(Simulation2D const& sim) const
-> stdex::mdarray<double, stdex::dextents<size_t, 2>>;
[[nodiscard]] auto operator()(Simulation2D const& sim) const -> stdex::mdarray<double, stdex::dextents<size_t, 2>>;
};

} // namespace pffdtd
59 changes: 14 additions & 45 deletions src/cpp/main_2d/engine_sycl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,15 @@

namespace pffdtd {

[[nodiscard]] constexpr auto to_ixy(
std::integral auto x,
std::integral auto y,
std::integral auto /*Nx*/,
std::integral auto Ny
) -> std::integral auto {
[[nodiscard]] constexpr auto
to_ixy(std::integral auto x, std::integral auto y, std::integral auto /*Nx*/, std::integral auto Ny) -> std::integral
auto {
return x * Ny + y;
}

static auto kernelAirUpdate(
sycl::id<2> id,
double* u0,
double const* u1,
double const* u2,
uint8_t const* inMask,
int64_t Ny
) -> void {
static auto
kernelAirUpdate(sycl::id<2> id, double* u0, double const* u1, double const* u2, uint8_t const* inMask, int64_t Ny)
-> void {
auto const x = id.get(0) + 1;
auto const y = id.get(1) + 1;
auto const idx = to_ixy(x, y, 0, Ny);
Expand Down Expand Up @@ -86,10 +78,11 @@ static auto kernelBoundaryLoss(
u0[ib] = (current + lossFactor * K4 * prev) / (1 + lossFactor * K4);
}

auto EngineSYCL::operator()(Simulation2D const& sim) const
-> stdex::mdarray<double, stdex::dextents<size_t, 2>> {
auto EngineSYCL::operator()(Simulation2D const& sim) const -> stdex::mdarray<double, stdex::dextents<size_t, 2>> {

for (auto device : sycl::device::get_devices()) { pffdtd::summary(device); }
for (auto device : sycl::device::get_devices()) {
pffdtd::summary(device);
}

auto const Nx = sim.Nx;
auto const Ny = sim.Ny;
Expand Down Expand Up @@ -133,14 +126,7 @@ auto EngineSYCL::operator()(Simulation2D const& sim) const
auto airRange = sycl::range<2>(Nx - 2, Ny - 2);

cgh.parallel_for<struct AirUpdate>(airRange, [=](sycl::id<2> id) {
kernelAirUpdate(
id,
getPtr(u0a),
getPtr(u1a),
getPtr(u2a),
getPtr(inMaskAcc),
Ny
);
kernelAirUpdate(id, getPtr(u0a), getPtr(u1a), getPtr(u2a), getPtr(inMaskAcc), Ny);
});
});

Expand All @@ -153,15 +139,7 @@ auto EngineSYCL::operator()(Simulation2D const& sim) const
auto rigidRange = sycl::range<1>(Nb);

cgh.parallel_for<struct BoundaryRigid>(rigidRange, [=](sycl::id<1> id) {
kernelBoundaryRigid(
id,
getPtr(u0a),
getPtr(u1a),
getPtr(u2a),
getPtr(bn_ixy_acc),
getPtr(adj_bn_acc),
Ny
);
kernelBoundaryRigid(id, getPtr(u0a), getPtr(u1a), getPtr(u2a), getPtr(bn_ixy_acc), getPtr(adj_bn_acc), Ny);
});
});

Expand All @@ -173,23 +151,14 @@ auto EngineSYCL::operator()(Simulation2D const& sim) const
auto lossRange = sycl::range<1>(Nb);

cgh.parallel_for<struct BoundaryLoss>(lossRange, [=](sycl::id<1> id) {
kernelBoundaryLoss(
id,
getPtr(u0a),
getPtr(u2a),
getPtr(bn_ixy_acc),
getPtr(adj_bn_acc),
loss_factor
);
kernelBoundaryLoss(id, getPtr(u0a), getPtr(u2a), getPtr(bn_ixy_acc), getPtr(adj_bn_acc), loss_factor);
});
});

queue.submit([&](sycl::handler& cgh) {
auto u0a = sycl::accessor{u0, cgh, sycl::read_write};
auto src_sig_acc = sycl::accessor{src_sig, cgh, sycl::read_only};
cgh.parallel_for<struct CopyInput>(sycl::range<1>(1), [=](sycl::id<1>) {
u0a[inx][iny] += src_sig_acc[n];
});
cgh.parallel_for<struct CopyInput>(sycl::range<1>(1), [=](sycl::id<1>) { u0a[inx][iny] += src_sig_acc[n]; });
});

queue.submit([&](sycl::handler& cgh) {
Expand Down
3 changes: 1 addition & 2 deletions src/cpp/main_2d/engine_sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace pffdtd {

struct EngineSYCL {
[[nodiscard]] auto operator()(Simulation2D const& sim) const
-> stdex::mdarray<double, stdex::dextents<size_t, 2>>;
[[nodiscard]] auto operator()(Simulation2D const& sim) const -> stdex::mdarray<double, stdex::dextents<size_t, 2>>;
};

} // namespace pffdtd
41 changes: 8 additions & 33 deletions src/cpp/main_3d/engine_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace pffdtd {

namespace {
namespace {

// function that does freq-dep RLC boundaries. See 2016 ISMRA paper and
// accompanying webpage (slightly improved here)
Expand Down Expand Up @@ -66,9 +66,8 @@ double process_bnl_pts_fd(
int64_t nbm = nb * MMb + m;
int32_t mbk = k * MMb + m;
MatQuad const* tm;
tm = &(mat_quads[mbk]);
Real vh0nbm
= (tm->b) * du + (tm->bd) * vh1nb[m] - _2 * (tm->bFh) * gh1[nbm];
tm = &(mat_quads[mbk]);
Real vh0nbm = (tm->b) * du + (tm->bd) * vh1nb[m] - _2 * (tm->bFh) * gh1[nbm];
gh1[nbm] += (vh0nbm + vh1nb[m]) / _2;
vh1[nbm] = vh0nbm;
}
Expand All @@ -78,7 +77,7 @@ double process_bnl_pts_fd(
return omp_get_wtime() - start;
}

}
} // namespace

auto run(Simulation3D& sd) -> double {
// keep local ints, scalars
Expand Down Expand Up @@ -321,19 +320,7 @@ auto run(Simulation3D& sd) -> double {
u0b[nb] = u0[bnl_ixyz[nb]];
}
// process FD boundary nodes
timeElapsedSampleBn = process_bnl_pts_fd(
u0b,
u2b,
ssaf_bnl,
mat_bnl,
Nbl,
Mb,
lo2,
vh1,
gh1,
mat_quads,
mat_beta
);
timeElapsedSampleBn = process_bnl_pts_fd(u0b, u2b, ssaf_bnl, mat_bnl, Nbl, Mb, lo2, vh1, gh1, mat_quads, mat_beta);
timeElapsedBn += timeElapsedSampleBn;
// write back
#pragma omp parallel for
Expand Down Expand Up @@ -392,21 +379,9 @@ auto run(Simulation3D& sd) -> double {
/*------------------------
* RETURN
------------------------*/
fmt::println(
"Air update: {:.6}s, {:.2} Mvox/s",
timeElapsedAir,
Npts * Nt / 1e6 / timeElapsedAir
);
fmt::println(
"Boundary loop: {:.6}s, {:.2} Mvox/s",
timeElapsedBn,
Nb * Nt / 1e6 / timeElapsedBn
);
fmt::println(
"Combined (total): {:.6}s, {:.2} Mvox/s",
timeElapsed,
Npts * Nt / 1e6 / timeElapsed
);
fmt::println("Air update: {:.6}s, {:.2} Mvox/s", timeElapsedAir, Npts * Nt / 1e6 / timeElapsedAir);
fmt::println("Boundary loop: {:.6}s, {:.2} Mvox/s", timeElapsedBn, Nb * Nt / 1e6 / timeElapsedBn);
fmt::println("Combined (total): {:.6}s, {:.2} Mvox/s", timeElapsed, Npts * Nt / 1e6 / timeElapsed);

return timeElapsed;
}
Expand Down
Loading

0 comments on commit 7d5d682

Please sign in to comment.