flow
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
bench_rbgs.cpp
Go to the documentation of this file.
1// Throughput benchmark of the Kokkos RB-GS Poisson sweep (the dominant solver kernel), for the
2// Kokkos-vs-native-CUDA efficiency comparison. Times many full Red-Black sweeps on a fixed grid and
3// reports ns/sweep + effective bandwidth. Pair with tests/cuda_bench/bench_rbgs.cu (identical
4// kernel, plain nvcc) run on the same GPU.
5#include <cstdio>
6#include <cstdlib>
7#include <Kokkos_Core.hpp>
8
9#include "mac_stencils.hpp"
10
11int main(int argc, char** argv) {
12 Kokkos::initialize(argc, argv);
13 {
14 const int N = (argc > 1) ? std::atoi(argv[1]) : 128;
15 const int K = (argc > 2) ? std::atoi(argv[2]) : 200;
16 const int g = 1;
17 peclet::flow::I3 e{N + 2 * g, N + 2 * g, N + 2 * g}, og{0, 0, 0};
18 const std::size_t n = (std::size_t)e.x * e.y * e.z;
19 peclet::flow::SField phi("phi", n), d("d", n);
20 Kokkos::deep_copy(phi, 1.0);
21 Kokkos::deep_copy(d, 0.5);
22
23 // warmup
24 for (int i = 0; i < 10; ++i)
26 Kokkos::fence();
27
28 double best = 1e30;
29 for (int rep = 0; rep < 5; ++rep) {
30 Kokkos::Timer t;
31 for (int i = 0; i < K; ++i)
33 Kokkos::fence();
34 double ms = t.seconds() * 1e3;
35 if (ms < best)
36 best = ms;
37 }
38 const double ns_per_sweep = best * 1e6 / K;
39 const double cells = (double)N * N * N;
40 const double ns_per_cell = ns_per_sweep / cells;
41 const double gbps =
42 cells * 64.0 / (ns_per_sweep); // 64 B/cell (6 nbr + d + write), bytes/ns = GB/s
43 std::printf("KOKKOS N=%d sweeps=%d : %.3f ns/sweep, %.4f ns/cell, %.1f GB/s (exec %s)\n", N, K,
44 ns_per_sweep, ns_per_cell, gbps, Kokkos::DefaultExecutionSpace::name());
45 }
46 Kokkos::finalize();
47 return 0;
48}
int main(int argc, char **argv)
flow — portable (Kokkos) MAC stencil operators: Red-Black Gauss-Seidel smoothers + divergence.
Kokkos::View< const double *, SMem > SConst
Kokkos::View< double *, SMem > SField
void poisSweep(SField phi, SConst d, I3 e, I3 og, int g)
static constexpr int N